Index: sys/kern/subr_sbuf.c =================================================================== --- sys/kern/subr_sbuf.c +++ sys/kern/subr_sbuf.c @@ -363,8 +363,8 @@ 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)); len = s->s_drain_func(s->s_drain_arg, s->s_buf, s->s_len); - if (len < 0) { - s->s_error = -len; + if (len <= 0) { + s->s_error = len ? -len : EDEADLK; return (s->s_error); } KASSERT(len > 0 && len <= s->s_len, @@ -633,9 +633,9 @@ break; /* Cannot print with the current available space. */ if (s->s_drain_func != NULL && s->s_len > 0) - error = sbuf_drain(s); - else - error = sbuf_extend(s, len - SBUF_FREESPACE(s)); + error = sbuf_drain(s); /* sbuf_drain() sets s_error. */ + else if (0 != sbuf_extend(s, len - SBUF_FREESPACE(s))) + s->s_error = error = ENOMEM; } while (error == 0); /* @@ -652,8 +652,6 @@ s->s_len += len; if (SBUF_ISSECTION(s)) s->s_sect_len += len; - if (!SBUF_HASROOM(s) && !SBUF_CANEXTEND(s)) - s->s_error = ENOMEM; KASSERT(s->s_len < s->s_size, ("wrote past end of sbuf (%d >= %d)", s->s_len, s->s_size));