Source-Changes-HG archive

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

[src/trunk]: src/sys/sys driver(9): devsw_detach never fails. Make it return...



details:   https://anonhg.NetBSD.org/src/rev/7775bf1a281f
branches:  trunk
changeset: 364489:7775bf1a281f
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Mar 28 12:33:20 2022 +0000

description:
driver(9): devsw_detach never fails.  Make it return void.

Prune a whole lotta dead branches as a result of this.  (Some logic
calling this is also wrong for other reasons; devsw_detach is final
-- you should never have any reason to decide to roll it back.  To be
cleaned up in subsequent commits...)

XXX kernel ABI change to devsw_detach signature requires bump

diffstat:

 external/cddl/osnet/dev/dtrace/dtrace_modevent.c       |   6 ++----
 external/cddl/osnet/dev/fbt/fbt.c                      |   5 +++--
 external/cddl/osnet/dev/sdt/sdt.c                      |   5 +++--
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c |   2 +-
 share/man/man9/devsw_attach.9                          |  17 ++++++++++-------
 sys/coda/coda_psdev.c                                  |   6 +++---
 sys/dev/ccd.c                                          |   8 ++++----
 sys/dev/clockctl.c                                     |  12 +++++-------
 sys/dev/hdaudio/hdaudio.c                              |  10 +++-------
 sys/dev/i2c/i2c.c                                      |  11 ++++-------
 sys/dev/pad/pad.c                                      |   8 +++-----
 sys/dev/raidframe/rf_netbsdkintf.c                     |  17 ++++-------------
 sys/dev/sysmon/sysmon.c                                |   6 +++---
 sys/dev/tprof/tprof.c                                  |  12 +++---------
 sys/dist/pf/net/pf_ioctl.c                             |   7 ++++---
 sys/external/bsd/ipf/netinet/ip_fil_netbsd.c           |   6 +++---
 sys/fs/autofs/autofs_vfsops.c                          |   6 ++----
 sys/kern/kern_drvctl.c                                 |  13 ++++---------
 sys/kern/subr_devsw.c                                  |   7 +++----
 sys/modules/examples/pollpal/pollpal.c                 |   7 ++++---
 sys/net/if_tap.c                                       |   9 +++------
 sys/net/if_tun.c                                       |  13 +++----------
 sys/rump/dev/lib/libbpf/bpf_component.c                |   7 +++----
 sys/rump/dev/lib/libdrvctl/drvctl_component.c          |   8 +++-----
 sys/sys/conf.h                                         |   4 ++--
 25 files changed, 85 insertions(+), 127 deletions(-)

diffs (truncated from 749 to 300 lines):

