Source-Changes-HG archive

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

[src/pgoyette-localcount]: src Instead of repeatedly typing the conditional i...



details:   https://anonhg.NetBSD.org/src/rev/590cac4d0b30
branches:  pgoyette-localcount
changeset: 852820:590cac4d0b30
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Jul 19 06:26:57 2016 +0000

description:
Instead of repeatedly typing the conditional initialization of the
.d_localcount members in the various {b,c}devsw, define an initializer
macro and use it.  This also removes the need for defining new symbols
for each 'struct localcount'.

As suggested by riastradh@

diffstat:

 external/cddl/osnet/dev/fbt/fbt.c                      |    6 +-
 external/cddl/osnet/dev/sdt/sdt.c                      |    6 +-
 external/cddl/osnet/dist/uts/common/dtrace/dtrace.c    |    4 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c |   12 +-
 sys/arch/acorn26/ioc/arcpp.c                           |   53 ++-
 sys/arch/acorn32/mainbus/fd.c                          |  114 +++++-
 sys/arch/acorn32/podulebus/asc.c                       |    9 +-
 sys/arch/alpha/pci/mcpcia.c                            |   20 +-
 sys/arch/alpha/tc/ioasic.c                             |   32 +-
 sys/arch/amiga/amiga/autoconf.c                        |   25 +-
 sys/arch/amiga/amiga/device.h                          |    5 +-
 sys/arch/amiga/dev/afsc.c                              |   11 +-
 sys/arch/amiga/dev/ahsc.c                              |   11 +-
 sys/arch/amiga/dev/atzsc.c                             |   11 +-
 sys/arch/amiga/dev/bppcsc.c                            |   11 +-
 sys/arch/amiga/dev/cbiiisc.c                           |   11 +-
 sys/arch/amiga/dev/drsc.c                              |   11 +-
 sys/arch/amiga/dev/fd.c                                |   99 +++++-
 sys/arch/amiga/dev/gtsc.c                              |   11 +-
 sys/arch/amiga/dev/mfc.c                               |  266 ++++++++++++++--
 sys/arch/amiga/dev/mgnsc.c                             |   11 +-
 sys/arch/amiga/dev/ms.c                                |   65 +++-
 sys/arch/amiga/dev/ser.c                               |   35 +-
 sys/arch/amiga/dev/wesc.c                              |   11 +-
 sys/arch/amiga/dev/zssc.c                              |   11 +-
 sys/arch/arc/dev/opms.c                                |   90 +++++-
 sys/arch/arc/dev/pccons.c                              |  144 +++++++-
 sys/arch/arc/jazz/fd.c                                 |   64 +++-
 sys/arch/arm/amlogic/amlogic_com.c                     |  140 +++++++-
 sys/arch/arm/at91/at91dbgu.c                           |  223 +++++++++++--
 sys/arch/arm/at91/at91usart.c                          |  222 +++++++++++--
 sys/dev/audio.c                                        |   12 +-
 sys/dev/cgd.c                                          |   16 +-
 sys/dev/dm/device-mapper.c                             |   14 +-
 sys/dev/fss.c                                          |   16 +-
 sys/dev/ld.c                                           |   16 +-
 sys/dev/md.c                                           |   16 +-
 sys/dev/pad/pad.c                                      |   12 +-
 sys/dev/pci/pci_usrreq.c                               |   12 +-
 sys/dev/pud/pud_dev.c                                  |   16 +-
 sys/dev/putter/putter.c                                |   11 +-
 sys/dev/raidframe/rf_netbsdkintf.c                     |   16 +-
 sys/dev/rndpseudo.c                                    |   12 +-
 sys/dev/scsipi/cd.c                                    |   16 +-
 sys/dev/scsipi/sd.c                                    |   16 +-
 sys/dev/sysmon/sysmon.c                                |   12 +-
 sys/dev/usb/ucom.c                                     |   12 +-
 sys/dev/usb/ulpt.c                                     |   12 +-
 sys/dev/vnd.c                                          |   16 +-
 sys/dev/wscons/wskbd.c                                 |   12 +-
 sys/dev/wscons/wsmouse.c                               |   12 +-
 sys/external/bsd/ipf/netinet/ip_fil_netbsd.c           |   15 +-
 sys/kern/kern_drvctl.c                                 |   12 +-
 sys/kern/tty_ptm.c                                     |   16 +-
 sys/kern/tty_pty.c                                     |   16 +-
 sys/kern/tty_tty.c                                     |   12 +-
 sys/net/bpf.c                                          |   28 +-
 sys/net/if_tap.c                                       |   12 +-
 sys/net/npf/npf.c                                      |   12 +-
 sys/netsmb/smb_dev.c                                   |   12 +-
 sys/opencrypto/cryptodev.c                             |   12 +-
 sys/rump/dev/lib/libbpf/bpf_component.c                |    6 +-
 sys/rump/librump/rumpvfs/devnull.c                     |   12 +-
 sys/rump/librump/rumpvfs/rumpblk.c                     |   20 +-
 sys/sys/localcount.h                                   |    9 +-
 65 files changed, 1523 insertions(+), 692 deletions(-)

