Module Name:    src
Committed By:   christos
Date:           Fri Dec  9 17:18:35 UTC 2016

Modified Files:
        src/sys/dev/ofisa: ess_ofisa.c if_cs_ofisa.c joy_ofisa.c ofisa.c
            ofisavar.h sb_ofisa.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/ofisa/ess_ofisa.c \
    src/sys/dev/ofisa/if_cs_ofisa.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/ofisa/joy_ofisa.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/ofisa/ofisa.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/ofisa/ofisavar.h
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/ofisa/sb_ofisa.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ofisa/ess_ofisa.c
diff -u src/sys/dev/ofisa/ess_ofisa.c:1.26 src/sys/dev/ofisa/ess_ofisa.c:1.27
--- src/sys/dev/ofisa/ess_ofisa.c:1.26	Fri Dec  9 11:22:09 2016
+++ src/sys/dev/ofisa/ess_ofisa.c	Fri Dec  9 12:18:35 2016
@@ -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 @@ ess_ofisa_attach(device_t parent, device
 		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);
 }
Index: src/sys/dev/ofisa/if_cs_ofisa.c
diff -u src/sys/dev/ofisa/if_cs_ofisa.c:1.26 src/sys/dev/ofisa/if_cs_ofisa.c:1.27
--- src/sys/dev/ofisa/if_cs_ofisa.c:1.26	Mon Apr 13 12:33:24 2015
+++ src/sys/dev/ofisa/if_cs_ofisa.c	Fri Dec  9 12:18:35 2016
@@ -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 @@ cs_ofisa_attach(device_t parent, device_
 	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 @@ cs_ofisa_attach(device_t parent, device_
 	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 @@ cs_ofisa_attach(device_t parent, device_
 	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 @@ cs_ofisa_attach(device_t parent, device_
 		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 @@ cs_ofisa_attach(device_t parent, device_
 	/* 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 @@ cs_ofisa_attach(device_t parent, device_
 	    &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");

Index: src/sys/dev/ofisa/joy_ofisa.c
diff -u src/sys/dev/ofisa/joy_ofisa.c:1.15 src/sys/dev/ofisa/joy_ofisa.c:1.16
--- src/sys/dev/ofisa/joy_ofisa.c:1.15	Wed Nov 23 18:07:33 2011
+++ src/sys/dev/ofisa/joy_ofisa.c	Fri Dec  9 12:18:35 2016
@@ -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 @@ joy_ofisa_attach(device_t parent, device
 	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 @@ joy_ofisa_attach(device_t parent, device
 		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;

Index: src/sys/dev/ofisa/ofisa.c
diff -u src/sys/dev/ofisa/ofisa.c:1.24 src/sys/dev/ofisa/ofisa.c:1.25
--- src/sys/dev/ofisa/ofisa.c:1.24	Fri Jun  3 03:39:30 2011
+++ src/sys/dev/ofisa/ofisa.c	Fri Dec  9 12:18:35 2016
@@ -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 @@ ofisa_reg_count(int phandle)
 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 @@ ofisa_reg_get(int phandle, struct ofisa_
 	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 @@ ofisa_reg_get(int phandle, struct ofisa_
 	rv = i;		/* number of descriptors processed (== ndescs) */
 
 out:
-	if (allocated)
+	if (buf != small)
 		free(buf, M_TEMP);
 	return (rv);
 }
@@ -221,8 +219,8 @@ ofisa_intr_count(int phandle)
 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 @@ ofisa_intr_get(int phandle, struct ofisa
 	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 @@ ofisa_intr_get(int phandle, struct ofisa
 	rv = i;		/* number of descriptors processed (== ndescs) */
 
 out:
-	if (allocated)
+	if (buf != small)
 		free(buf, M_TEMP);
 	return (rv);
 }
@@ -305,8 +301,8 @@ ofisa_dma_count(int phandle)
 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)
@@ -317,10 +313,8 @@ ofisa_dma_get(int phandle, struct ofisa_
 	i = ndescs * 20;
 	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, "dma", buf, i) != proplen) {
@@ -338,7 +332,7 @@ ofisa_dma_get(int phandle, struct ofisa_
 	rv = i;		/* number of descriptors processed (== ndescs) */
 
 out:
-	if (allocated)
+	if (buf != small)
 		free(buf, M_TEMP);
 	return (rv);
 }
@@ -386,3 +380,29 @@ ofisa_dma_print(struct ofisa_dma_desc *d
 
 	}
 }
+
+void
+ofisa_print_model(device_t self, int phandle)
+{
+	char *model, small[OFW_MAX_STACK_BUF_SIZE];
+        int n = OF_getproplen(phandle, "model");
+
+        if (n <= 0)
+		return;
+
+	if (n > OFW_MAX_STACK_BUF_SIZE) {
+		model = malloc(n, M_TEMP, M_WAITOK);
+	} else {
+		model = small;
+	}
+
+	if (OF_getprop(phandle, "model", model, n) != n)
+		goto out;
+		
+	aprint_normal(": %s\n", model);
+	if (self)
+		aprint_normal_dev(self, "");
+out:
+	if (model != small)
+		free(model, M_TEMP);
+}

Index: src/sys/dev/ofisa/ofisavar.h
diff -u src/sys/dev/ofisa/ofisavar.h:1.6 src/sys/dev/ofisa/ofisavar.h:1.7
--- src/sys/dev/ofisa/ofisavar.h:1.6	Sun Dec 11 07:22:48 2005
+++ src/sys/dev/ofisa/ofisavar.h	Fri Dec  9 12:18:35 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofisavar.h,v 1.6 2005/12/11 12:22:48 christos Exp $	*/
+/*	$NetBSD: ofisavar.h,v 1.7 2016/12/09 17:18:35 christos Exp $	*/
 
 /*
  * Copyright 1998
@@ -98,5 +98,6 @@ void	ofisa_intr_print(struct ofisa_intr_
 int	ofisa_dma_count(int);
 int	ofisa_dma_get(int, struct ofisa_dma_desc *, int);
 void	ofisa_dma_print(struct ofisa_dma_desc *, int);
+void	ofisa_print_model(device_t, int);
 
 #endif /* _DEV_OFISA_OFISAVAR_H_ */

Index: src/sys/dev/ofisa/sb_ofisa.c
diff -u src/sys/dev/ofisa/sb_ofisa.c:1.17 src/sys/dev/ofisa/sb_ofisa.c:1.18
--- src/sys/dev/ofisa/sb_ofisa.c:1.17	Mon Apr 28 16:23:54 2008
+++ src/sys/dev/ofisa/sb_ofisa.c	Fri Dec  9 12:18:35 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: sb_ofisa.c,v 1.17 2008/04/28 20:23:54 martin Exp $	*/
+/*	$NetBSD: sb_ofisa.c,v 1.18 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: sb_ofisa.c,v 1.17 2008/04/28 20:23:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sb_ofisa.c,v 1.18 2016/12/09 17:18:35 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -91,8 +91,7 @@ sb_ofisa_attach(device_t parent, device_
 	struct ofisa_reg_desc reg;
 	struct ofisa_intr_desc intr;
 	struct ofisa_dma_desc dma[2];
-	int n, ndrq;
-	char *model;
+	int ndrq;
 
 	sc->sc_dev = self;
 
@@ -109,28 +108,28 @@ sb_ofisa_attach(device_t parent, device_
 
 	n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
 	if (n != 1) {
-		printf(": error getting register data\n");
+		aprint_error(": error getting register data\n");
 		return;
 	}
 	if (reg.type != OFISA_REG_TYPE_IO) {
-		printf(": register type not i/o\n");
+		aprint_error(": register type not i/o\n");
 		return;
 	}
 	if (reg.len != SB_NPORT && reg.len != SBP_NPORT) {
-		printf(": weird register size (%lu, expected %d or %d)\n",
+		aprint_error(": weird register size (%lu, expected %d or %d)\n",
 		    (unsigned long)reg.len, SB_NPORT, SBP_NPORT);
 		return;
 	}
 
 	n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
 	if (n != 1) {
-		printf(": error getting interrupt data\n");
+		aprint_error(": error getting interrupt data\n");
 		return;
 	}
 
 	ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2);
 	if (ndrq != 1 && ndrq != 2) {
-		printf(": error getting DMA data\n");
+		aprint_error(": error getting DMA data\n");
 		return;
 	}
 
@@ -179,12 +178,7 @@ sb_ofisa_attach(device_t parent, device_
 	sc->sc_ih = isa_intr_establish(aa->ic, intr.irq, IST_EDGE, IPL_AUDIO,
 	    sbdsp_intr, sc);
 
-	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)
-			aprint_normal(": %s\n%s", model, device_xname(self));
-	}
+	ofisa_print_model(self, aa->oba.oba_phandle);
 
 	sbattach(sc);
 }

Reply via email to