From nobody Fri Apr 25 22:03:56 2025 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 4Zkn190Kzrz5t7Xv; Fri, 25 Apr 2025 22:03: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zkn185dWVz3D9p; Fri, 25 Apr 2025 22:03:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745618636; 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=Um7eyxVv3UZGECKLYruuogHN7Fhmu/zqRYZ2XPxId+M=; b=r+ck4Jg5bA4nVgexPYb6bJmN/s3ngv2IZ20U2JqlOP+3Yt2zD6Yl4ZAHciY3hOgkdIhVG5 kY3QH8Xefm9OfRAwJfzcLRuRMnhhCpn+mRSGuZwuVGivVTPeXwEw95eCMpn8lhHFwZo9U4 avZHykSSIWQTvJ/bJ5ZD6LijlxXvHfRIbrVN4aPXjDtiFCO6mLTuIeiJeLZABhF9MNqWY4 GJFXgEVgRvIyWCxqIL296mRh3+Iex9Y74oyPHdyQbt8LRjr37YG2CnIM38H3kmRuLFnJLQ yLM0oCKgqLii11E3QYC49IvstNrl0eiwGYpI8HxxzoByp5QBuDDMDMRSnm+Psg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745618636; a=rsa-sha256; cv=none; b=oxYyKbK1iNpvWTbcgpJ1eHUe3mqgYtPJ/iP+59Cr5mtEM1s+fmN0zwB/B4cG2r1YqGuC+W rIhEcPdZ4qV5/awJE1CV8HuyDViplImbxuSLSYljEYzSqU1kuGG+jrmYq+m1KDtYloqzQY Tn1Ty7zFzyJBbMNE7pa44YH8Z46bNnpCFJegi/dfJCaDWMWJQx8CJaizXIkiPsMLF9I6CF TsdlVWpu5ojGul2+flpcoAZj1x6CFO0b1uG4FQwdkHX/eC38oXTw2CA2lc/VbUzK6Neb5F CIoQOo7U4iA5tLOON3wVFnHso9lY317CwOd1OF2GvIShbLDdy/9W12KozpbVHQ== 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=1745618636; 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=Um7eyxVv3UZGECKLYruuogHN7Fhmu/zqRYZ2XPxId+M=; b=BHIhAwLEOV0C+CS+glmAVbNjhL9LuyoE5CO25ueyn4HMFSC94+D1FCd9oeUhez8+bCsj1j XCD4D3Te9tlNibGwLKVCGVooMUdmtRpp5xF3HCrtghpMe+OxJpAHsTysboqQSTa1ryhqTm vx2WnL48WdSZtUhx8oDgq7Z6d59qV+qL6+DmiJzJHZa4kJlnMHie9o73eg0A0yPjJSp9NZ dNMpp5Oy1YMfIC/gP8CUvNY3v+S4GGezJbTm3mx6jBNoE1zk+3cnCAg1iGdg+LFZ9BuUZG LuYjGP/z/YUYzlthAjDx/2pReC1PkDOPAU9w+thjthEz11VMm1xCmG6Btyfn/w== 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 4Zkn185DbfzsS1; Fri, 25 Apr 2025 22:03:56 +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 53PM3uB9017771; Fri, 25 Apr 2025 22:03:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53PM3uWQ017768; Fri, 25 Apr 2025 22:03:56 GMT (envelope-from git) Date: Fri, 25 Apr 2025 22:03:56 GMT Message-Id: <202504252203.53PM3uWQ017768@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: 4a556c2277fd - main - Revert "sound: Create a dsp_close() helper function" 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: 4a556c2277fd63d83820099d72e953275a03a814 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=4a556c2277fd63d83820099d72e953275a03a814 commit 4a556c2277fd63d83820099d72e953275a03a814 Author: Christos Margiolis AuthorDate: 2025-04-25 22:02:08 +0000 Commit: Christos Margiolis CommitDate: 2025-04-25 22:02:08 +0000 Revert "sound: Create a dsp_close() helper function" Committed by accident. This reverts commit 532b45fe103c623855bf1004d5de2fd41e2885e4. --- sys/dev/sound/pcm/dsp.c | 129 +++++++++++++++++++++++++++--------------------- 1 file changed, 74 insertions(+), 55 deletions(-) diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index 0f7cf0d456cf..bc64b50b4510 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -97,7 +97,6 @@ struct cdevsw dsp_cdevsw = { static eventhandler_tag dsp_ehtag = NULL; -static void dsp_close_chan(struct pcm_channel *c); static int dsp_oss_syncgroup(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_syncgroup *group); static int dsp_oss_syncstart(int sg_id); static int dsp_oss_policy(struct pcm_channel *wrch, struct pcm_channel *rdch, int policy); @@ -242,19 +241,20 @@ dsp_chn_alloc(struct snddev_info *d, struct pcm_channel **ch, int direction, } static void -dsp_close_chan(struct pcm_channel *c) +dsp_close(void *data) { + struct dsp_cdevpriv *priv = data; + struct pcm_channel *rdch, *wrch, *parent; struct snddev_info *d; - struct pcm_channel *parent; int sg_ids; - if (c == NULL) + if (priv == NULL) return; - d = c->parentsnddev; + d = priv->sc; /* At this point pcm_unregister() will destroy all channels anyway. */ if (!DSP_REGISTERED(d)) - return; + goto skip; PCM_GIANT_ENTER(d); @@ -262,63 +262,82 @@ dsp_close_chan(struct pcm_channel *c) PCM_WAIT(d); PCM_ACQUIRE(d); - CHN_REMOVE(d, c, channels.pcm.opened); - - PCM_UNLOCK(d); + rdch = priv->rdch; + wrch = priv->wrch; - /* - * The channel itself need not be locked because: - * a) Adding a channel to a syncgroup happens only in dsp_ioctl(), - * which cannot run concurrently to dsp_close_chan(). - * b) The syncmember pointer (sm) is protected by the global - * syncgroup list lock. - * c) A channel can't just disappear, invalidating pointers, unless - * it's closed/dereferenced first. - */ - PCM_SG_LOCK(); - sg_ids = chn_syncdestroy(c); - PCM_SG_UNLOCK(); - if (sg_ids != 0) - free_unr(pcmsg_unrhdr, sg_ids); + if (rdch != NULL) + CHN_REMOVE(d, rdch, channels.pcm.opened); + if (wrch != NULL) + CHN_REMOVE(d, wrch, channels.pcm.opened); - if (c->flags & CHN_F_VIRTUAL) { - parent = c->parentchannel; - CHN_LOCK(parent); - CHN_LOCK(c); - vchan_destroy(c); - CHN_UNLOCK(parent); - } else { - CHN_LOCK(c); - if (c->direction == PCMDIR_REC) - chn_abort(c); /* won't sleep */ - else - chn_flush(c); /* may sleep */ - c->flags &= ~(CHN_F_RUNNING | CHN_F_MMAP | CHN_F_DEAD | - CHN_F_EXCLUSIVE); - chn_reset(c, 0, 0); - chn_release(c); + if (rdch != NULL || wrch != NULL) { + PCM_UNLOCK(d); + if (rdch != NULL) { + /* + * The channel itself need not be locked because: + * a) Adding a channel to a syncgroup happens only + * in dsp_ioctl(), which cannot run concurrently + * to dsp_close(). + * b) The syncmember pointer (sm) is protected by + * the global syncgroup list lock. + * c) A channel can't just disappear, invalidating + * pointers, unless it's closed/dereferenced + * first. + */ + PCM_SG_LOCK(); + sg_ids = chn_syncdestroy(rdch); + PCM_SG_UNLOCK(); + if (sg_ids != 0) + free_unr(pcmsg_unrhdr, sg_ids); + + if (rdch->flags & CHN_F_VIRTUAL) { + parent = rdch->parentchannel; + CHN_LOCK(parent); + CHN_LOCK(rdch); + vchan_destroy(rdch); + CHN_UNLOCK(parent); + } else { + CHN_LOCK(rdch); + 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); + chn_release(rdch); + } + } + if (wrch != NULL) { + /* + * Please see block above. + */ + PCM_SG_LOCK(); + sg_ids = chn_syncdestroy(wrch); + PCM_SG_UNLOCK(); + if (sg_ids != 0) + free_unr(pcmsg_unrhdr, sg_ids); + + if (wrch->flags & CHN_F_VIRTUAL) { + parent = wrch->parentchannel; + CHN_LOCK(parent); + CHN_LOCK(wrch); + vchan_destroy(wrch); + CHN_UNLOCK(parent); + } else { + CHN_LOCK(wrch); + chn_flush(wrch); /* may sleep */ + wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MMAP | + CHN_F_DEAD | CHN_F_EXCLUSIVE); + chn_reset(wrch, 0, 0); + chn_release(wrch); + } + } + PCM_LOCK(d); } - PCM_LOCK(d); - PCM_RELEASE(d); PCM_UNLOCK(d); PCM_GIANT_LEAVE(d); -} - - -static void -dsp_close(void *data) -{ - struct dsp_cdevpriv *priv = data; - - if (priv == NULL) - return; - - dsp_close_chan(priv->rdch); - dsp_close_chan(priv->wrch); - +skip: free(priv, M_DEVBUF); priv = NULL; }