Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev sequencer(4): Sprinkle KNF.
details: https://anonhg.NetBSD.org/src/rev/3c890ad8be5a
branches: trunk
changeset: 365248:3c890ad8be5a
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sat Apr 16 11:12:21 2022 +0000
description:
sequencer(4): Sprinkle KNF.
- Sort includes.
- Nix trailing whitespace.
- No parens for return.
- Blank line between declarations and statements.
- Note MP bug with unit allocation.
No functional change intended.
diffstat:
sys/dev/sequencer.c | 113 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 71 insertions(+), 42 deletions(-)
diffs (truncated from 412 to 300 lines):
diff -r ac865c74ab82 -r 3c890ad8be5a sys/dev/sequencer.c
--- a/sys/dev/sequencer.c Sat Apr 16 09:53:13 2022 +0000
+++ b/sys/dev/sequencer.c Sat Apr 16 11:12:21 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sequencer.c,v 1.76 2022/03/31 19:30:15 pgoyette Exp $ */
+/* $NetBSD: sequencer.c,v 1.77 2022/04/16 11:12:21 riastradh Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.76 2022/03/31 19:30:15 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.77 2022/04/16 11:12:21 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "sequencer.h"
@@ -63,27 +63,29 @@
#endif
#include <sys/param.h>
-#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include <sys/atomic.h>
+#include <sys/audioio.h>
+#include <sys/conf.h>
+#include <sys/device.h>
#include <sys/fcntl.h>
-#include <sys/vnode.h>
-#include <sys/select.h>
+#include <sys/intr.h>
+#include <sys/ioctl.h>
+#include <sys/kauth.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/midiio.h>
+#include <sys/module.h>
+#include <sys/pcq.h>
#include <sys/poll.h>
-#include <sys/kmem.h>
#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/syslog.h>
-#include <sys/kernel.h>
+#include <sys/select.h>
#include <sys/signalvar.h>
-#include <sys/conf.h>
-#include <sys/audioio.h>
-#include <sys/midiio.h>
-#include <sys/device.h>
-#include <sys/intr.h>
-#include <sys/atomic.h>
-#include <sys/pcq.h>
+#include <sys/syslog.h>
+#include <sys/systm.h>
#include <sys/vnode.h>
-#include <sys/kauth.h>
-#include <sys/module.h>
+#include <sys/vnode.h>
#include <dev/midi_if.h>
#include <dev/midivar.h>
@@ -149,7 +151,8 @@
static int seq_do_timing(struct sequencer_softc *, seq_event_t *);
static int seq_do_local(struct sequencer_softc *, seq_event_t *);
static int seq_do_sysex(struct sequencer_softc *, seq_event_t *);
-static int seq_do_fullsize(struct sequencer_softc *, seq_event_t *, struct uio *);
+static int seq_do_fullsize(struct sequencer_softc *, seq_event_t *,
+ struct uio *);
static int seq_input_event(struct sequencer_softc *, seq_event_t *);
static int seq_drain(struct sequencer_softc *);
static void seq_startoutput(struct sequencer_softc *);
@@ -168,7 +171,8 @@
static int midiseq_chnpressure(struct midi_dev *, int, seq_event_t *);
static int midiseq_ctlchange(struct midi_dev *, int, seq_event_t *);
static int midiseq_pitchbend(struct midi_dev *, int, seq_event_t *);
-static int midiseq_loadpatch(struct midi_dev *, struct sysex_info *, struct uio *);
+static int midiseq_loadpatch(struct midi_dev *, struct sysex_info *,
+ struct uio *);
void midiseq_in(struct midi_dev *, u_char *, int);
static dev_type_open(sequenceropen);
@@ -193,12 +197,14 @@
.d_discard = nodiscard,
.d_flag = D_OTHER | D_MPSAFE
};
-static LIST_HEAD(, sequencer_softc) sequencers = LIST_HEAD_INITIALIZER(sequencers);
+static LIST_HEAD(, sequencer_softc) sequencers =
+ LIST_HEAD_INITIALIZER(sequencers);
static kmutex_t sequencer_lock;
static void
sequencerdestroy(struct sequencer_softc *sc)
{
+
callout_halt(&sc->sc_callout, &sc->lock);
callout_destroy(&sc->sc_callout);
softint_disestablish(sc->sih);
@@ -214,6 +220,7 @@
sequencercreate(int unit)
{
struct sequencer_softc *sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
+
sc->sc_unit = unit;
callout_init(&sc->sc_callout, CALLOUT_MPSAFE);
sc->sih = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
@@ -235,12 +242,14 @@
sequencerget(int unit)
{
struct sequencer_softc *sc;
+
if (unit < 0) {
#ifdef DIAGNOSTIC
panic("%s: unit %d!", __func__, unit);
#endif
return NULL;
}
+
mutex_enter(&sequencer_lock);
LIST_FOREACH(sc, &sequencers, sc_link) {
if (sc->sc_unit == unit) {
@@ -249,18 +258,26 @@
}
}
mutex_exit(&sequencer_lock);
+
+ /*
+ * XXXSMP -- nothing excludes another thread from creating the
+ * same unit here
+ */
if ((sc = sequencercreate(unit)) == NULL)
return NULL;
+
mutex_enter(&sequencer_lock);
LIST_INSERT_HEAD(&sequencers, sc, sc_link);
mutex_exit(&sequencer_lock);
+
return sc;
}
#ifdef notyet
-static void
+static void
sequencerput(struct sequencer_softc *sc)
{
+
mutex_enter(&sequencer_lock);
LIST_REMOVE(sc, sc_link);
mutex_exit(&sequencer_lock);
@@ -271,6 +288,7 @@
void
sequencerattach(int n)
{
+
mutex_init(&sequencer_lock, MUTEX_DEFAULT, IPL_NONE);
}
@@ -297,6 +315,7 @@
/* First, find the device and take sc_lock. */
if ((sc = sequencerget(SEQUENCERUNIT(dev))) == NULL)
return ENXIO;
+
mutex_enter(&sc->lock);
while (sc->dvlock) {
cv_wait(&sc->lchan, &sc->lock);
@@ -400,7 +419,7 @@
error = 0;
while (!SEQ_QEMPTY(&sc->outq) && !error)
error = cv_timedwait_sig(&sc->wchan, &sc->lock, 60*hz);
- return (error);
+ return error;
}
static void
@@ -493,7 +512,7 @@
DPRINTF(("%s: %"PRIx64" done\n", __func__, dev));
- return (0);
+ return 0;
}
static int
@@ -511,7 +530,7 @@
cmd->unknown.byte[6]));
q = &sc->inq;
if (SEQ_QFULL(q))
- return (ENOMEM);
+ return ENOMEM;
SEQ_QPUT(q, *cmd);
cv_broadcast(&sc->rchan);
selnotify(&sc->rsel, 0, NOTE_SUBMIT);
@@ -652,7 +671,7 @@
int error;
seq_event_t cmdbuf;
int size;
-
+
DPRINTFN(2, ("sequencerwrite: %"PRIx64", count=%d\n", dev,
(int)uio->uio_resid));
@@ -869,6 +888,7 @@
{
struct sequencer_softc *sc;
int revents = 0;
+
if ((sc = sequencerget(SEQUENCERUNIT(dev))) == NULL)
return ENXIO;
@@ -976,6 +996,7 @@
{
struct sequencer_softc *sc;
struct selinfo *sip;
+
if ((sc = sequencerget(SEQUENCERUNIT(dev))) == NULL)
return ENXIO;
@@ -991,7 +1012,7 @@
break;
default:
- return (EINVAL);
+ return EINVAL;
}
kn->kn_hook = sc;
@@ -1000,7 +1021,7 @@
selrecord_knote(sip, kn);
mutex_exit(&sc->lock);
- return (0);
+ return 0;
}
static void
@@ -1051,11 +1072,11 @@
case SEQOLD_MIDIPUTC:
dev = b->putc.device;
if (dev < 0 || dev >= sc->nmidi)
- return (ENXIO);
+ return ENXIO;
return midiseq_out(sc->devs[dev], &b->putc.byte, 1, 0);
default:
DPRINTFN(-1,("seq_do_command: unimpl command %02x\n", b->tag));
- return (EINVAL);
+ return EINVAL;
}
}
@@ -1139,7 +1160,7 @@
KASSERT(mutex_owned(&sc->lock));
- return (EINVAL);
+ return EINVAL;
}
static int
@@ -1153,7 +1174,7 @@
dev = b->sysex.device;
if (dev < 0 || dev >= sc->nmidi)
- return (ENXIO);
+ return ENXIO;
DPRINTF(("%s: dev=%d\n", __func__, dev));
md = sc->devs[dev];
@@ -1275,7 +1296,7 @@
error = EINVAL;
break;
}
- return (error);
+ return error;
}
static int
@@ -1293,10 +1314,10 @@
memcpy(&sysex, b, sizeof(*b));
dev = sysex.device_no;
if (/* dev < 0 || */ dev >= sc->nmidi)
- return (ENXIO);
+ return ENXIO;
DPRINTFN(2, ("seq_do_fullsize: fmt=%04x, dev=%d, len=%d\n",
sysex.key, dev, sysex.len));
- return (midiseq_loadpatch(sc->devs[dev], &sysex, uio));
+ return midiseq_loadpatch(sc->devs[dev], &sysex, uio);
}
/*
@@ -1429,7 +1450,7 @@
dev_t dev;
vnode_t *vp;
int oflags;
-
+
major = devsw_name2chr("midi", NULL, 0);
dev = makedev(major, unit);
Home |
Main Index |
Thread Index |
Old Index