Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ofisa Factor our model printing code; use aprint; el...



details:   https://anonhg.NetBSD.org/src/rev/9b5dd23e3b6e
branches:  trunk
changeset: 349394:9b5dd23e3b6e
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Dec 09 17:18:35 2016 +0000

description:
Factor our model printing code; use aprint; eliminate alloca.

diffstat:

 sys/dev/ofisa/ess_ofisa.c   |  15 ++---------
 sys/dev/ofisa/if_cs_ofisa.c |  41 +++++++++++-------------------
 sys/dev/ofisa/joy_ofisa.c   |  15 ++---------
 sys/dev/ofisa/ofisa.c       |  60 ++++++++++++++++++++++++++++++---------------
 sys/dev/ofisa/ofisavar.h    |   3 +-
 sys/dev/ofisa/sb_ofisa.c    |  24 ++++++-----------
 6 files changed, 72 insertions(+), 86 deletions(-)

diffs (truncated from 443 to 300 lines):

diff -r 14c8f2e889b9 -r 9b5dd23e3b6e sys/dev/ofisa/ess_ofisa.c
--- a/sys/dev/ofisa/ess_ofisa.c Fri Dec 09 16:22:09 2016 +0000
+++ b/sys/dev/ofisa/ess_ofisa.c Fri Dec 09 17:18:35 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ess_ofisa.c,v 1.26 2016/12/09 16:22:09 christos Exp $  */
+/*     $NetBSD: ess_ofisa.c,v 1.27 2016/12/09 17:18:35 christos Exp $  */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ess_ofisa.c,v 1.26 2016/12/09 16:22:09 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ess_ofisa.c,v 1.27 2016/12/09 17:18:35 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -161,16 +161,7 @@
                return;
        }
 
-       n = OF_getproplen(aa->oba.oba_phandle, "model");
-       if (n > 0) {
-               char model[256];
-               if (n > 256)
-                       n = 256;
-               if (OF_getprop(aa->oba.oba_phandle, "model", model, n) == n) {
-                       aprint_normal(": %s\n", model);
-                       aprint_normal_dev(self, "");
-               }
-       }
+       ofisa_print_model(self, aa->oba.oba_phandle);
 
        essattach(sc, 0);
 }
diff -r 14c8f2e889b9 -r 9b5dd23e3b6e sys/dev/ofisa/if_cs_ofisa.c
--- a/sys/dev/ofisa/if_cs_ofisa.c       Fri Dec 09 16:22:09 2016 +0000
+++ b/sys/dev/ofisa/if_cs_ofisa.c       Fri Dec 09 17:18:35 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_cs_ofisa.c,v 1.26 2015/04/13 16:33:24 riastradh Exp $       */
+/*     $NetBSD: if_cs_ofisa.c,v 1.27 2016/12/09 17:18:35 christos Exp $        */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_cs_ofisa.c,v 1.26 2015/04/13 16:33:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_cs_ofisa.c,v 1.27 2016/12/09 17:18:35 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -98,7 +98,6 @@
        struct ofisa_dma_desc dma;
        int i, n, *media, nmedia, defmedia;
        bus_addr_t io_addr, mem_addr;
-       char *model = NULL;
        const char *message = NULL;
        u_int8_t enaddr[6];
 
