git: 04c91ac48ad1 - main - selsocket: handle sopoll() errors correctly

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Wed, 13 Oct 2021 23:44:00 UTC
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=04c91ac48ad13ce0d1392cedbd69c2c0223d206f

commit 04c91ac48ad13ce0d1392cedbd69c2c0223d206f
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2021-10-13 23:43:06 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2021-10-13 23:43:48 +0000

    selsocket: handle sopoll() errors correctly
    
    Without this change, unmounting smbfs filesystems with an INVARIANTS
    kernel would panic after 10e64782ed59727e8c9fe4a5c7e17f497903c8eb.
    
    Found by:       markj
    Reviewed by:    markj, jhb
    Obtained from:  CheriBSD
    MFC after:      3 days
    Sponsored by:   DARPA
    Differential Revision:  https://reviews.freebsd.org/D32492
---
 sys/kern/sys_generic.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index e6b2cba27a04..41e9c556f73f 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -1794,10 +1794,10 @@ selsocket(struct socket *so, int events, struct timeval *tvp, struct thread *td)
 	 */
 	for (;;) {
 		selfdalloc(td, NULL);
-		error = sopoll(so, events, NULL, td);
-		/* error here is actually the ready events. */
-		if (error)
-			return (0);
+		if (sopoll(so, events, NULL, td) != 0) {
+			error = 0;
+			break;
+		}
 		error = seltdwait(td, asbt, precision);
 		if (error)
 			break;