diff -r a6912d81e2a9 -r 7775bf1a281f external/cddl/osnet/dev/dtrace/dtrace_modevent.c
--- a/external/cddl/osnet/dev/dtrace/dtrace_modevent.c  Mon Mar 28 11:21:40 2022 +0000
+++ b/external/cddl/osnet/dev/dtrace/dtrace_modevent.c  Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dtrace_modevent.c,v 1.6 2018/05/28 21:05:03 chs Exp $  */
+/*     $NetBSD: dtrace_modevent.c,v 1.7 2022/03/28 12:33:20 riastradh Exp $    */
 
 /*
  * CDDL HEADER START
@@ -42,9 +42,7 @@
                return error;
 
        case MODULE_CMD_FINI:
-               error = devsw_detach(NULL, &dtrace_cdevsw);
-               if (error != 0)
-                       return error;
+               devsw_detach(NULL, &dtrace_cdevsw);
 
                error = dtrace_unload();
                if (error != 0) {
diff -r a6912d81e2a9 -r 7775bf1a281f external/cddl/osnet/dev/fbt/fbt.c
--- a/external/cddl/osnet/dev/fbt/fbt.c Mon Mar 28 11:21:40 2022 +0000
+++ b/external/cddl/osnet/dev/fbt/fbt.c Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fbt.c,v 1.27 2019/07/16 07:26:00 hannken Exp $ */
+/*     $NetBSD: fbt.c,v 1.28 2022/03/28 12:33:20 riastradh Exp $       */
 
 /*
  * CDDL HEADER START
@@ -1329,7 +1329,8 @@
                error = fbt_unload();
                if (error != 0)
                        return error;
-               return devsw_detach(NULL, &fbt_cdevsw);
+               devsw_detach(NULL, &fbt_cdevsw);
+               return 0;
        case MODULE_CMD_AUTOUNLOAD:
                return EBUSY;
        default:
diff -r a6912d81e2a9 -r 7775bf1a281f external/cddl/osnet/dev/sdt/sdt.c
--- a/external/cddl/osnet/dev/sdt/sdt.c Mon Mar 28 11:21:40 2022 +0000
+++ b/external/cddl/osnet/dev/sdt/sdt.c Mon Mar 28 12:33:20 2022 +0000
@@ -39,7 +39,7 @@
  * unloaded; in particular, probes may not span multiple kernel modules.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdt.c,v 1.20 2019/03/09 18:53:52 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdt.c,v 1.21 2022/03/28 12:33:20 riastradh Exp $");
 
 #include <sys/cdefs.h>
 #include <sys/proc.h>
@@ -562,7 +562,8 @@
                error = sdt_unload();
                if (error != 0)
                        return error;
-               return devsw_detach(NULL, &sdt_cdevsw);
+               devsw_detach(NULL, &sdt_cdevsw);
+               return 0;
        case MODULE_CMD_AUTOUNLOAD:
                return EBUSY;
        default:
diff -r a6912d81e2a9 -r 7775bf1a281f external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c    Mon Mar 28 11:21:40 2022 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c    Mon Mar 28 12:33:20 2022 +0000
@@ -7231,7 +7231,7 @@
                if (error)
                        return error;
 
-               (void) devsw_detach(&zfs_bdevsw, &zfs_cdevsw);
+               devsw_detach(&zfs_bdevsw, &zfs_cdevsw);
 
 attacherr:
                zfs_sysctl_fini();
diff -r a6912d81e2a9 -r 7775bf1a281f share/man/man9/devsw_attach.9
--- a/share/man/man9/devsw_attach.9     Mon Mar 28 11:21:40 2022 +0000
+++ b/share/man/man9/devsw_attach.9     Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: devsw_attach.9,v 1.3 2017/04/30 12:30:00 pgoyette Exp $
+.\"    $NetBSD: devsw_attach.9,v 1.4 2022/03/28 12:33:20 riastradh Exp $
 .\"
 .\" Copyright (c) 2015 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 30, 2017
+.Dd January 11, 2022
 .Dt DEVSW 9
 .Os
 .Sh NAME
@@ -49,7 +49,7 @@
 .Fa "const struct cdevsw *cdev"
 .Fa "devmajor_t *cmajor"
 .Fc
-.Ft int
+.Ft void
 .Fo devsw_detach
 .Fa "const struct bdevsw *bdev"
 .Fa "const struct cdevsw *cdev"
@@ -130,6 +130,11 @@
 structures.
 .Fn devsw_detach
 should be called before a loaded device driver is unloaded.
+The caller must ensure that there are no open instances of the device,
+and that the device's
+.Fn d_open
+function will fail, before calling.
+Fn devsw_detach .
 .Pp
 The
 .Fn bdevsw_lookup
@@ -155,10 +160,8 @@
 .Sh RETURN VALUES
 Upon successful completion,
 .Fn devsw_attach
-and
-.Fn devsw_detach
-return 0.
-Otherwise they return an error value.
+returns 0.
+Otherwise it returns an error value.
 .Pp
 In case of failure,
 .Fn bdevsw_lookup
diff -r a6912d81e2a9 -r 7775bf1a281f sys/coda/coda_psdev.c
--- a/sys/coda/coda_psdev.c     Mon Mar 28 11:21:40 2022 +0000
+++ b/sys/coda/coda_psdev.c     Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: coda_psdev.c,v 1.60 2021/09/26 01:16:08 thorpej Exp $  */
+/*     $NetBSD: coda_psdev.c,v 1.61 2022/03/28 12:33:20 riastradh Exp $        */
 
 /*
  *
@@ -54,7 +54,7 @@
 /* These routines are the device entry points for Venus. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: coda_psdev.c,v 1.60 2021/09/26 01:16:08 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: coda_psdev.c,v 1.61 2022/03/28 12:33:20 riastradh Exp $");
 
 extern int coda_nc_initialized;    /* Set if cache has been initialized */
 
@@ -758,7 +758,7 @@
                                if (VC_OPEN(vcp))
                                        return EBUSY;
                        }
-                       return devsw_detach(NULL, &vcoda_cdevsw);
+                       devsw_detach(NULL, &vcoda_cdevsw);
                }
 #endif
                break;
diff -r a6912d81e2a9 -r 7775bf1a281f sys/dev/ccd.c
--- a/sys/dev/ccd.c     Mon Mar 28 11:21:40 2022 +0000
+++ b/sys/dev/ccd.c     Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ccd.c,v 1.187 2022/03/12 17:27:50 riastradh Exp $      */
+/*     $NetBSD: ccd.c,v 1.188 2022/03/28 12:33:20 riastradh Exp $      */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * from: Utah $Hdr: cd.c 1.6 90/11/28$
+ * from: Utah $Hdr$
  *
  *     @(#)cd.c        8.2 (Berkeley) 11/16/93
  */
@@ -88,7 +88,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.187 2022/03/12 17:27:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ccd.c,v 1.188 2022/03/28 12:33:20 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1710,7 +1710,7 @@
                        error = EBUSY;
                } else {
                        mutex_exit(&ccd_lock);
-                       error = devsw_detach(&ccd_bdevsw, &ccd_cdevsw);
+                       devsw_detach(&ccd_bdevsw, &ccd_cdevsw);
                        ccddetach();
                }
 #endif
