From nobody Sun Apr 28 19:49:05 2024 X-Original-To: dev-commits-src-main@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 4VSH8f2RLjz5Jr2f; Sun, 28 Apr 2024 19:49:06 +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 4VSH8f0szpz42Wq; Sun, 28 Apr 2024 19:49:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714333746; 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=r8zxLuuECWxpqmyn6jZp2kufxf53CTMfgdM8kAU3xWU=; b=ncI+00blLPgfi86fNrFv9PTGsW9I7/VYkRQ6wlq0/HuT9vmbQtWL5emf8ePq3ZfNjbsvSk SugEb+jWP+50EqDwCRlimOwdR+zhYZ0No1xqQZk3K4t+/UGsNsPr7An7768ho4IY8EzAyb MvvouJckX2s808IbpkserkU4ppsH74oibrwJMyMpwhuBQQjROXJrYjyppPZkbNTi2Frzbr UxIhdb8TigsXN6N6b15t1iHI0E4LuIxVBf9pNIur85j5sDvZatGeDhNpyL+OeF1A+kajTN 2H+ZuzwbT/s6wlfjNoTx+jXCBYtyN8VZOgeH9UAWa1ouxjmhHALaxED4z1wZ5g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714333746; a=rsa-sha256; cv=none; b=CSr6Rwxg8d8h5lpA8uONQu2GJHhpHCF6wiu3SYq/qptJD+JgAOLgt0ksib4JtEUV67Z/zN 967oOjY9QL35sHgC06JtdeqGu6UGWGmr/cHDzuV5BQYnmPq+dFAfe+dQwxaPMq6sE3HqJW HJfe9f7sfsL/RqFa1j3P7VNOVaCR9dQmmdsca8NdFl3tt7x+UBmRTtPNZoFAMrG5gm8NLC 1d3ea/5X1KeRwc2q0h1nYUi2iF8nibS/S2ooP3NodFDZDIpQPAujmoBMRdXTi7GxkbKFyC f7Ocw8OYLQ8nVjyV4W0+ZDmIzJOtZ7igPee4tLeufEOI/vLgO6ae9QbuiAXHhQ== 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=1714333746; 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=r8zxLuuECWxpqmyn6jZp2kufxf53CTMfgdM8kAU3xWU=; b=ZxZHOImbR+Of9KT9PTs5sIYc1wFKnLTfSvcOHb4TOhg9iqxD/Yx5INNxLNxClIxK7IsEm2 53XzuikBZblJQ7jG01cDZMsNJ+QmRvH4Ew8A0hmBE/FIxDNTRUAuAK9wkFaVDi3mPvLk74 ngYtznslr0500fDVssJPk8fwRLwzRdd3ogUOSPGVQX1XgWg5rtRuw5/VmtH2zdp/KF/dOV 7Bb/cpNnEQJEXQ/TLz68szTubk4qmv0mldrwV+t5J0u84Tg2zxz7RVT+QmBACgJ+yYa/fH rgHTFGOCiVtzITMBSKejKiqINC7fq933JRE7CAJbK6/3wqOFks9FSpfHUlGYEQ== 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 4VSH8f0V44zf8M; Sun, 28 Apr 2024 19:49:06 +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 43SJn5mY063568; Sun, 28 Apr 2024 19:49:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43SJn5dF063565; Sun, 28 Apr 2024 19:49:05 GMT (envelope-from git) Date: Sun, 28 Apr 2024 19:49:05 GMT Message-Id: <202404281949.43SJn5dF063565@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: a24050e2b784 - main - sound: Move pcm_chnref() and pcm_chnrelease() to pcm/channel.c List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: a24050e2b784e13561da3ab731a1db92f2e3366c Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=a24050e2b784e13561da3ab731a1db92f2e3366c commit a24050e2b784e13561da3ab731a1db92f2e3366c Author: Christos Margiolis AuthorDate: 2024-04-28 19:46:55 +0000 Commit: Christos Margiolis CommitDate: 2024-04-28 19:48:24 +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 --- 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 b44a7344121c..029326dfc05a 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);