git: f6f67f58c19d - main - ng_socket: Treat EEXIST from kern_kldload() as success
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 09 Apr 2024 10:06:42 UTC
The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=f6f67f58c19db4f25f5c2cf4869efc7054493a55 commit f6f67f58c19db4f25f5c2cf4869efc7054493a55 Author: Zhenlei Huang <zlei@FreeBSD.org> AuthorDate: 2024-04-09 10:04:47 +0000 Commit: Zhenlei Huang <zlei@FreeBSD.org> CommitDate: 2024-04-09 10:04:47 +0000 ng_socket: Treat EEXIST from kern_kldload() as success EEXIST is possible in a race condition. Inspired by: ffc72591b1f5 (Don't worry if a module is already loaded ...) Reviewed by: glebius MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D44633 --- sys/netgraph/ng_socket.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c index c356f7d6aa12..c570584d4b44 100644 --- a/sys/netgraph/ng_socket.c +++ b/sys/netgraph/ng_socket.c @@ -285,11 +285,15 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, if (ng_findtype(mkp->type) == NULL) { char filename[NG_TYPESIZ + 3]; int fileid; + bool loaded; /* Not found, try to load it as a loadable module. */ snprintf(filename, sizeof(filename), "ng_%s", mkp->type); error = kern_kldload(curthread, filename, &fileid); + loaded = (error == 0); + if (error == EEXIST) + error = 0; if (error != 0) { free(msg, M_NETGRAPH_MSG); goto release; @@ -298,9 +302,10 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, /* See if type has been loaded successfully. */ if (ng_findtype(mkp->type) == NULL) { free(msg, M_NETGRAPH_MSG); - (void)kern_kldunload(curthread, fileid, - LINKER_UNLOAD_NORMAL); - error = ENXIO; + if (loaded) + (void)kern_kldunload(curthread, fileid, + LINKER_UNLOAD_NORMAL); + error = ENXIO; goto release; } }