Module Name: src
Committed By: pgoyette
Date: Fri Jul 8 16:10:34 UTC 2022
Modified Files:
src/sys/dev/pci: nvme_pci.c
Log Message:
Initialize cmajor & bmajor so the devsw_attach() has a chance of
succeeding.
Record the success of devsw_attach(), and do not try later to
devsw_detach() unless the attach succeeded.
Partial fix for kern/56914
To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/pci/nvme_pci.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/pci/nvme_pci.c
diff -u src/sys/dev/pci/nvme_pci.c:1.33 src/sys/dev/pci/nvme_pci.c:1.34
--- src/sys/dev/pci/nvme_pci.c:1.33 Thu Jul 7 23:54:17 2022
+++ src/sys/dev/pci/nvme_pci.c Fri Jul 8 16:10:34 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: nvme_pci.c,v 1.33 2022/07/07 23:54:17 pgoyette Exp $ */
+/* $NetBSD: nvme_pci.c,v 1.34 2022/07/08 16:10:34 pgoyette Exp $ */
/* $OpenBSD: nvme_pci.c,v 1.3 2016/04/14 11:18:32 dlg Exp $ */
/*
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.33 2022/07/07 23:54:17 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.34 2022/07/08 16:10:34 pgoyette Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -495,12 +495,14 @@ nvme_modcmd(modcmd_t cmd, void *opaque)
#ifdef _MODULE
devmajor_t cmajor, bmajor;
extern const struct cdevsw nvme_cdevsw;
+ bool devsw_ok = false;
#endif
int error = 0;
#ifdef _MODULE
switch (cmd) {
case MODULE_CMD_INIT:
+ bmajor = cmajor = NODEVMAJOR;
error = devsw_attach(nvme_cd.cd_name, NULL, &bmajor,
&nvme_cdevsw, &cmajor);
if (error) {
@@ -508,18 +510,22 @@ nvme_modcmd(modcmd_t cmd, void *opaque)
nvme_cd.cd_name, error);
/* do not abort, just /dev/nvme* will not work */
}
+ else
+ devsw_ok = true;
+
error = config_init_component(cfdriver_ioconf_nvme_pci,
cfattach_ioconf_nvme_pci, cfdata_ioconf_nvme_pci);
if (error) {
- devsw_detach(NULL, &nvme_cdevsw);
+ if (devsw_ok)
+ devsw_detach(NULL, &nvme_cdevsw);
break;
}
- bmajor = cmajor = NODEVMAJOR;
break;
case MODULE_CMD_FINI:
error = config_fini_component(cfdriver_ioconf_nvme_pci,
cfattach_ioconf_nvme_pci, cfdata_ioconf_nvme_pci);
- devsw_detach(NULL, &nvme_cdevsw);
+ if (devsw_ok)
+ devsw_detach(NULL, &nvme_cdevsw);
break;
default:
break;