diffs (truncated from 5653 to 300 lines):

diff -r f9b1c4c7c3a6 -r 590cac4d0b30 external/cddl/osnet/dev/fbt/fbt.c
--- a/external/cddl/osnet/dev/fbt/fbt.c Mon Jul 18 22:00:05 2016 +0000
+++ b/external/cddl/osnet/dev/fbt/fbt.c Tue Jul 19 06:26:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fbt.c,v 1.18.2.3 2016/07/18 03:50:58 pgoyette Exp $    */
+/*     $NetBSD: fbt.c,v 1.18.2.4 2016/07/19 06:27:00 pgoyette Exp $    */
 
 /*
  * CDDL HEADER START
@@ -152,9 +152,8 @@
 #define        FBT_ADDR2NDX(addr)      ((((uintptr_t)(addr)) >> 4) & fbt_probetab_mask)
 #define        FBT_PROBETAB_SIZE       0x8000          /* 32k entries -- 128K total */
 
-struct localcount fbt_localcount;
-
 static const struct cdevsw fbt_cdevsw = {
+       LOCALCOUNT_INITIALIZER
        .d_open         = fbt_open,
        .d_close        = noclose,
        .d_read         = noread,
@@ -166,7 +165,6 @@
        .d_mmap         = nommap,
        .d_kqfilter     = nokqfilter,
        .d_discard      = nodiscard,
-       .d_localcount   = &fbt_localcount,
        .d_flag         = D_OTHER
 };
 
diff -r f9b1c4c7c3a6 -r 590cac4d0b30 external/cddl/osnet/dev/sdt/sdt.c
--- a/external/cddl/osnet/dev/sdt/sdt.c Mon Jul 18 22:00:05 2016 +0000
+++ b/external/cddl/osnet/dev/sdt/sdt.c Tue Jul 19 06:26:57 2016 +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.16.2.3 2016/07/18 03:50:58 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdt.c,v 1.16.2.4 2016/07/19 06:27:00 pgoyette Exp $");
 
 #include <sys/cdefs.h>
 #include <sys/param.h>
@@ -119,9 +119,8 @@
        return (0);
 }
 
-struct localcount sdt_localcount;
-
 static const struct cdevsw sdt_cdevsw = {
+       LOCALCOUNT_INITIALIZER
        .d_open         = sdt_open,
        .d_close        = noclose,
        .d_read         = noread,
@@ -133,7 +132,6 @@
        .d_mmap         = nommap,
        .d_kqfilter     = nokqfilter,
        .d_discard      = nodiscard,
-       .d_localcount   = &sdt_localcount,
        .d_flag         = D_OTHER
 };
 #endif
diff -r f9b1c4c7c3a6 -r 590cac4d0b30 external/cddl/osnet/dist/uts/common/dtrace/dtrace.c
--- a/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c       Mon Jul 18 22:00:05 2016 +0000
+++ b/external/cddl/osnet/dist/uts/common/dtrace/dtrace.c       Tue Jul 19 06:26:57 2016 +0000
@@ -15339,9 +15339,8 @@
 /* Pseudo Device Entry points */
 /* Just opens, clones to the fileops below */
 
