From owner-dev-commits-src-branches@freebsd.org Fri Apr 16 19:36:21 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 028315DD00C; Fri, 16 Apr 2021 19:36:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FMRKJ67yxz4lS7; Fri, 16 Apr 2021 19:36:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C0AF124DE; Fri, 16 Apr 2021 19:36:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13GJaK6P073819; Fri, 16 Apr 2021 19:36:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13GJaK8M073818; Fri, 16 Apr 2021 19:36:20 GMT (envelope-from git) Date: Fri, 16 Apr 2021 19:36:20 GMT Message-Id: <202104161936.13GJaK8M073818@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Richard Scheffenegger Subject: git: 424f6363927a - stable/12 - Make sbuf_drain safe for external use MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rscheff X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 424f6363927a113fe5a1dcb4691039ec25cf3680 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Apr 2021 19:36:21 -0000 The branch stable/12 has been updated by rscheff: URL: https://cgit.FreeBSD.org/src/commit/?id=424f6363927a113fe5a1dcb4691039ec25cf3680 commit 424f6363927a113fe5a1dcb4691039ec25cf3680 Author: Richard Scheffenegger AuthorDate: 2021-04-02 18:11:45 +0000 Commit: Richard Scheffenegger CommitDate: 2021-04-16 19:34:26 +0000 Make sbuf_drain safe for external use While sbuf_drain was an internal function, two KASSERTS checked the sanity of it being called. However, an external caller may be ignorant if there is any data to drain, or if an error has already accumulated. Be nice and return immediately with the accumulated error. MFC after: 2 weeks Reviewed By: tuexen, #transport Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D29544 (cherry picked from commit cad4fd0365a5e3235e715e072e6ee9dffaa7a3ab) --- sys/kern/subr_sbuf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/kern/subr_sbuf.c b/sys/kern/subr_sbuf.c index c8f2af2ebca2..ac6bc14b7a8c 100644 --- a/sys/kern/subr_sbuf.c +++ b/sys/kern/subr_sbuf.c @@ -380,8 +380,13 @@ sbuf_drain(struct sbuf *s) { int len; - KASSERT(s->s_len > 0, ("Shouldn't drain empty sbuf %p", s)); - KASSERT(s->s_error == 0, ("Called %s with error on %p", __func__, s)); + /* + * Immediately return when no work to do, + * or an error has already been accumulated. + */ + if ((s->s_len == 0) || (s->s_error != 0)) + return(s->s_error); + if (SBUF_DODRAINTOEOR(s) && s->s_rec_off == 0) return (s->s_error = EDEADLK); len = s->s_drain_func(s->s_drain_arg, s->s_buf,