From nobody Fri May 17 19:30:57 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 4Vgxrx6s5Dz5LgNG; Fri, 17 May 2024 19:30:57 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vgxrx5VMDz4txD; Fri, 17 May 2024 19:30:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715974257; 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=DHkaQ+ApWiFrY2/JYHvdKuAChprh/uKlub2QEjupx2A=; b=qp/yIDpeX/X3ZWy2J1GQmL/rakLXa3i4GII4553yYxzmjO/BTrro1Exvk52+QebyEv3ATf Yv4AOblmiQv9xXACyad451odU6YxFmw6dDPbZZhF32ViMxvqXIN/KuxeTbacGs29ubZtG5 KezGsmGMkKqsXoldvm/CKmQ/QrNZk62dXEXAXXDqxo5N2/jRr6jOLvsvoC4bwzTa/o3WGl XuwSSJMqIYHKinxHrNuhiwnv8dQO2uDFLWkdW5YysvvOtAVxwqeu60f75Bn0ph6U+Q9NK/ gHukvBq2kVBmhyNjUASQkTns8R1SXS7XaVPRMsyz+VsPNbld/ZQlSQEwid05wA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715974257; a=rsa-sha256; cv=none; b=EFLUltkbQ7cQR0MNOmkfyRCIR9RRKKIxto4pCeDXyra2EEwC7aYzzw058zUCljHW3He2PG ePc5DlZJLpnKRN/lu0WSviz5at5j65byjm2ESaOOQ07fePKkDazIlcBdHnYLLi2tZmIvHo Dht2EWZH5c9okTr9KVvJXlCVR1tBa5DfK7ZlWfABYvkYemBLLrDiWPC/uwVR2Hk6Ak+wud dWnNrX285pMvcaxSG+bh0z8RAm3ZUaPIWPbwFu9DHkEkWP1BxnJjXQa1+YG/tmBelIBIHd uvdL3q04tVtyA29rosPfYLV4VIFfWwJVpOunCRPpWwTFOpgO4y3O2L1fYveBHA== 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=1715974257; 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=DHkaQ+ApWiFrY2/JYHvdKuAChprh/uKlub2QEjupx2A=; b=a6/OdOhc9g96ODWRXCMOOoRdOyHWAfbXJlMTGOiswxgmqh+8ODPRoY/4Urhh1O2jIbBAy9 JIKjapJss5pEa0TaTaTefrkFE+gRrgbid+LSxucSJ7zUp+60T0TGMFq3PVDIN5ilzm6l7x Td9kUdmCUgPP2Ybe2+2mBe9VpMcXKl+m1nQ6bx1ZcxrSCZP4rp4VMuKIdcqnF/ao6Z3Q7I 1JCwOzvZsV4xC9cektyGouD6pdSwDqEJnXHMuGu0Fk6ID5bi1MmYX1X4sCSaCeOvG8IjzL v1ATmULWMVfKfkTs/0CYgEpiatvKzjHBfYMGFZzWavZoiw9UiZSbpTE3YYO58A== 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 4Vgxrx54mxzvsN; Fri, 17 May 2024 19:30:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44HJUvS3099469; Fri, 17 May 2024 19:30:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44HJUvvY099466; Fri, 17 May 2024 19:30:57 GMT (envelope-from git) Date: Fri, 17 May 2024 19:30:57 GMT Message-Id: <202405171930.44HJUvvY099466@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: 930b5a3c07f2 - stable/14 - sound: Move pcm_chnref() and pcm_chnrelease() to pcm/channel.c 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 930b5a3c07f23c8eafbd9ad73d45cc216841e7d3 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=930b5a3c07f23c8eafbd9ad73d45cc216841e7d3 commit 930b5a3c07f23c8eafbd9ad73d45cc216841e7d3 Author: Christos Margiolis AuthorDate: 2024-04-28 19:46:55 +0000 Commit: Christos Margiolis CommitDate: 2024-05-17 19:30:34 +0000 sound: Move pcm_chnref() and pcm_chnrelease() to pcm/channel.c Improve code layering. These are channel functions, and so they do not belong in pcm/sound.c. While here, assert in chn_ref() that new refcount won't be negative. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D44985 (cherry picked from commit a24050e2b784e13561da3ab731a1db92f2e3366c) --- sys/dev/sound/pcm/channel.c | 28 ++++++++++++++++++++++++++++ sys/dev/sound/pcm/channel.h | 2 ++ sys/dev/sound/pcm/dsp.c | 26 +++++++++++++------------- sys/dev/sound/pcm/sound.c | 26 -------------------------- sys/dev/sound/pcm/sound.h | 2 -- 5 files changed, 43 insertions(+), 41 deletions(-) diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index 21a91ff13186..0fea169e3eb7 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -1314,6 +1314,34 @@ chn_shutdown(struct pcm_channel *c) c->flags |= CHN_F_DEAD; } +/* release a locked channel and unlock it */ +int +chn_release(struct pcm_channel *c) +{ + PCM_BUSYASSERT(c->parentsnddev); + CHN_LOCKASSERT(c); + + c->flags &= ~CHN_F_BUSY; + c->pid = -1; + strlcpy(c->comm, CHN_COMM_UNUSED, sizeof(c->comm)); + CHN_UNLOCK(c); + + return (0); +} + +int +chn_ref(struct pcm_channel *c, int ref) +{ + PCM_BUSYASSERT(c->parentsnddev); + CHN_LOCKASSERT(c); + KASSERT((c->refcount + ref) >= 0, + ("%s(): new refcount will be negative", __func__)); + + c->refcount += ref; + + return (c->refcount); +} + int chn_setvolume_multi(struct pcm_channel *c, int vc, int left, int right, int center) diff --git a/sys/dev/sound/pcm/channel.h b/sys/dev/sound/pcm/channel.h index 45381b907fa2..698a1186924f 100644 --- a/sys/dev/sound/pcm/channel.h +++ b/sys/dev/sound/pcm/channel.h @@ -262,6 +262,8 @@ int chn_poll(struct pcm_channel *c, int ev, struct thread *td); int chn_init(struct pcm_channel *c, void *devinfo, int dir, int direction); void chn_kill(struct pcm_channel *c); void chn_shutdown(struct pcm_channel *c); +int chn_release(struct pcm_channel *c); +int chn_ref(struct pcm_channel *c, int ref); int chn_reset(struct pcm_channel *c, u_int32_t fmt, u_int32_t spd); int chn_setvolume_multi(struct pcm_channel *c, int vc, int left, int right, int center); diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index 448ecb183298..9c31fff7e8cd 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -181,8 +181,8 @@ getchns(struct dsp_cdevpriv *priv, uint32_t prio) pcm_setflags(d->dev, flags); if (ch != NULL) { CHN_LOCK(ch); - pcm_chnref(ch, -1); - pcm_chnrelease(ch); + chn_ref(ch, -1); + chn_release(ch); } PCM_RELEASE(d); PCM_UNLOCK(d); @@ -301,7 +301,7 @@ dsp_close(void *data) wdref--; else { CHN_LOCK(volch); - pcm_chnref(volch, -1); + chn_ref(volch, -1); CHN_UNLOCK(volch); } } @@ -332,12 +332,12 @@ dsp_close(void *data) free_unr(pcmsg_unrhdr, sg_ids); CHN_LOCK(rdch); - pcm_chnref(rdch, rdref); + chn_ref(rdch, rdref); chn_abort(rdch); /* won't sleep */ rdch->flags &= ~(CHN_F_RUNNING | CHN_F_MMAP | CHN_F_DEAD | CHN_F_EXCLUSIVE); chn_reset(rdch, 0, 0); - pcm_chnrelease(rdch); + chn_release(rdch); } if (wrch != NULL) { /* @@ -350,12 +350,12 @@ dsp_close(void *data) free_unr(pcmsg_unrhdr, sg_ids); CHN_LOCK(wrch); - pcm_chnref(wrch, wdref); + chn_ref(wrch, wdref); chn_flush(wrch); /* may sleep */ wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MMAP | CHN_F_DEAD | CHN_F_EXCLUSIVE); chn_reset(wrch, 0, 0); - pcm_chnrelease(wrch); + chn_release(wrch); } PCM_LOCK(d); } @@ -451,7 +451,7 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) if (rderror != 0) { if (rdch != NULL) - pcm_chnrelease(rdch); + chn_release(rdch); if (!DSP_F_DUPLEX(flags)) { PCM_RELEASE_QUICK(d); PCM_GIANT_EXIT(d); @@ -463,7 +463,7 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) rdch->flags |= CHN_F_NBIO; if (flags & O_EXCL) rdch->flags |= CHN_F_EXCLUSIVE; - pcm_chnref(rdch, 1); + chn_ref(rdch, 1); chn_vpc_reset(rdch, SND_VOL_C_PCM, 0); CHN_UNLOCK(rdch); } @@ -479,7 +479,7 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) if (wrerror != 0) { if (wrch != NULL) - pcm_chnrelease(wrch); + chn_release(wrch); if (!DSP_F_DUPLEX(flags)) { if (rdch != NULL) { /* @@ -487,8 +487,8 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) * created record channel */ CHN_LOCK(rdch); - pcm_chnref(rdch, -1); - pcm_chnrelease(rdch); + chn_ref(rdch, -1); + chn_release(rdch); } PCM_RELEASE_QUICK(d); PCM_GIANT_EXIT(d); @@ -500,7 +500,7 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td) wrch->flags |= CHN_F_NBIO; if (flags & O_EXCL) wrch->flags |= CHN_F_EXCLUSIVE; - pcm_chnref(wrch, 1); + chn_ref(wrch, 1); chn_vpc_reset(wrch, SND_VOL_C_PCM, 0); CHN_UNLOCK(wrch); } diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c index b3ae93b77a5d..9d5eaf3f5ad7 100644 --- a/sys/dev/sound/pcm/sound.c +++ b/sys/dev/sound/pcm/sound.c @@ -306,32 +306,6 @@ vchan_alloc: return (err); } -/* release a locked channel and unlock it */ -int -pcm_chnrelease(struct pcm_channel *c) -{ - PCM_BUSYASSERT(c->parentsnddev); - CHN_LOCKASSERT(c); - - c->flags &= ~CHN_F_BUSY; - c->pid = -1; - strlcpy(c->comm, CHN_COMM_UNUSED, sizeof(c->comm)); - CHN_UNLOCK(c); - - return (0); -} - -int -pcm_chnref(struct pcm_channel *c, int ref) -{ - PCM_BUSYASSERT(c->parentsnddev); - CHN_LOCKASSERT(c); - - c->refcount += ref; - - return (c->refcount); -} - static void pcm_setmaxautovchans(struct snddev_info *d, int num) { diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h index 70addf32bddd..08aa56cc96f7 100644 --- a/sys/dev/sound/pcm/sound.h +++ b/sys/dev/sound/pcm/sound.h @@ -296,8 +296,6 @@ SYSCTL_DECL(_hw_snd); int pcm_setvchans(struct snddev_info *d, int direction, int newcnt, int num); int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, char *comm); -int pcm_chnrelease(struct pcm_channel *c); -int pcm_chnref(struct pcm_channel *c, int ref); struct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo); int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch);