Source-Changes-HG archive

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

[src/trunk]: src/sys For device modules that provide both auto-config and /de...



details:   https://anonhg.NetBSD.org/src/rev/c7941de4b610
branches:  trunk
changeset: 364615:c7941de4b610
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Thu Mar 31 19:30:15 2022 +0000

description:
For device modules that provide both auto-config and /dev/xxx
interfaces, make sure that initialization and destruction
follow the proper sequence.  This is triggered by the recent
changes to the devsw stuff; per riastradh@ the required call
sequence is:

        devsw_attach()
        config_init_component() or config_cf*_attach()
        ...
        config_fini_component() or config_cf*_detach()
        devsw_detach()

While here, add a few missing calls to some of the detach
routines.

Testing of these changes has been limited to:
        1. compile without build break
        2. no related test failures from atf
        3. modload/modunload work as well as
           before.

No functional device testing done, since I don't have any
of these devices.  Let me know of any damage I might cause
here!

XXX Some of the modules affected by this commit are already
XXX broken;  see kern/56772.  This commit does not break
any additional modules (as far as I know).

diffstat:

 sys/dev/audio/audio.c                         |  13 ++---
 sys/dev/cgd.c                                 |  55 +++++++++++++-------------
 sys/dev/dm/device-mapper.c                    |  25 ++++++-----
 sys/dev/dtv/dtv_device.c                      |  21 +++++----
 sys/dev/flash/flash.c                         |  17 +++----
 sys/dev/fss.c                                 |  28 ++++++-------
 sys/dev/gpio/gpio.c                           |  20 ++++----
 sys/dev/gpio/gpiopps.c                        |  23 +++++-----
 sys/dev/i2c/sht3x.c                           |  26 ++++++-----
 sys/dev/ic/scmd.c                             |  22 +++++-----
 sys/dev/ir/cir.c                              |  15 +++---
 sys/dev/iscsi/iscsi_main.c                    |  27 +++++++-----
 sys/dev/midi.c                                |  10 +--
 sys/dev/pad/pad.c                             |  27 ++++--------
 sys/dev/pci/nvme_pci.c                        |  20 ++++----
 sys/dev/pci/vio9p.c                           |   9 ++-
 sys/dev/sequencer.c                           |  11 +---
 sys/dev/spkr.c                                |  10 +--
 sys/dev/vnd.c                                 |  56 ++++++++++++--------------
 sys/dev/wscons/wsbell.c                       |  10 +--
 sys/modules/lua/lua.c                         |  25 ++++++-----
 sys/net/if_tap.c                              |  36 +++++++----------
 sys/opencrypto/cryptodev.c                    |  31 ++++++--------
 sys/rump/dev/lib/libmd/md_component.c         |  10 ++--
 sys/rump/dev/lib/libpci/pci_at_mainbus.c      |  10 ++--
 sys/rump/dev/lib/libscsipi/scsipi_component.c |  10 ++--
 sys/rump/dev/lib/libucom/ucom_at_usb.c        |  10 ++--
 sys/rump/dev/lib/libulpt/ulpt_at_usb.c        |  10 ++--
 sys/rump/dev/lib/libvirtio_ld/ld_at_virtio.c  |  19 ++++----
 sys/rump/dev/lib/libwscons/wscons_component.c |  14 +++--
 30 files changed, 299 insertions(+), 321 deletions(-)

diffs (truncated from 1576 to 300 lines):

diff -r de16dfa60726 -r c7941de4b610 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Thu Mar 31 17:43:50 2022 +0000
+++ b/sys/dev/audio/audio.c     Thu Mar 31 19:30:15 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.121 2022/03/28 12:39:57 riastradh Exp $    */
+/*     $NetBSD: audio.c,v 1.122 2022/03/31 19:30:15 pgoyette Exp $     */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.121 2022/03/28 12:39:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.122 2022/03/31 19:30:15 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -9070,14 +9070,13 @@
                break;
        case MODULE_CMD_FINI:
 #ifdef _MODULE
-               devsw_detach(NULL, &audio_cdevsw);
                error = config_fini_component(cfdriver_ioconf_audio,
                   cfattach_ioconf_audio, cfdata_ioconf_audio);
-               if (error)
-                       devsw_attach(audio_cd.cd_name, NULL, &audio_bmajor,
-                           &audio_cdevsw, &audio_cmajor);
+               if (error == 0)
+                       devsw_detach(NULL, &audio_cdevsw);
 #endif
-               psref_class_destroy(audio_psref_class);
+               if (error == 0)
+                       psref_class_destroy(audio_psref_class);
                break;
        default:
                error = ENOTTY;
