From nobody Fri Apr 25 16:56:43 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 4ZkfBh0rDBz5tmSb; Fri, 25 Apr 2025 16:56:44 +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 4ZkfBg3zm4z3TBb; Fri, 25 Apr 2025 16:56:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1745600203; 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=/u7jghkJNwXhd5RcvMSFl+R3WxoIwvziwc8M7XF7tIk=; b=tuEIk9c4Tji2LhimPbAHAlF1Y1YQbRdromTfoy2FgpuQSKBB/JYzuLJq+lmAlC6axijOUG rnuBIwiNS3RZB37/mtLj1/U+86SiQYFK4Yrzh1qqpvoDAcx6zZcgRSza2QJtDqw9AbmgvZ 5C1uFVSgU4ohgZFwxKAHhZIpFkO77Wi5Z6AaYU1AmP8Un7elHTb9j/U+nh7OvG4INinS0q B4xZZe6UMlCP/7qV9gFGPoghppbDM7fkgo7XweLNU5ucTSePqQY0Z2is/oajZxO3X/mrS5 HxTY8W/kmXMpR+ZMw9Ymu3amhVh1hDj8tz1Dg5nbVRq7LOMPl6OglaxMeiRiRA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1745600203; a=rsa-sha256; cv=none; b=ZUnaccm/Pkiw4vFtvUfPnf5dtTRF1+zCPQDAZHFtWAa4R65qk15Mk9h66/juJejN0HJbvf R7r1Xu2EBxlVXv2MRAFzpEVOAOdU3DZuVpnH2tz0FCjX93QslHy9QzIkp39sk1Sxjadf2N zk5itQQ4fb800hqd/OyZjaLkyvKMpXj7Dh9K2puehvRDuP6L1/ocvUnxdP4BMbiRFak+gc KeopeThn4B3wVYYuso27YgdPxNRD3AI43r1kAZjDxm8WunJJF9fqp0nCcZdB8rIT4iumn0 L+ZtqLu67HS5q6caMJQFgJHUo70FhqptCR7vJLuhKkdK1iOax/isyp25z8wBoA== 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=1745600203; 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=/u7jghkJNwXhd5RcvMSFl+R3WxoIwvziwc8M7XF7tIk=; b=c7pvWJPsxS2CJBfWpMWb2z0DAzNdACbei56V3brOqG3o7i9PJmKNTAgBthuhg71p/ULfR4 sbNwI079SMvF6Uqek018pVyy/jJDtOJ/IV1qu9DhNq0U5KqEST8SLlAX6ctIxpDSrYLTug /o3BWkWtM1iejJLiKulEUsyLoqYCTYeQfty8Q+ZyEY14eiZmfPjA43X9i9hp7uz4SavZ5E 15D35Obtsl4jNfWIdNqJoZ5WEqRiKHCpqDW6dh2iltW9eRpRgO5R2/wT0Drb+u9iRTer8+ thTBAzIpeR5oZ9Ih8AlR6CClykSOATbn3dRhL60lyhqQfUft97WcejKKQOYDPQ== 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 4ZkfBg3RC2zkpM; Fri, 25 Apr 2025 16:56:43 +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 53PGuhSg034819; Fri, 25 Apr 2025 16:56:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53PGuhWh034816; Fri, 25 Apr 2025 16:56:43 GMT (envelope-from git) Date: Fri, 25 Apr 2025 16:56:43 GMT Message-Id: <202504251656.53PGuhWh034816@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: 532b45fe103c - main - 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: 532b45fe103c623855bf1004d5de2fd41e2885e4 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=532b45fe103c623855bf1004d5de2fd41e2885e4 commit 532b45fe103c623855bf1004d5de2fd41e2885e4 Author: Christos Margiolis AuthorDate: 2025-04-25 16:56:03 +0000 Commit: Christos Margiolis CommitDate: 2025-04-25 16:56:22 +0000 sound: Create a dsp_close() helper function Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D49805 --- sys/dev/sound/pcm/dsp.c | 129 +++++++++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 74 deletions(-) diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index bc64b50b4510..0f7cf0d456cf 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -97,6 +97,7 @@ 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); @@ -241,20 +242,19 @@ dsp_chn_alloc(struct snddev_info *d, struct pcm_channel **ch, int direction, } static void -dsp_close(void *data) +dsp_close_chan(struct pcm_channel *c) { - struct dsp_cdevpriv *priv = data; - struct pcm_channel *rdch, *wrch, *parent; struct snddev_info *d; + struct pcm_channel *parent; int sg_ids; - if (priv == NULL) + if (c == NULL) return; - d = priv->sc; + d = c->parentsnddev; /* At this point pcm_unregister() will destroy all channels anyway. */ if (!DSP_REGISTERED(d)) - goto skip; + return; PCM_GIANT_ENTER(d); @@ -262,82 +262,63 @@ dsp_close(void *data) PCM_WAIT(d); PCM_ACQUIRE(d); - rdch = priv->rdch; - wrch = priv->wrch; + CHN_REMOVE(d, c, channels.pcm.opened); - if (rdch != NULL) - CHN_REMOVE(d, rdch, channels.pcm.opened); - if (wrch != NULL) - CHN_REMOVE(d, wrch, channels.pcm.opened); + PCM_UNLOCK(d); - 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); + /* + * 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 (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); } + PCM_LOCK(d); + PCM_RELEASE(d); PCM_UNLOCK(d); PCM_GIANT_LEAVE(d); -skip: +} + + +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); + free(priv, M_DEVBUF); priv = NULL; }