ng_socket: Treat EEXIST from kern_kldload() as success

EEXIST is possible in a race condition.

Inspired by:	ffc72591b1 (Don't worry if a module is already loaded ...)
Reviewed by:	glebius
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D44633
This commit is contained in:
Zhenlei Huang 2024-04-09 18:04:47 +08:00
parent cce11997a0
commit f6f67f58c1

View File

@ -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;
}
}