diff -r de16dfa60726 -r c7941de4b610 sys/dev/cgd.c
--- a/sys/dev/cgd.c     Thu Mar 31 17:43:50 2022 +0000
+++ b/sys/dev/cgd.c     Thu Mar 31 19:30:15 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cgd.c,v 1.142 2021/12/27 22:57:19 riastradh Exp $ */
+/* $NetBSD: cgd.c,v 1.143 2022/03/31 19:30:15 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.142 2021/12/27 22:57:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cgd.c,v 1.143 2022/03/31 19:30:15 pgoyette Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -1723,7 +1723,7 @@
        aprint_debug("cgd: self-tests passed\n");
 }
 
-MODULE(MODULE_CLASS_DRIVER, cgd, "blowfish,des,dk_subr,bufq_fcfs");
+MODULE(MODULE_CLASS_DRIVER, cgd, "adiantum,blowfish,des,dk_subr,bufq_fcfs");
 
 #ifdef _MODULE
 CFDRIVER_DECL(cgd, DV_DISK, NULL);
@@ -1742,31 +1742,34 @@
                mutex_init(&cgd_spawning_mtx, MUTEX_DEFAULT, IPL_NONE);
                cv_init(&cgd_spawning_cv, "cgspwn");
 
-               error = config_cfdriver_attach(&cgd_cd);
-               if (error)
-                       break;
-
-               error = config_cfattach_attach(cgd_cd.cd_name, &cgd_ca);
-               if (error) {
-                       config_cfdriver_detach(&cgd_cd);
-                       aprint_error("%s: unable to register cfattach for"
-                           "%s, error %d\n", __func__, cgd_cd.cd_name, error);
-                       break;
-               }
                /*
                 * Attach the {b,c}devsw's
                 */
                error = devsw_attach("cgd", &cgd_bdevsw, &cgd_bmajor,
                    &cgd_cdevsw, &cgd_cmajor);
+               if (error) {
+                       aprint_error("%s: unable to attach %s devsw, "
+                           "error %d", __func__, cgd_cd.cd_name, error);
+                       break;
+               }
 
                /*
-                * If devsw_attach fails, remove from autoconf database
+                * Attach to autoconf database
                 */
+               error = config_cfdriver_attach(&cgd_cd);
                if (error) {
-                       config_cfattach_detach(cgd_cd.cd_name, &cgd_ca);
+                       devsw_detach(&cgd_bdevsw, &cgd_cdevsw);
+                       aprint_error("%s: unable to register cfdriver for"
+                           "%s, error %d\n", __func__, cgd_cd.cd_name, error);
+                       break;
+               }
+
+               error = config_cfattach_attach(cgd_cd.cd_name, &cgd_ca);
+               if (error) {
                        config_cfdriver_detach(&cgd_cd);
-                       aprint_error("%s: unable to attach %s devsw, "
-                           "error %d", __func__, cgd_cd.cd_name, error);
+                       devsw_detach(&cgd_bdevsw, &cgd_cdevsw);
+                       aprint_error("%s: unable to register cfattach for"
+                           "%s, error %d\n", __func__, cgd_cd.cd_name, error);
                        break;
                }
 #endif
