diff --git a/sys/netgraph/ng_socket.c b/sys/netgraph/ng_socket.c --- a/sys/netgraph/ng_socket.c +++ b/sys/netgraph/ng_socket.c @@ -285,21 +285,27 @@ 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); + error = ENXIO; goto release; } /* 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); + if (loaded) + (void)kern_kldunload(curthread, fileid, + LINKER_UNLOAD_NORMAL); error = ENXIO; goto release; }