diff -r a6912d81e2a9 -r 7775bf1a281f sys/dev/clockctl.c
--- a/sys/dev/clockctl.c        Mon Mar 28 11:21:40 2022 +0000
+++ b/sys/dev/clockctl.c        Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: clockctl.c,v 1.38 2020/02/21 00:26:22 joerg Exp $ */
+/*      $NetBSD: clockctl.c,v 1.39 2022/03/28 12:33:20 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.38 2020/02/21 00:26:22 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clockctl.c,v 1.39 2022/03/28 12:33:20 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ntp.h"
@@ -182,14 +182,12 @@
                        return EBUSY;
                }
 #ifdef _MODULE
-               error = devsw_detach(NULL, &clockctl_cdevsw);
+               devsw_detach(NULL, &clockctl_cdevsw);
 #endif
                mutex_exit(&clockctl_mtx);
 
-               if (error == 0) {
-                       kauth_unlisten_scope(clockctl_listener);
-                       mutex_destroy(&clockctl_mtx);
-               }
+               kauth_unlisten_scope(clockctl_listener);
+               mutex_destroy(&clockctl_mtx);
                break;
 
        default:
diff -r a6912d81e2a9 -r 7775bf1a281f sys/dev/hdaudio/hdaudio.c
--- a/sys/dev/hdaudio/hdaudio.c Mon Mar 28 11:21:40 2022 +0000
+++ b/sys/dev/hdaudio/hdaudio.c Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hdaudio.c,v 1.16 2021/08/07 16:19:11 thorpej Exp $ */
+/* $NetBSD: hdaudio.c,v 1.17 2022/03/28 12:33:21 riastradh Exp $ */
 
 /*
  * Copyright (c) 2009 Precedence Technologies Ltd <support%precedence.co.uk@localhost>
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.16 2021/08/07 16:19:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.17 2022/03/28 12:33:21 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -1636,11 +1636,7 @@
                error = config_cfdriver_detach(&hdaudio_cd);
                if (error)
                        break;
-               error = devsw_detach(NULL, &hdaudio_cdevsw);
-               if (error) {
-                       config_cfdriver_attach(&hdaudio_cd);
-                       break;
-               }
+               devsw_detach(NULL, &hdaudio_cdevsw);
 #endif
                break;
        default:
diff -r a6912d81e2a9 -r 7775bf1a281f sys/dev/i2c/i2c.c
--- a/sys/dev/i2c/i2c.c Mon Mar 28 11:21:40 2022 +0000
+++ b/sys/dev/i2c/i2c.c Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i2c.c,v 1.84 2022/01/24 09:42:14 andvar Exp $  */
+/*     $NetBSD: i2c.c,v 1.85 2022/03/28 12:33:21 riastradh Exp $       */
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -53,7 +53,7 @@
 #endif /* _KERNEL_OPT */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.84 2022/01/24 09:42:14 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.85 2022/03/28 12:33:21 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -942,7 +942,7 @@
                if (error) {
                        aprint_error("%s: unable to init component\n",
                            iic_cd.cd_name);
-                       (void)devsw_detach(NULL, &iic_cdevsw);
+                       devsw_detach(NULL, &iic_cdevsw);
                }
                mutex_exit(&iic_mtx);
 #endif
@@ -960,10 +960,7 @@
                        mutex_exit(&iic_mtx);
                        break;
                }
-               error = devsw_detach(NULL, &iic_cdevsw);
-               if (error != 0)
-                       config_init_component(cfdriver_ioconf_iic,
-                           cfattach_ioconf_iic, cfdata_ioconf_iic);
+               devsw_detach(NULL, &iic_cdevsw);
 #endif
                mutex_exit(&iic_mtx);
                break;
diff -r a6912d81e2a9 -r 7775bf1a281f sys/dev/pad/pad.c
--- a/sys/dev/pad/pad.c Mon Mar 28 11:21:40 2022 +0000
+++ b/sys/dev/pad/pad.c Mon Mar 28 12:33:20 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.76 2022/03/12 17:07:10 riastradh Exp $ */
+/* $NetBSD: pad.c,v 1.77 2022/03/28 12:33:21 riastradh Exp $ */



Home | Main Index | Thread Index | Old Index