@@ -1775,17 +1778,10 @@
        case MODULE_CMD_FINI:
 #ifdef _MODULE
                /*
-                * Remove {b,c}devsw's
-                */
-               devsw_detach(&cgd_bdevsw, &cgd_cdevsw);
-
-               /*
-                * Now remove device from autoconf database
+                * Remove device from autoconf database
                 */
                error = config_cfattach_detach(cgd_cd.cd_name, &cgd_ca);
                if (error) {
-                       (void)devsw_attach("cgd", &cgd_bdevsw, &cgd_bmajor,
-                           &cgd_cdevsw, &cgd_cmajor);
                        aprint_error("%s: failed to detach %s cfattach, "
                            "error %d\n", __func__, cgd_cd.cd_name, error);
                        break;
@@ -1793,13 +1789,16 @@
                error = config_cfdriver_detach(&cgd_cd);
                if (error) {
                        (void)config_cfattach_attach(cgd_cd.cd_name, &cgd_ca);
-                       (void)devsw_attach("cgd", &cgd_bdevsw, &cgd_bmajor,
-                           &cgd_cdevsw, &cgd_cmajor);
                        aprint_error("%s: failed to detach %s cfdriver, "
                            "error %d\n", __func__, cgd_cd.cd_name, error);
                        break;
                }
 
+               /*
+                * Remove {b,c}devsw's
+                */
+               devsw_detach(&cgd_bdevsw, &cgd_cdevsw);
+
                cv_destroy(&cgd_spawning_cv);
                mutex_destroy(&cgd_spawning_mtx);
 #endif
diff -r de16dfa60726 -r c7941de4b610 sys/dev/dm/device-mapper.c
--- a/sys/dev/dm/device-mapper.c        Thu Mar 31 17:43:50 2022 +0000
+++ b/sys/dev/dm/device-mapper.c        Thu Mar 31 19:30:15 2022 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: device-mapper.c,v 1.63 2022/03/28 10:38:00 mlelstv Exp $ */
+/*        $NetBSD: device-mapper.c,v 1.64 2022/03/31 19:30:15 pgoyette Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -170,26 +170,28 @@
 
        switch (cmd) {
        case MODULE_CMD_INIT:
-               error = config_cfdriver_attach(&dm_cd);
+               error = devsw_attach(dm_cd.cd_name, &dm_bdevsw, &bmajor,
+                   &dm_cdevsw, &cmajor);
+               if (error == EEXIST)
+                       error = 0;
                if (error)
                        break;
 
+               error = config_cfdriver_attach(&dm_cd);
+               if (error) {
+                       devsw_detach(&dm_bdevsw, &dm_cdevsw);
+                       return error;
+               }
+
                error = config_cfattach_attach(dm_cd.cd_name, &dm_ca);
                if (error) {
+                       config_cfdriver_detach(&dm_cd);
+                       devsw_detach(&dm_bdevsw, &dm_cdevsw);
                        aprint_error("%s: unable to register cfattach\n",
                            dm_cd.cd_name);
                        return error;
                }
 
-               error = devsw_attach(dm_cd.cd_name, &dm_bdevsw, &bmajor,
-                   &dm_cdevsw, &cmajor);
-               if (error == EEXIST)
-                       error = 0;
-               if (error) {
-                       config_cfattach_detach(dm_cd.cd_name, &dm_ca);
-                       config_cfdriver_detach(&dm_cd);
-                       break;
-               }
                dm_doinit();
                break;
        case MODULE_CMD_FINI:
@@ -208,6 +210,7 @@
                        break;
 
                config_cfdriver_detach(&dm_cd);
+               config_cfattach_detach(dm_cd.cd_name, &dm_ca);
 
                devsw_detach(&dm_bdevsw, &dm_cdevsw);
                break;
diff -r de16dfa60726 -r c7941de4b610 sys/dev/dtv/dtv_device.c
--- a/sys/dev/dtv/dtv_device.c  Thu Mar 31 17:43:50 2022 +0000
+++ b/sys/dev/dtv/dtv_device.c  Thu Mar 31 19:30:15 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dtv_device.c,v 1.13 2021/07/24 07:48:38 skrll Exp $ */
+/* $NetBSD: dtv_device.c,v 1.14 2022/03/31 19:30:15 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dtv_device.c,v 1.13 2021/07/24 07:48:38 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dtv_device.c,v 1.14 2022/03/31 19:30:15 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -176,23 +176,26 @@
        switch (cmd) {
        case MODULE_CMD_INIT:
 #ifdef _MODULE
+               error = devsw_attach("dtv", NULL, &bmaj, &dtv_cdevsw, &cmaj);
+               if (error)
+                       return error;
+
                error = config_init_component(cfdriver_ioconf_dtv,
                    cfattach_ioconf_dtv, cfdata_ioconf_dtv);
                if (error)
-                       return error;
-               error = devsw_attach("dtv", NULL, &bmaj, &dtv_cdevsw, &cmaj);
-               if (error)
-                       config_fini_component(cfdriver_ioconf_dtv,
-                           cfattach_ioconf_dtv, cfdata_ioconf_dtv);
+                       devsw_detach(NULL, &dtv_cdevsw);
                return error;
 #else
                return 0;
 #endif
        case MODULE_CMD_FINI:
 #ifdef _MODULE
-               devsw_detach(NULL, &dtv_cdevsw);
-               return config_fini_component(cfdriver_ioconf_dtv,
+               error = config_fini_component(cfdriver_ioconf_dtv,
                    cfattach_ioconf_dtv, cfdata_ioconf_dtv);
+               if (error == 0)
+                       devsw_detach(NULL, &dtv_cdevsw);
+
+               return error;
 #else
                return 0;
 #endif
diff -r de16dfa60726 -r c7941de4b610 sys/dev/flash/flash.c
--- a/sys/dev/flash/flash.c     Thu Mar 31 17:43:50 2022 +0000
+++ b/sys/dev/flash/flash.c     Thu Mar 31 19:30:15 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: flash.c,v 1.17 2021/08/07 16:19:10 thorpej Exp $       */
+/*     $NetBSD: flash.c,v 1.18 2022/03/31 19:30:16 pgoyette Exp $      */
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.17 2021/08/07 16:19:10 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: flash.c,v 1.18 2022/03/31 19:30:16 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -648,22 +648,21 @@
        switch (cmd) {
        case MODULE_CMD_INIT:
 #ifdef _MODULE
+               error = devsw_attach("flash", &flash_bdevsw, &bmaj,
+                   &flash_cdevsw, &cmaj);
+               if (error)
+                       return error;
                error = config_init_component(cfdriver_ioconf_flash,
                    cfattach_ioconf_flash, cfdata_ioconf_flash);
                if (error)
-                       return error;
-               error = devsw_attach("flash", &flash_bdevsw, &bmaj,
-                   &flash_cdevsw, &cmaj);
-               if (error)
-                       config_fini_component(cfdriver_ioconf_flash,
-                           cfattach_ioconf_flash, cfdata_ioconf_flash);
+                       devsw_detach(&flash_bdevsw, &flash_cdevsw);
 #endif
                return error;
        case MODULE_CMD_FINI:
 #ifdef _MODULE



Home | Main Index | Thread Index | Old Index