Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Initialize cmajor & bmajor so the devsw_attach()...



details:   https://anonhg.NetBSD.org/src/rev/11415d713512
branches:  trunk
changeset: 368382:11415d713512
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Fri Jul 08 16:10:34 2022 +0000

description:
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

diffstat:

 sys/dev/pci/nvme_pci.c |  16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diffs (59 lines):

diff -r 283e36c6f16a -r 11415d713512 sys/dev/pci/nvme_pci.c
--- a/sys/dev/pci/nvme_pci.c    Fri Jul 08 09:00:00 2022 +0000
+++ b/sys/dev/pci/nvme_pci.c    Fri Jul 08 16:10:34 2022 +0000
@@ -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 @@
 #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_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;



Home | Main Index | Thread Index | Old Index