From nobody Fri Nov 28 14:35:27 2025 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 4dHwnW4v4xz6HZp2 for ; Fri, 28 Nov 2025 14:35:27 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dHwnW32b4z3sm2 for ; Fri, 28 Nov 2025 14:35:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764340527; 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=+08zxuL+sjVlH+3nD1vDYn8Gs6aHy4jvez9RmlSlMHk=; b=tFAfXN5PiVYm79c3VOtJJ5L7Hzy5Q4JRiRIdLsBNs8kTLgoGG3UMlct8/EhECV9R3RVSNZ dh/Q18ZhxerCqw5dFcm8lbdGQ1GiqOnTiwXUlLgb+O5qnONEKXHgladoZYgTQ0rBFffP/K sW4eRI3Qa07pTNpbhpbFkb4G/9B6k96vhcMP1M6tB3E5Hj3UKwoITPiVarakmLmDqdEjvx oXANvwHCDCHuSVFQJbX1GdASF5KSUph90Vl+wM59eZk177chBQsoSwRf+iHGrTPqJkh5fm Y+gPS27bRuJwNrVLtx/kAFvCvz+XvGCpfogZInNWGbYMi4yaAwKriy64SPCgnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1764340527; 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=+08zxuL+sjVlH+3nD1vDYn8Gs6aHy4jvez9RmlSlMHk=; b=D85m4dNO55FeEc5KrEnkiTdgX9E1Nsr3/k5lfJoMMsg7zjPLjC/4K3jJnVUETbt7RvpVCP TBWTSJuJGM9jvKFB9JNu2pVbJJvWvGosceIzG8YZdm/wL4keSIBlcMGiDqX0e+n4Cs2r4M Z+V59l9B+O3bt7fGpPukroTDqTZCKwfgkFVke9jWCb7E3+5JUXh6b2tZGnPqamhXyUWNdI aSK+noxfJQYkbuxUKgZ2radEcqz+OpBq23A+hJdInUJIVKjBQ84qh+gbms4svQIAktxH9Y BrEdiEsVB/c/l6UcfONtq/q4NSMwahHhuxdq6M8aioArZyS2Xdn6jc2+fEZzGw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1764340527; a=rsa-sha256; cv=none; b=nCw2/gp9f18xw6JRWjZ1l64cXDx7pG5X+prd4u0b9rR1jxpKv75/Buvk5K2VpS5BbOKsrY 6XGVB32QtsdRVvj/4Zhfrf+r0dbrYGGlUD47sZ+sBdMIPVNUvd+WF4z4x2OOn746X9F2qe Kr5XP5Q4QwPDOzQ44QNJGTrPRhp66sCEoSMk7bNt2FvEsLV2fEprjQc2rdMyODLLcCu0ZC 5Nf875ridPq/kiyDQEl1ap0zo9xbEPSpcEDSl+cxLmlQ8LVp9Uf5fwgJxINiKzwOnRI6K4 ah9cBbYkkLUerFEEhWHVekLzQVS1t+cXm/Af8klEpJlAsRjmLOxTmVvXHoF7fQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dHwnW2FtRz15kZ for ; Fri, 28 Nov 2025 14:35:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 28cc9 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 28 Nov 2025 14:35:27 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: 48765e9306e9 - stable/15 - sound: Simplify logic in dsp_io_ops() 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/15 X-Git-Reftype: branch X-Git-Commit: 48765e9306e94ea0910280f2ce2f4a6f0a38a7d1 Auto-Submitted: auto-generated Date: Fri, 28 Nov 2025 14:35:27 +0000 Message-Id: <6929b32f.28cc9.e2bb68c@gitrepo.freebsd.org> The branch stable/15 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=48765e9306e94ea0910280f2ce2f4a6f0a38a7d1 commit 48765e9306e94ea0910280f2ce2f4a6f0a38a7d1 Author: Christos Margiolis AuthorDate: 2025-11-21 16:14:13 +0000 Commit: Christos Margiolis CommitDate: 2025-11-28 14:34:41 +0000 sound: Simplify logic in dsp_io_ops() Use CHN_LOCK()/CHN_UNLOCK() directly, instead of dsp_lock_chans()/dsp_unlock_chans(). These functions are useful when we want to potentially lock both channels. Here we know which channel we are locking, so we can just lock it directly. This way we get rid of the prio variable as well. Related to runpid again, there is no reason to assign it when CHN_F_RUNNING is not set. channel->pid (as well as channel->comm) is always assigned in dsp_chn_alloc(). Get rid of runpid. I do not see how we can end up with channel->pid (td->td_proc->p_pid) not matching buf->uio_td->td_proc->p_pid. Also improve errno values. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D53736 (cherry picked from commit b4c32d67d40a862620aa3e565ed0cb9ad59f1e60) --- sys/dev/sound/pcm/dsp.c | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c index 1ae090f252c2..cb8b5414973c 100644 --- a/sys/dev/sound/pcm/dsp.c +++ b/sys/dev/sound/pcm/dsp.c @@ -464,8 +464,7 @@ dsp_io_ops(struct dsp_cdevpriv *priv, struct uio *buf) struct snddev_info *d; struct pcm_channel *ch; int (*chn_io)(struct pcm_channel *, struct uio *); - int prio, ret; - pid_t runpid; + int ret; d = priv->sc; if (!DSP_REGISTERED(d)) @@ -475,37 +474,27 @@ dsp_io_ops(struct dsp_cdevpriv *priv, struct uio *buf) switch (buf->uio_rw) { case UIO_READ: - prio = FREAD; ch = priv->rdch; chn_io = chn_read; break; case UIO_WRITE: - prio = FWRITE; ch = priv->wrch; chn_io = chn_write; break; } - - runpid = buf->uio_td->td_proc->p_pid; - - dsp_lock_chans(priv, prio); - - if (ch == NULL || !(ch->flags & CHN_F_BUSY)) { - if (priv->rdch != NULL || priv->wrch != NULL) - dsp_unlock_chans(priv, prio); + if (ch == NULL) { PCM_GIANT_EXIT(d); - return (EBADF); + return (ENXIO); } + CHN_LOCK(ch); - if (ch->flags & (CHN_F_MMAP | CHN_F_DEAD) || - (ch->flags & CHN_F_RUNNING && ch->pid != runpid)) { - dsp_unlock_chans(priv, prio); + if (!(ch->flags & CHN_F_BUSY) || + (ch->flags & (CHN_F_MMAP | CHN_F_DEAD))) { + CHN_UNLOCK(ch); PCM_GIANT_EXIT(d); - return (EINVAL); - } else if (!(ch->flags & CHN_F_RUNNING)) { + return (ENXIO); + } else if (!(ch->flags & CHN_F_RUNNING)) ch->flags |= CHN_F_RUNNING; - ch->pid = runpid; - } /* * chn_read/write must give up channel lock in order to copy bytes @@ -517,8 +506,7 @@ dsp_io_ops(struct dsp_cdevpriv *priv, struct uio *buf) ch->inprog--; CHN_BROADCAST(&ch->cv); - - dsp_unlock_chans(priv, prio); + CHN_UNLOCK(ch); PCM_GIANT_LEAVE(d);