-struct localcount dtrace_localcount;
-
 const struct cdevsw dtrace_cdevsw = {
+       LOCALCOUNT_INITIALIZER
        .d_open         = dtrace_open,
        .d_close        = noclose,
        .d_read         = noread,
@@ -15353,7 +15352,6 @@
        .d_mmap         = nommap,
        .d_kqfilter     = nokqfilter,
        .d_discard      = nodiscard,
-       .d_localcount   = &dtrace_localcount,
        .d_flag         = D_OTHER | D_MPSAFE
 };
 
diff -r f9b1c4c7c3a6 -r 590cac4d0b30 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c    Mon Jul 18 22:00:05 2016 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ioctl.c    Tue Jul 19 06:26:57 2016 +0000
@@ -4563,24 +4563,19 @@
            &rval);
 }
 
-#ifdef _MODULE
-struct localcount zfs_b_localcount, zfs_c_localcount;
-#endif
-
 const struct bdevsw zfs_bdevsw = {
+       LOCALCOUNT_INITIALIZER
        .d_open = nb_zvol_bopen,
        .d_close = nb_zvol_bclose,
        .d_strategy = zvol_strategy,
        .d_ioctl = nb_zfsdev_ioctl,
        .d_dump = nodump,
        .d_psize = nosize,
-#ifdef _MODULE
-       .d_localcount = &zfs_b_localcount,
-#endif
        .d_flag = D_DISK | D_MPSAFE
 };
 
 const struct cdevsw zfs_cdevsw = {
+       LOCALCOUNT_INITIALIZER
        .d_open = nb_zvol_copen,
        .d_close = nb_zvol_cclose,
        .d_read = nb_zvol_read,
@@ -4591,9 +4586,6 @@
        .d_poll = nopoll,
        .d_mmap = nommap,
        .d_kqfilter = nokqfilter,
-#ifdef _MODULE
-       .d_localcount = &zfs_c_localcount,
-#endif
        .d_flag = D_DISK | D_MPSAFE
 };
 
