aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_sbuf.c
diff options
context:
space:
mode:
authorRichard Scheffenegger <rscheff@FreeBSD.org>2021-04-02 18:11:45 +0000
committerRichard Scheffenegger <rscheff@FreeBSD.org>2021-04-02 18:12:11 +0000
commitcad4fd0365a5e3235e715e072e6ee9dffaa7a3ab (patch)
tree2d88d62a5a2479f444f40f7195b2a531cf428188 /sys/kern/subr_sbuf.c
parent36d6e65722ea515bf2d122d6e69096a5ff620a92 (diff)
downloadsrc-cad4fd0365a5e3235e715e072e6ee9dffaa7a3ab.tar.gz
src-cad4fd0365a5e3235e715e072e6ee9dffaa7a3ab.zip
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
Diffstat (limited to 'sys/kern/subr_sbuf.c')
-rw-r--r--sys/kern/subr_sbuf.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/sys/kern/subr_sbuf.c b/sys/kern/subr_sbuf.c
index 66822115dbcb..cdeaf690208f 100644
--- a/sys/kern/subr_sbuf.c
+++ b/sys/kern/subr_sbuf.c
@@ -388,8 +388,12 @@ 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);