Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev - Always validate the return value read from the out...
details: https://anonhg.NetBSD.org/src/rev/ef52b78fbdf4
branches: trunk
changeset: 521178:ef52b78fbdf4
user: ad <ad%NetBSD.org@localhost>
date: Fri Jan 25 16:10:35 2002 +0000
description:
- Always validate the return value read from the outbound FIFO.
- Copy access method info into the softc so we don't double dereference.
- Remove static on functions.
diffstat:
sys/dev/eisa/cac_eisa.c | 38 +++++++++++-----------
sys/dev/ic/cac.c | 84 ++++++++++++++++++++++++++----------------------
sys/dev/ic/cacvar.h | 6 +-
sys/dev/ic/ld_cac.c | 26 +++++++-------
sys/dev/pci/cac_pci.c | 61 +++++++++++++++++++----------------
5 files changed, 114 insertions(+), 101 deletions(-)
diffs (truncated from 651 to 300 lines):
diff -r b88853fcbc03 -r ef52b78fbdf4 sys/dev/eisa/cac_eisa.c
--- a/sys/dev/eisa/cac_eisa.c Fri Jan 25 15:35:43 2002 +0000
+++ b/sys/dev/eisa/cac_eisa.c Fri Jan 25 16:10:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cac_eisa.c,v 1.4 2001/11/15 09:48:03 lukem Exp $ */
+/* $NetBSD: cac_eisa.c,v 1.5 2002/01/25 16:10:37 ad Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cac_eisa.c,v 1.4 2001/11/15 09:48:03 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cac_eisa.c,v 1.5 2002/01/25 16:10:37 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -87,20 +87,20 @@
#define CAC_EISA_IOSIZE 0x0017
#define CAC_EISA_IOCONF 0x38
-static void cac_eisa_attach(struct device *, struct device *, void *);
-static int cac_eisa_match(struct device *, struct cfdata *, void *);
+void cac_eisa_attach(struct device *, struct device *, void *);
+int cac_eisa_match(struct device *, struct cfdata *, void *);
-static struct cac_ccb *cac_eisa_l0_completed(struct cac_softc *);
-static int cac_eisa_l0_fifo_full(struct cac_softc *);
-static void cac_eisa_l0_intr_enable(struct cac_softc *, int);
-static int cac_eisa_l0_intr_pending(struct cac_softc *);
-static void cac_eisa_l0_submit(struct cac_softc *, struct cac_ccb *);
+struct cac_ccb *cac_eisa_l0_completed(struct cac_softc *);
+int cac_eisa_l0_fifo_full(struct cac_softc *);
+void cac_eisa_l0_intr_enable(struct cac_softc *, int);
+int cac_eisa_l0_intr_pending(struct cac_softc *);
+void cac_eisa_l0_submit(struct cac_softc *, struct cac_ccb *);
struct cfattach cac_eisa_ca = {
sizeof(struct cac_softc), cac_eisa_match, cac_eisa_attach
};
-static struct cac_linkage cac_eisa_l0 = {
+static const struct cac_linkage cac_eisa_l0 = {
cac_eisa_l0_completed,
cac_eisa_l0_fifo_full,
cac_eisa_l0_intr_enable,
@@ -111,7 +111,7 @@
struct cac_eisa_type {
const char *ct_prodstr;
const char *ct_typestr;
- struct cac_linkage *ct_linkage;
+ const struct cac_linkage *ct_linkage;
} static cac_eisa_type[] = {
{ "CPQ4001", "IDA", &cac_eisa_l0 },
{ "CPQ4002", "IDA-2", &cac_eisa_l0 },
@@ -120,7 +120,7 @@
{ "CPQ4030", "SMART-2/E", &cac_l0 },
};
-static int
+int
cac_eisa_match(struct device *parent, struct cfdata *match, void *aux)
{
struct eisa_attach_args *ea;
@@ -135,7 +135,7 @@
return (0);
}
-static void
+void
cac_eisa_attach(struct device *parent, struct device *self, void *aux)
{
struct eisa_attach_args *ea;
@@ -206,7 +206,7 @@
break;
printf(": Compaq %s\n", cac_eisa_type[i].ct_typestr);
- sc->sc_cl = cac_eisa_type[i].ct_linkage;
+ memcpy(&sc->sc_cl, cac_eisa_type[i].ct_linkage, sizeof(sc->sc_cl));
cac_init(sc, intrstr, 0);
}
@@ -214,7 +214,7 @@
* Linkage specific to EISA boards.
*/
-static int
+int
cac_eisa_l0_fifo_full(struct cac_softc *sc)
{
@@ -222,7 +222,7 @@
CAC_EISA_CHANNEL_CLEAR) == 0);
}
-static void
+void
cac_eisa_l0_submit(struct cac_softc *sc, struct cac_ccb *ccb)
{
u_int16_t size;
@@ -243,7 +243,7 @@
cac_outb(sc, CAC_EISAREG_LOCAL_DOORBELL, CAC_EISA_CHANNEL_BUSY);
}
-static struct cac_ccb *
+struct cac_ccb *
cac_eisa_l0_completed(struct cac_softc *sc)
{
struct cac_ccb *ccb;
@@ -272,7 +272,7 @@
return (ccb);
}
-static int
+int
cac_eisa_l0_intr_pending(struct cac_softc *sc)
{
@@ -280,7 +280,7 @@
CAC_EISA_CHANNEL_BUSY);
}
-static void
+void
cac_eisa_l0_intr_enable(struct cac_softc *sc, int state)
{
diff -r b88853fcbc03 -r ef52b78fbdf4 sys/dev/ic/cac.c
--- a/sys/dev/ic/cac.c Fri Jan 25 15:35:43 2002 +0000
+++ b/sys/dev/ic/cac.c Fri Jan 25 16:10:35 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cac.c,v 1.19 2001/11/13 13:14:35 lukem Exp $ */
+/* $NetBSD: cac.c,v 1.20 2002/01/25 16:10:35 ad Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cac.c,v 1.19 2001/11/13 13:14:35 lukem Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cac.c,v 1.20 2002/01/25 16:10:35 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -62,24 +62,24 @@
#include <dev/ic/cacreg.h>
#include <dev/ic/cacvar.h>
-static struct cac_ccb *cac_ccb_alloc(struct cac_softc *, int);
-static void cac_ccb_done(struct cac_softc *, struct cac_ccb *);
-static void cac_ccb_free(struct cac_softc *, struct cac_ccb *);
-static int cac_ccb_poll(struct cac_softc *, struct cac_ccb *, int);
-static int cac_ccb_start(struct cac_softc *, struct cac_ccb *);
-static int cac_print(void *, const char *);
-static void cac_shutdown(void *);
-static int cac_submatch(struct device *, struct cfdata *, void *);
+struct cac_ccb *cac_ccb_alloc(struct cac_softc *, int);
+void cac_ccb_done(struct cac_softc *, struct cac_ccb *);
+void cac_ccb_free(struct cac_softc *, struct cac_ccb *);
+int cac_ccb_poll(struct cac_softc *, struct cac_ccb *, int);
+int cac_ccb_start(struct cac_softc *, struct cac_ccb *);
+int cac_print(void *, const char *);
+void cac_shutdown(void *);
+int cac_submatch(struct device *, struct cfdata *, void *);
-static struct cac_ccb *cac_l0_completed(struct cac_softc *);
-static int cac_l0_fifo_full(struct cac_softc *);
-static void cac_l0_intr_enable(struct cac_softc *, int);
-static int cac_l0_intr_pending(struct cac_softc *);
-static void cac_l0_submit(struct cac_softc *, struct cac_ccb *);
+struct cac_ccb *cac_l0_completed(struct cac_softc *);
+int cac_l0_fifo_full(struct cac_softc *);
+void cac_l0_intr_enable(struct cac_softc *, int);
+int cac_l0_intr_pending(struct cac_softc *);
+void cac_l0_submit(struct cac_softc *, struct cac_ccb *);
static void *cac_sdh; /* shutdown hook */
-struct cac_linkage cac_l0 = {
+const struct cac_linkage cac_l0 = {
cac_l0_completed,
cac_l0_fifo_full,
cac_l0_intr_enable,
@@ -186,14 +186,14 @@
if (cac_sdh == NULL)
cac_sdh = shutdownhook_establish(cac_shutdown, NULL);
- (*sc->sc_cl->cl_intr_enable)(sc, CAC_INTR_ENABLE);
+ (*sc->sc_cl.cl_intr_enable)(sc, CAC_INTR_ENABLE);
return (0);
}
/*
* Shut down all `cac' controllers.
*/
-static void
+void
cac_shutdown(void *cookie)
{
extern struct cfdriver cac_cd;
@@ -214,7 +214,7 @@
/*
* Print autoconfiguration message for a sub-device.
*/
-static int
+int
cac_print(void *aux, const char *pnp)
{
struct cac_attach_args *caca;
@@ -230,7 +230,7 @@
/*
* Match a sub-device.
*/
-static int
+int
cac_submatch(struct device *parent, struct cfdata *cf, void *aux)
{
struct cac_attach_args *caca;
@@ -256,14 +256,14 @@
sc = (struct cac_softc *)cookie;
- if (!(*sc->sc_cl->cl_intr_pending)(sc)) {
+ if (!(*sc->sc_cl.cl_intr_pending)(sc)) {
#ifdef DEBUG
printf("%s: spurious intr\n", sc->sc_dv.dv_xname);
#endif
return (0);
}
- while ((ccb = (*sc->sc_cl->cl_completed)(sc)) != NULL) {
+ while ((ccb = (*sc->sc_cl.cl_completed)(sc)) != NULL) {
cac_ccb_done(sc, ccb);
cac_ccb_start(sc, NULL);
}
@@ -331,14 +331,14 @@
s = splbio();
/* Synchronous commands musn't wait. */
- if ((*sc->sc_cl->cl_fifo_full)(sc)) {
+ if ((*sc->sc_cl.cl_fifo_full)(sc)) {
cac_ccb_free(sc, ccb);
rv = -1;
} else {
#ifdef DIAGNOSTIC
ccb->ccb_flags |= CAC_CCB_ACTIVE;
#endif
- (*sc->sc_cl->cl_submit)(sc, ccb);
+ (*sc->sc_cl.cl_submit)(sc, ccb);
rv = cac_ccb_poll(sc, ccb, 2000);
cac_ccb_free(sc, ccb);
}
@@ -355,7 +355,7 @@
/*
* Wait for the specified CCB to complete. Must be called at splbio.
*/
-static int
+int
cac_ccb_poll(struct cac_softc *sc, struct cac_ccb *wantccb, int timo)
{
struct cac_ccb *ccb;
@@ -364,13 +364,14 @@
do {
for (; timo != 0; timo--) {
- if ((ccb = (*sc->sc_cl->cl_completed)(sc)) != NULL)
+ ccb = (*sc->sc_cl.cl_completed)(sc);
+ if (ccb != NULL)
break;
DELAY(100);
}
if (timo == 0) {
- printf("%s: timeout", sc->sc_dv.dv_xname);
+ printf("%s: timeout\n", sc->sc_dv.dv_xname);
return (EBUSY);
}
cac_ccb_done(sc, ccb);
@@ -383,7 +384,7 @@
* Enqueue the specifed command (if any) and attempt to start all enqueued
* commands. Must be called at splbio.
*/
-static int
+int
cac_ccb_start(struct cac_softc *sc, struct cac_ccb *ccb)
{
@@ -391,13 +392,13 @@
SIMPLEQ_INSERT_TAIL(&sc->sc_ccb_queue, ccb, ccb_chain);
while ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_queue)) != NULL) {
- if ((*sc->sc_cl->cl_fifo_full)(sc))
+ if ((*sc->sc_cl.cl_fifo_full)(sc))
return (EBUSY);
SIMPLEQ_REMOVE_HEAD(&sc->sc_ccb_queue, ccb, ccb_chain);
#ifdef DIAGNOSTIC
ccb->ccb_flags |= CAC_CCB_ACTIVE;
#endif
Home |
Main Index |
Thread Index |
Old Index