diff -r f9b1c4c7c3a6 -r 590cac4d0b30 sys/arch/acorn26/ioc/arcpp.c
--- a/sys/arch/acorn26/ioc/arcpp.c      Mon Jul 18 22:00:05 2016 +0000
+++ b/sys/arch/acorn26/ioc/arcpp.c      Tue Jul 19 06:26:57 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: arcpp.c,v 1.15 2015/08/30 04:16:18 dholland Exp $ */
+/* $NetBSD: arcpp.c,v 1.15.2.1 2016/07/19 06:26:57 pgoyette Exp $ */
 
 /*-
  * Copyright (c) 2001 Ben Harris
@@ -52,7 +52,7 @@
 
 #include <sys/param.h>
 
-__KERNEL_RCSID(0, "$NetBSD: arcpp.c,v 1.15 2015/08/30 04:16:18 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arcpp.c,v 1.15.2.1 2016/07/19 06:26:57 pgoyette Exp $");
 
 #include <sys/conf.h>
 #include <sys/device.h>
@@ -191,10 +191,16 @@
        bus_space_tag_t iot;
        bus_space_handle_t ioh;
        int error, s;
+       device_t self;
 
-       sc = device_lookup_private(&arcpp_cd, ARCPPUNIT(dev));
-       if (sc == NULL)
+       self = device_lookup_acquire(&arcpp_cd, minor(dev));
+       if (self == NULL)
                return ENXIO;
+       sc = device_private(self);
+       if (sc == NULL) {
+               error = ENXIO;
+               goto out;
+       }
 
 #ifdef DIAGNOSTIC
        if (sc->sc_state)
@@ -202,8 +208,10 @@
                    sc->sc_state);
 #endif
 
-       if (sc->sc_state)
-               return EBUSY;
+       if (sc->sc_state) {
+               error = EBUSY;
+               goto out;
+       }
 
        sc->sc_state = ARCPP_INIT;
        sc->sc_flags = flags;
@@ -218,12 +226,13 @@
        if (error == EWOULDBLOCK) {
                sc->sc_state = 0;
                splx(s);
-               return EBUSY;
+               error = EBUSY;
+               goto out;
        }
        if (error) {
                sc->sc_state = 0;
                splx(s);
-               return error;
+               goto out;
        }
 
        sc->sc_inbuf = malloc(ARCPP_BSIZE, M_DEVBUF, M_WAITOK);
@@ -235,6 +244,9 @@
        splx(s);
 
        return 0;
+
+ out:  device_release(self);
+       return error;
 }
 
 /*
@@ -243,8 +255,17 @@
 int
 arcppclose(dev_t dev, int flag, int mode, struct lwp *l)
 {
-       struct arcpp_softc *sc = device_lookup_private(&arcpp_cd, ARCPPUNIT(dev));
+       device_t self;
+       struct arcpp_softc *sc;
 
+       self = device_lookup_acquire(&arcpp_cd, minor(dev));
+       if (self == NULL)
+               return ENXIO;
+       sc = device_private(&arcpp_cd, ARCPPUNIT(dev));
+       if (sc == NULL) {
+               device_release(self);
+               return ENXIO;
+       }
        if (sc->sc_count)
                (void) arcpppushbytes(sc);
 
@@ -253,6 +274,7 @@
        sc->sc_state = 0;
        free(sc->sc_inbuf, M_DEVBUF);
 
+       device_release(self);
        return 0;
 }
 
@@ -279,10 +301,19 @@
 int
 arcppwrite(dev_t dev, struct uio *uio, int flags)
 {
-       struct arcpp_softc *sc = device_lookup_private(&arcpp_cd, ARCPPUNIT(dev));
+       device_t self;
+       struct arcpp_softc *sc;
        size_t n;
        int error = 0;
 
+       self = device_lookup_acquire(&arcpp_cd, minor(dev));
+       if (self == NULL)
+               return ENXIO;
+       sc = device_private(&arcpp_cd, ARCPPUNIT(dev));
+       if (sc == NULL) {
+               device_release(self);
+               return ENXIO;
+       }
        while ((n = min(ARCPP_BSIZE, uio->uio_resid)) != 0) {
                uiomove(sc->sc_cp = sc->sc_inbuf, n, uio);
                sc->sc_count = n;
@@ -294,9 +325,11 @@
                         */
                        uio->uio_resid += sc->sc_count;
                        sc->sc_count = 0;
+                       device_release(self);
                        return error;
                }
        }
+       device_release(self);
        return 0;
 }
 
diff -r f9b1c4c7c3a6 -r 590cac4d0b30 sys/arch/acorn32/mainbus/fd.c
--- a/sys/arch/acorn32/mainbus/fd.c     Mon Jul 18 22:00:05 2016 +0000
+++ b/sys/arch/acorn32/mainbus/fd.c     Tue Jul 19 06:26:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fd.c,v 1.58 2015/04/26 15:15:19 mlelstv Exp $  */
+/*     $NetBSD: fd.c,v 1.58.2.1 2016/07/19 06:26:57 pgoyette Exp $     */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -82,7 +82,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.58 2015/04/26 15:15:19 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.58.2.1 2016/07/19 06:26:57 pgoyette Exp $");
 
 #include "opt_ddb.h"
 
@@ -567,10 +567,20 @@
 void
 fdstrategy(struct buf *bp)
 {
-       struct fd_softc *fd = device_lookup_private(&fd_cd,FDUNIT(bp->b_dev));
+       device_t self;
+       struct fd_softc *fd
        int sz;
        int s;
 
+       self = device_lookup_acquire(&fd_cd, FDUNIT(bp->b_dev);
+       if (self == NULL)
+               return;
+       fd = device_private(self);
+       if (fd == NULL) {
+               bp->b_error = ENXIO;
+               return;
+       }
+
        /* Valid unit, controller, and request? */
        if (bp->b_blkno < 0 ||
            ((bp->b_bcount % FDC_BSIZE) != 0 &&
@@ -625,12 +635,14 @@
        }
 #endif



Home | Main Index | Thread Index | Old Index