@@ -126,29 +125,29 @@
        n = cs_ofisa_md_reg_fixup(parent, self, aux, reg, 2, n);
 #endif
        if (n < 1 || n > 2) {
-               printf(": error getting register data\n");
+               aprint_error(": error getting register data\n");
                return;
        }
 
        for (i = 0; i < n; i++) {
                if (reg[i].type == OFISA_REG_TYPE_IO) {
                        if (io_addr != (bus_addr_t) -1) {
-                               printf(": multiple I/O regions\n");
+                               aprint_error(": multiple I/O regions\n");
                                return;
                        }
                        if (reg[i].len != CS8900_IOSIZE) {
-                               printf(": weird register size (%lu, expected %d)\n",
+                               aprint_error(": weird register size (%lu, expected %d)\n",
                                    (unsigned long)reg[i].len, CS8900_IOSIZE);
                                return;
                        }
                        io_addr = reg[i].addr;
                } else {
                        if (mem_addr != (bus_addr_t) -1) {
-                               printf(": multiple memory regions\n");
+                               aprint_error(": multiple memory regions\n");
                                return;
                        }
                        if (reg[i].len != CS8900_MEMSIZE) {
-                               printf(": weird register size (%lu, expected %d)\n",
+                               aprint_error(": weird register size (%lu, expected %d)\n",
                                    (unsigned long)reg[i].len, CS8900_MEMSIZE);
                                return;
                        }
@@ -161,13 +160,13 @@
        n = cs_ofisa_md_intr_fixup(parent, self, aux, &intr, 1, n);
 #endif
        if (n != 1) {
-               printf(": error getting interrupt data\n");
+               aprint_error(": error getting interrupt data\n");
                return;
        }
        sc->sc_irq = intr.irq;
 
        if (CS8900_IRQ_ISVALID(sc->sc_irq) == 0) {
-               printf(": invalid IRQ %d\n", sc->sc_irq);
+               aprint_error(": invalid IRQ %d\n", sc->sc_irq);
                return;
        }
 
@@ -180,12 +179,12 @@
                isc->sc_drq = dma.drq;
 
        if (io_addr == (bus_addr_t) -1) {
-               printf(": no I/O space\n");
+               aprint_error(": no I/O space\n");
                return;
        }
        if (bus_space_map(sc->sc_iot, io_addr, CS8900_IOSIZE, 0,
            &sc->sc_ioh)) {
-               printf(": unable to map register space\n");
+               aprint_error(": unable to map register space\n");
                return;
        }
 
@@ -202,7 +201,7 @@
        /* Dig MAC address out of the firmware. */
        if (OF_getprop(aa->oba.oba_phandle, "mac-address", enaddr,
            sizeof(enaddr)) < 0) {
-               printf(": unable to get Ethernet address\n");
+               aprint_error(": unable to get Ethernet address\n");
                return;
        }
 
@@ -214,23 +213,13 @@
            &defmedia);
 #endif
        if (media == NULL) {
-               printf(": unable to get media information\n");
+               aprint_error(": unable to get media information\n");
                return;
        }
 
-       n = OF_getproplen(aa->oba.oba_phandle, "model");
-       if (n > 0) {
-               model = alloca(n);
-               if (OF_getprop(aa->oba.oba_phandle, "model", model, n) != n)
-                       model = NULL;   /* Safe; alloca is on-stack */
-       }
-       if (model != NULL)
-               printf(": %s\n", model);
-       else
-               printf("\n");
-
+       ofisa_print_model(self, aa->oba.oba_phandle);
        if (message != NULL)
-               printf("%s: %s\n", device_xname(self), message);
+               aprint_normal(": %s\n", message);
 
        if (defmedia == -1) {
                aprint_error_dev(self, "unable to get default media\n");
diff -r 14c8f2e889b9 -r 9b5dd23e3b6e sys/dev/ofisa/joy_ofisa.c
--- a/sys/dev/ofisa/joy_ofisa.c Fri Dec 09 16:22:09 2016 +0000
+++ b/sys/dev/ofisa/joy_ofisa.c Fri Dec 09 17:18:35 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: joy_ofisa.c,v 1.15 2011/11/23 23:07:33 jmcneill Exp $  */
+/*     $NetBSD: joy_ofisa.c,v 1.16 2016/12/09 17:18:35 christos Exp $  */
 
 /*-
  * Copyright (c) 1996, 1998, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: joy_ofisa.c,v 1.15 2011/11/23 23:07:33 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: joy_ofisa.c,v 1.16 2016/12/09 17:18:35 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -80,7 +80,6 @@
        struct joy_softc *sc = &osc->sc_joy;
        struct ofisa_attach_args *aa = aux;
        struct ofisa_reg_desc reg;
-       char *model = NULL;
        int n;
 
        /*
@@ -115,15 +114,7 @@
                return;
        }
 
-       n = OF_getproplen(aa->oba.oba_phandle, "model");
-       if (n > 0) {
-               model = alloca(n);
-               if (OF_getprop(aa->oba.oba_phandle, "model", model, n) != n)
-                       model = NULL;   /* safe; alloca */
-       }
-       if (model != NULL)
-               aprint_normal(": %s", model);
-       aprint_normal("\n");
+       ofisa_print_model(NULL, aa->oba.oba_phandle);
 
        mutex_init(&osc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
        sc->sc_lock = &osc->sc_lock;
diff -r 14c8f2e889b9 -r 9b5dd23e3b6e sys/dev/ofisa/ofisa.c
--- a/sys/dev/ofisa/ofisa.c     Fri Dec 09 16:22:09 2016 +0000
+++ b/sys/dev/ofisa/ofisa.c     Fri Dec 09 17:18:35 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofisa.c,v 1.24 2011/06/03 07:39:30 matt Exp $  */
+/*     $NetBSD: ofisa.c,v 1.25 2016/12/09 17:18:35 christos Exp $      */
 
 /*
  * Copyright 1997, 1998
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofisa.c,v 1.24 2011/06/03 07:39:30 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofisa.c,v 1.25 2016/12/09 17:18:35 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -149,8 +149,8 @@
 int
 ofisa_reg_get(int phandle, struct ofisa_reg_desc *descp, int ndescs)
 {
-       char *buf, *bp;
-       int i, proplen, allocated, rv;
+       char *buf, *bp, small[OFW_MAX_STACK_BUF_SIZE];
+       int i, proplen, rv;
 
        i = ofisa_reg_count(phandle);
        if (i < 0)
@@ -161,10 +161,8 @@
        i = ndescs * 12;
        if (i > OFW_MAX_STACK_BUF_SIZE) {
                buf = malloc(i, M_TEMP, M_WAITOK);
-               allocated = 1;
        } else {
-               buf = alloca(i);
-               allocated = 0;
+               buf = small;
        }
 
        if (OF_getprop(phandle, "reg", buf, i) != proplen) {
@@ -183,7 +181,7 @@
        rv = i;         /* number of descriptors processed (== ndescs) */
 
 out:
-       if (allocated)
+       if (buf != small)
                free(buf, M_TEMP);
        return (rv);
 }
@@ -221,8 +219,8 @@
 int
 ofisa_intr_get(int phandle, struct ofisa_intr_desc *descp, int ndescs)
 {
-       char *buf, *bp;
-       int i, proplen, allocated, rv;
+       char *buf, *bp, small[OFW_MAX_STACK_BUF_SIZE];
+       int i, proplen, rv;
 
        i = ofisa_intr_count(phandle);
        if (i < 0)
@@ -233,10 +231,8 @@
        i = ndescs * 8;
        if (i > OFW_MAX_STACK_BUF_SIZE) {
                buf = malloc(i, M_TEMP, M_WAITOK);
-               allocated = 1;
        } else {
-               buf = alloca(i);
-               allocated = 0;
+               buf = small;
        }
 
        if (OF_getprop(phandle, "interrupts", buf, i) != proplen) {
@@ -268,7 +264,7 @@
        rv = i;         /* number of descriptors processed (== ndescs) */
 
 out:
-       if (allocated)
+       if (buf != small)
                free(buf, M_TEMP);
        return (rv);
 }
@@ -305,8 +301,8 @@
 int
 ofisa_dma_get(int phandle, struct ofisa_dma_desc *descp, int ndescs)
 {
-       char *buf, *bp;
-       int i, proplen, allocated, rv;
+       char *buf, *bp, small[OFW_MAX_STACK_BUF_SIZE];
+       int i, proplen, rv;
 
        i = ofisa_dma_count(phandle);
        if (i < 0)



Home | Main Index | Thread Index | Old Index