From cfaba33937475c0383ec0477c3843be790f6be24 Mon Sep 17 00:00:00 2001 From: thorpej Date: Thu, 6 Jul 2000 00:43:04 +0000 Subject: [PATCH] Use device_lookup(). --- sys/dev/ata/wd.c | 31 ++++++++++--------------------- sys/dev/audio.c | 21 +++++++++------------ sys/dev/midi.c | 16 ++++++++-------- 3 files changed, 27 insertions(+), 41 deletions(-) diff --git a/sys/dev/ata/wd.c b/sys/dev/ata/wd.c index dcbfff692f2a..385131bca574 100644 --- a/sys/dev/ata/wd.c +++ b/sys/dev/ata/wd.c @@ -1,4 +1,4 @@ -/* $NetBSD: wd.c,v 1.207 2000/07/05 23:31:13 thorpej Exp $ */ +/* $NetBSD: wd.c,v 1.208 2000/07/06 00:43:36 thorpej Exp $ */ /* * Copyright (c) 1998 Manuel Bouyer. All rights reserved. @@ -713,16 +713,12 @@ wdopen(dev, flag, fmt, p) struct proc *p; { struct wd_softc *wd; - int unit, part; - int error; + int part, error; WDCDEBUG_PRINT(("wdopen\n"), DEBUG_FUNCS); - unit = WDUNIT(dev); - if (unit >= wd_cd.cd_ndevs) - return ENXIO; - wd = wd_cd.cd_devs[unit]; + wd = device_lookup(&wd_cd, WDUNIT(dev)); if (wd == NULL) - return ENXIO; + return (ENXIO); /* * If this is the first open of this device, add a reference @@ -1098,15 +1094,12 @@ wdsize(dev) dev_t dev; { struct wd_softc *wd; - int part, unit, omask; + int part, omask; int size; WDCDEBUG_PRINT(("wdsize\n"), DEBUG_FUNCS); - unit = WDUNIT(dev); - if (unit >= wd_cd.cd_ndevs) - return (-1); - wd = wd_cd.cd_devs[unit]; + wd = device_lookup(&wd_cd, WDUNIT(dev)); if (wd == NULL) return (-1); @@ -1142,9 +1135,8 @@ wddump(dev, blkno, va, size) { struct wd_softc *wd; /* disk unit to do the I/O */ struct disklabel *lp; /* disk's disklabel */ - int unit, part; + int part, err; int nblks; /* total number of sectors left to write */ - int err; char errbuf[256]; /* Check if recursive dump; if so, punt. */ @@ -1152,12 +1144,9 @@ wddump(dev, blkno, va, size) return EFAULT; wddoingadump = 1; - unit = WDUNIT(dev); - if (unit >= wd_cd.cd_ndevs) - return ENXIO; - wd = wd_cd.cd_devs[unit]; - if (wd == (struct wd_softc *)0) - return ENXIO; + wd = device_lookup(&wd_cd, WDUNIT(dev)); + if (wd == NULL) + return (ENXIO); part = WDPART(dev); diff --git a/sys/dev/audio.c b/sys/dev/audio.c index 1c6be2199cf2..0008e4afe47e 100644 --- a/sys/dev/audio.c +++ b/sys/dev/audio.c @@ -1,4 +1,4 @@ -/* $NetBSD: audio.c,v 1.129 2000/06/27 21:25:02 augustss Exp $ */ +/* $NetBSD: audio.c,v 1.130 2000/07/06 00:43:04 thorpej Exp $ */ /* * Copyright (c) 1991-1993 Regents of the University of California. @@ -555,12 +555,11 @@ audioopen(dev, flags, ifmt, p) int flags, ifmt; struct proc *p; { - int unit = AUDIOUNIT(dev); struct audio_softc *sc; int error; - if (unit >= audio_cd.cd_ndevs || - (sc = audio_cd.cd_devs[unit]) == NULL) + sc = device_lookup(&audio_cd, AUDIOUNIT(dev)); + if (sc == NULL) return (ENXIO); if (sc->sc_dying) @@ -621,13 +620,12 @@ audioread(dev, uio, ioflag) struct uio *uio; int ioflag; { - int unit = AUDIOUNIT(dev); struct audio_softc *sc; int error; - if (unit >= audio_cd.cd_ndevs || - (sc = audio_cd.cd_devs[unit]) == NULL) - return ENXIO; + sc = device_lookup(&audio_cd, AUDIOUNIT(dev)); + if (sc == NULL) + return (ENXIO); if (sc->sc_dying) return (EIO); @@ -657,13 +655,12 @@ audiowrite(dev, uio, ioflag) struct uio *uio; int ioflag; { - int unit = AUDIOUNIT(dev); struct audio_softc *sc; int error; - if (unit >= audio_cd.cd_ndevs || - (sc = audio_cd.cd_devs[unit]) == NULL) - return ENXIO; + sc = device_lookup(&audio_cd, AUDIOUNIT(dev)); + if (sc == NULL) + return (ENXIO); if (sc->sc_dying) return (EIO); diff --git a/sys/dev/midi.c b/sys/dev/midi.c index 6523ad6c27ed..4fef44b0c1c8 100644 --- a/sys/dev/midi.c +++ b/sys/dev/midi.c @@ -1,4 +1,4 @@ -/* $NetBSD: midi.c,v 1.16 2000/05/06 14:35:28 augustss Exp $ */ +/* $NetBSD: midi.c,v 1.17 2000/07/06 00:43:04 thorpej Exp $ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -344,14 +344,14 @@ midiopen(dev, flags, ifmt, p) int flags, ifmt; struct proc *p; { - int unit = MIDIUNIT(dev); struct midi_softc *sc; struct midi_hw_if *hw; int error; - if (unit >= midi_cd.cd_ndevs || - (sc = midi_cd.cd_devs[unit]) == NULL) - return ENXIO; + sc = device_lookup(&midi_cd, MIDIUNIT(dev)); + if (sc == NULL) + return (ENXIO); + DPRINTF(("midiopen %p\n", sc)); hw = sc->hw_if; @@ -726,12 +726,12 @@ midi_getinfo(dev, mi) dev_t dev; struct midi_info *mi; { - int unit = MIDIUNIT(dev); struct midi_softc *sc; - if (unit >= midi_cd.cd_ndevs || - (sc = midi_cd.cd_devs[unit]) == NULL) + sc = device_lookup(&midi_cd, MIDIUNIT(dev)); + if (sc == NULL) return; + sc->hw_if->getinfo(sc->hw_hdl, mi); }