From nobody Wed Jul 10 16:49:09 2024 X-Original-To: dev-commits-src-branches@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 4WK3jK5NpTz5Qmyj; Wed, 10 Jul 2024 16:49:09 +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 4WK3jK2dkVz4gbl; Wed, 10 Jul 2024 16:49:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1720630149; 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=vn15dWk9WdFNgwV7FDkymIkyBPhfk9AJxQP2GFxtON4=; b=RqRgKow4DEE7jT2dSXITLenoO/W6AB3w5SzRHEt9i5arFCvrquP+OXnf9MAsVeuexHMz6k WcXVh9L6tU/ESa867iSgYvvsFZUCEsyn88GIyc5ZmBwugT9pV6K2s4sxn6LiYDMwp6/psm +jOjQFz9rgKrLOpeJi8/BKLO3d1kfInTKuPG2uO+dkjy2mPZ9XRQWvRS5q/AoEvfmVi+l4 cgQyoZMfnDThNgFEXMlDom1uG9dEIwKEeIug1p8v+K5I2Y/7gRv5vog+6p8vxUKAffZV2a VLA/1eYRwBarWw40Yj5IUpSmKkfPsSnCzUoDPwcNYyWl3H/NfK7GB2mnldB9pw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1720630149; a=rsa-sha256; cv=none; b=KCqBEM2NdbwSk7Aot/WA6oBn1lEhaQNzfm7Kx6bmVYqyHUiZLsXARMrKW/Q1mC09VruDiN q+OL6O7uHlY61R7XvI22DDquQoU/qJF6Brv+Dvk6hcdW9DjuaZx0lM/F6Qa6Wtoz1UL2My uwfqQ81kXIkYShdGvG9eRUuMoUefaPGsK3R1QkCm39LU2M17Kc5+p0TgL3K3qD3WFQ/F6Y b75/Tv6sgJiM2E2CyM5EKDDVz+dYcEMJ4vuJOjfr0/zvub01X1ulNlJTlVd/W2mgJdDLdU OJk+sHDPuWSt+FYlerQYfdDIVk444Y/G9j/8We8J170XpzfUF11kkwGhdOU5LA== 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=1720630149; 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=vn15dWk9WdFNgwV7FDkymIkyBPhfk9AJxQP2GFxtON4=; b=y1Konem1MIDP4RgXqaIDSmtqZqTGAFzsxptYMe6NDJMq5Q6RPIR3KinqEBqewmdg4I9C6x Kjowkl9SZlqQwNz4nWNPhrHeA+f6bImrYSeKBOC9FMxbfX8++IjUhXwUmVLqKUSR8zUFij sd/VdbvaSofZDjzUMb0s9Xl1OxMqvPyzpjkDpllQYKwlnapaSTqR11AkHs0QkDR3XCV6hf Am6H1QdjRYJMrtD8NFTj/eMPvcQX61RXmo4p4fU1tvLf3hW5JniGsid3Lc6cpoqqbh0Zvx s7W3fO/oa2HRY7MX/cL8ZiCOXZDysErtHrmQMj+ik+37dcGkRQiPxjzsQRoB2g== 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 4WK3jK2DqhzQ5S; Wed, 10 Jul 2024 16:49:09 +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 46AGn9AH035081; Wed, 10 Jul 2024 16:49:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46AGn9co035078; Wed, 10 Jul 2024 16:49:09 GMT (envelope-from git) Date: Wed, 10 Jul 2024 16:49:09 GMT Message-Id: <202407101649.46AGn9co035078@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: ff6b61a2c886 - stable/14 - sound: Handle midistat_lock through function interface List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: ff6b61a2c88631e66287c478cd373ed39878b174 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=ff6b61a2c88631e66287c478cd373ed39878b174 commit ff6b61a2c88631e66287c478cd373ed39878b174 Author: Christos Margiolis AuthorDate: 2024-07-06 18:22:59 +0000 Commit: Christos Margiolis CommitDate: 2024-07-10 16:48:13 +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 (cherry picked from commit 2d6fc24673ccc97020c94094f97ee015f1db9702) --- 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 2dcd64625b6c..d2b495ea04cd 100644 --- a/sys/dev/sound/midi/midi.c +++ b/sys/dev/sound/midi/midi.c @@ -178,7 +178,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; @@ -259,6 +259,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. @@ -281,7 +299,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. @@ -359,7 +377,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); @@ -379,7 +397,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; } @@ -397,7 +415,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)) @@ -419,7 +437,7 @@ midi_uninit(struct snd_midi *m) err: mtx_unlock(&m->lock); exit: - sx_xunlock(&midistat_lock); + midistat_unlock(); return err; } @@ -927,9 +945,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; @@ -941,7 +959,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; } @@ -949,14 +967,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; } @@ -967,13 +985,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; @@ -982,7 +1000,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; } @@ -995,7 +1013,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)) { @@ -1354,7 +1372,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")); @@ -1380,7 +1398,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, @@ -1397,7 +1415,7 @@ midi_unload(void) MIDI_DEBUG(1, printf("midi_unload()\n")); retval = EBUSY; - sx_xlock(&midistat_lock); + midistat_lock(); if (midistat_isopen) goto exit0; @@ -1410,19 +1428,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; @@ -1471,7 +1489,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++; } @@ -1484,9 +1502,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; } @@ -1503,7 +1521,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; @@ -1518,9 +1536,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 ec99fdea4637..ab2d48294a6a 100644 --- a/sys/dev/sound/midi/sequencer.c +++ b/sys/dev/sound/midi/sequencer.c @@ -747,7 +747,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); @@ -785,7 +785,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);