From nobody Sat Jul 06 18:24:15 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WGf0w0DsHz5PMRr; Sat, 06 Jul 2024 18:24:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WGf0v5KgMz54G9; Sat, 6 Jul 2024 18:24:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720290255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=s82fzPSiuoi06iSxPPbviBKrH0nAVeF26bJx30CMjao=; b=fpPaZHktvCfS+j82jugHksPtEXcc8Bndi5W6s/lurb6FG+GF+gfD9o1dLVYOZYCQP53uD0 nT9P1dlp771Jmgh+gHA1ut8ya7oSAYgv29gACUJtfjJAo4so9pMi1pWtoLFXx4inInkPmS djvpI30g6VSCuvkbk/ga3S+rAZpaBhlVspWhNN1fAiAl2SwimHo+dJRR1Kfh0U0R2Advr6 yFFw7nlaovCjsrSJbb0x+GvYoeC4SQ/EdtYVLXPbV3cU7NEkMTlnl8WMY9F1J/6r/l7QyC OhQ+ttxrKjSgoJ9jtMpdeV9Q6eRfzivAmO+fNZKHdOmOvZ4uhZTX0TsV7ibm2Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720290255; a=rsa-sha256; cv=none; b=AzKGnZhGDqV8qc/trZd2+PBDqAJD85FBHyOTRn/URE/OQBLuHumhFY/8As8tfwohsC/oPR NCyF+IAJJ8p1ujEUAfeicNntdpa6XsYFfPZgBqyfXWdbnhPRHOlmgGS+iluWb+Hqxo9Tqu TGZIt/c1ikU+c++tRMvXhs/obvI1gxkr+nMoibCCmoys3fYlUldoe4otZ2WVuZjeambgNS gASPrOBYIk06ryQ2GEZSf7RGSJXjeZ16AEDOA1/Fkq7wg0YpfnaedA8YFx/qVKtZOWmCLS nzhdvykoz5Iz/ai+795wQ1ezYeUQDZd9GxQkADjUr8XUyopoa21LwsLx/MxeUQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720290255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=s82fzPSiuoi06iSxPPbviBKrH0nAVeF26bJx30CMjao=; b=iz/c4ZVzvLmsioT+4LpeO/WuWhFEsEJivofAwI8854OGZVoDXxdOgjIcw4V9/t0FdV3tEk n9woT0pmb/SKs/lc7/5L5dljakWWK+8FOkQPNNYVBIHOKuv5PN9V+xeFx3kSSvn0MJ8EtH mRCt0obYsMpW7CJRB90xWeXttN7v0qYEo4tikO1uYBwcT+rFXreWAW8xzpPkvVgTirqngl IKutKXcgv7+PJTXqnNH7jNExlf0k8objG7UuQzo7QCTKoz/4JdZssn22YIb+wCSFXiklsS FV15duO4rJvWuJS0eJ+Yl3Hj0+zaI4gMl43FvRM2jAxMN6XV/+72XOA8TlkJBw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WGf0v4xGQzqpy; Sat, 6 Jul 2024 18:24:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 466IOFtL090937; Sat, 6 Jul 2024 18:24:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 466IOF5P090934; Sat, 6 Jul 2024 18:24:15 GMT (envelope-from git) Date: Sat, 6 Jul 2024 18:24:15 GMT Message-Id: <202407061824.466IOF5P090934@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 2d6fc24673cc - main - sound: Handle midistat_lock through function interface List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2d6fc24673ccc97020c94094f97ee015f1db9702 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=2d6fc24673ccc97020c94094f97ee015f1db9702 commit 2d6fc24673ccc97020c94094f97ee015f1db9702 Author: Christos Margiolis AuthorDate: 2024-07-06 18:22:59 +0000 Commit: Christos Margiolis CommitDate: 2024-07-06 18:22:59 +0000 sound: Handle midistat_lock through function interface midistat_lock is used outside midi/midi.c as well, so implement lock, unlock and lockassert functions in order not to expose the lock in the header file. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D45857 --- sys/dev/sound/midi/midi.c | 76 ++++++++++++++++++++++++++---------------- sys/dev/sound/midi/midi.h | 6 ++-- sys/dev/sound/midi/sequencer.c | 4 +-- 3 files changed, 53 insertions(+), 33 deletions(-) diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c index 66fb67b31e7a..c42cb1d7a90c 100644 --- a/sys/dev/sound/midi/midi.c +++ b/sys/dev/sound/midi/midi.c @@ -177,7 +177,7 @@ TAILQ_HEAD(, snd_midi) midi_devs; * /dev/midistat variables and declarations, protected by midistat_lock */ -struct sx midistat_lock; +struct sx mstat_lock; static int midistat_isopen = 0; static struct sbuf midistat_sbuf; @@ -258,6 +258,24 @@ SYSCTL_INT(_hw_midi_stat, OID_AUTO, verbose, CTLFLAG_RW, * CODE START */ +void +midistat_lock(void) +{ + sx_xlock(&mstat_lock); +} + +void +midistat_unlock(void) +{ + sx_xunlock(&mstat_lock); +} + +void +midistat_lockassert(void) +{ + sx_assert(&mstat_lock, SA_XLOCKED); +} + /* * Register a new rmidi device. cls midi_if interface unit == 0 means * auto-assign new unit number unit != 0 already assigned a unit number, eg. @@ -280,7 +298,7 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie) uint8_t *buf; MIDI_DEBUG(1, printf("midiinit: unit %d/%d.\n", unit, channel)); - sx_xlock(&midistat_lock); + midistat_lock(); /* * Protect against call with existing unit/channel or auto-allocate a * new unit number. @@ -358,7 +376,7 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie) TAILQ_INSERT_TAIL(&midi_devs, m, link); - sx_xunlock(&midistat_lock); + midistat_unlock(); m->dev = make_dev(&midi_cdevsw, unit, UID_ROOT, GID_WHEEL, 0666, "midi%d.%d", unit, channel); @@ -378,7 +396,7 @@ err1: free(m->synth, M_MIDI); free(m, M_MIDI); err0: - sx_xunlock(&midistat_lock); + midistat_unlock(); MIDI_DEBUG(1, printf("midi_init ended in error\n")); return NULL; } @@ -396,7 +414,7 @@ midi_uninit(struct snd_midi *m) int err; err = EBUSY; - sx_xlock(&midistat_lock); + midistat_lock(); mtx_lock(&m->lock); if (m->busy) { if (!(m->rchan || m->wchan)) @@ -418,7 +436,7 @@ midi_uninit(struct snd_midi *m) err: mtx_unlock(&m->lock); exit: - sx_xunlock(&midistat_lock); + midistat_unlock(); return err; } @@ -926,9 +944,9 @@ midistat_open(struct cdev *i_dev, int flags, int mode, struct thread *td) MIDI_DEBUG(1, printf("midistat_open\n")); - sx_xlock(&midistat_lock); + midistat_lock(); if (midistat_isopen) { - sx_xunlock(&midistat_lock); + midistat_unlock(); return EBUSY; } midistat_isopen = 1; @@ -940,7 +958,7 @@ midistat_open(struct cdev *i_dev, int flags, int mode, struct thread *td) out: if (error) midistat_isopen = 0; - sx_xunlock(&midistat_lock); + midistat_unlock(); return error; } @@ -948,14 +966,14 @@ static int midistat_close(struct cdev *i_dev, int flags, int mode, struct thread *td) { MIDI_DEBUG(1, printf("midistat_close\n")); - sx_xlock(&midistat_lock); + midistat_lock(); if (!midistat_isopen) { - sx_xunlock(&midistat_lock); + midistat_unlock(); return EBADF; } sbuf_delete(&midistat_sbuf); midistat_isopen = 0; - sx_xunlock(&midistat_lock); + midistat_unlock(); return 0; } @@ -966,13 +984,13 @@ midistat_read(struct cdev *i_dev, struct uio *uio, int flag) int err; MIDI_DEBUG(4, printf("midistat_read\n")); - sx_xlock(&midistat_lock); + midistat_lock(); if (!midistat_isopen) { - sx_xunlock(&midistat_lock); + midistat_unlock(); return EBADF; } if (uio->uio_offset < 0 || uio->uio_offset > sbuf_len(&midistat_sbuf)) { - sx_xunlock(&midistat_lock); + midistat_unlock(); return EINVAL; } err = 0; @@ -981,7 +999,7 @@ midistat_read(struct cdev *i_dev, struct uio *uio, int flag) err = uiomove(sbuf_data(&midistat_sbuf) + uio->uio_offset, l, uio); } - sx_xunlock(&midistat_lock); + midistat_unlock(); return err; } @@ -994,7 +1012,7 @@ midistat_prepare(struct sbuf *s) { struct snd_midi *m; - sx_assert(&midistat_lock, SA_XLOCKED); + midistat_lockassert(); sbuf_printf(s, "FreeBSD Midi Driver (midi2)\n"); if (TAILQ_EMPTY(&midi_devs)) { @@ -1353,7 +1371,7 @@ midisynth_bender(void *n, uint8_t chn, uint16_t val) static int midi_destroy(struct snd_midi *m, int midiuninit) { - sx_assert(&midistat_lock, SA_XLOCKED); + midistat_lockassert(); mtx_assert(&m->lock, MA_OWNED); MIDI_DEBUG(3, printf("midi_destroy\n")); @@ -1379,7 +1397,7 @@ midi_destroy(struct snd_midi *m, int midiuninit) static int midi_load(void) { - sx_init(&midistat_lock, "midistat lock"); + sx_init(&mstat_lock, "midistat lock"); TAILQ_INIT(&midi_devs); midistat_dev = make_dev(&midistat_cdevsw, MIDI_DEV_MIDICTL, UID_ROOT, @@ -1396,7 +1414,7 @@ midi_unload(void) MIDI_DEBUG(1, printf("midi_unload()\n")); retval = EBUSY; - sx_xlock(&midistat_lock); + midistat_lock(); if (midistat_isopen) goto exit0; @@ -1409,19 +1427,19 @@ midi_unload(void) if (retval) goto exit1; } - sx_xunlock(&midistat_lock); + midistat_unlock(); destroy_dev(midistat_dev); /* * Made it here then unload is complete */ - sx_destroy(&midistat_lock); + sx_destroy(&mstat_lock); return 0; exit1: mtx_unlock(&m->lock); exit0: - sx_xunlock(&midistat_lock); + midistat_unlock(); if (retval) MIDI_DEBUG(2, printf("midi_unload: failed\n")); return retval; @@ -1470,7 +1488,7 @@ midimapper_open_locked(void *arg1, void **cookie) int retval = 0; struct snd_midi *m; - sx_assert(&midistat_lock, SX_XLOCKED); + midistat_lockassert(); TAILQ_FOREACH(m, &midi_devs, link) { retval++; } @@ -1483,9 +1501,9 @@ midimapper_open(void *arg1, void **cookie) { int retval; - sx_xlock(&midistat_lock); + midistat_lock(); retval = midimapper_open_locked(arg1, cookie); - sx_xunlock(&midistat_lock); + midistat_unlock(); return retval; } @@ -1502,7 +1520,7 @@ midimapper_fetch_synth_locked(void *arg, void *cookie, int unit) struct snd_midi *m; int retval = 0; - sx_assert(&midistat_lock, SX_XLOCKED); + midistat_lockassert(); TAILQ_FOREACH(m, &midi_devs, link) { if (unit == retval) return (kobj_t)m->synth; @@ -1517,9 +1535,9 @@ midimapper_fetch_synth(void *arg, void *cookie, int unit) { kobj_t synth; - sx_xlock(&midistat_lock); + midistat_lock(); synth = midimapper_fetch_synth_locked(arg, cookie, unit); - sx_xunlock(&midistat_lock); + midistat_unlock(); return synth; } diff --git a/sys/dev/sound/midi/midi.h b/sys/dev/sound/midi/midi.h index afbfdfa6abbc..2254fab690e9 100644 --- a/sys/dev/sound/midi/midi.h +++ b/sys/dev/sound/midi/midi.h @@ -39,10 +39,12 @@ MALLOC_DECLARE(M_MIDI); #define M_RXEN 0x04 #define M_TXEN 0x08 -extern struct sx midistat_lock; - struct snd_midi; +void midistat_lock(void); +void midistat_unlock(void); +void midistat_lockassert(void); + struct snd_midi * midi_init(kobj_class_t _mpu_cls, int _unit, int _channel, void *cookie); int midi_uninit(struct snd_midi *_m); diff --git a/sys/dev/sound/midi/sequencer.c b/sys/dev/sound/midi/sequencer.c index 01f9d0b4809b..6b3a2711e951 100644 --- a/sys/dev/sound/midi/sequencer.c +++ b/sys/dev/sound/midi/sequencer.c @@ -746,7 +746,7 @@ mseq_open(struct cdev *i_dev, int flags, int mode, struct thread *td) * Mark this device busy. */ - sx_xlock(&midistat_lock); + midistat_lock(); mtx_lock(&scp->seq_lock); if (scp->busy) { mtx_unlock(&scp->seq_lock); @@ -784,7 +784,7 @@ mseq_open(struct cdev *i_dev, int flags, int mode, struct thread *td) } } } - sx_xunlock(&midistat_lock); + midistat_unlock(); timer_setvals(scp, 60, 100);