git: 044ef293a8bb - main - sound: Remove unncessary locking in sysctl_hw_snd_hwvol_mixer()

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Fri, 18 Sep 2026 18:18:46 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=044ef293a8bbd057de3fb13ec97d3d0ee16462e4

commit 044ef293a8bbd057de3fb13ec97d3d0ee16462e4
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-09-18 18:18:13 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-09-18 18:18:13 +0000

    sound: Remove unncessary locking in sysctl_hw_snd_hwvol_mixer()
    
    The locking around strlcpy() was because of m->hwvol_mixer, but this is
    just an int, so we don't need to lock in this case. Instead lock only
    when m->hwvol_mixer is written.
    
    While here, add parentheses around the returns.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 month
    Differential Revision:  https://reviews.freebsd.org/D59109
---
 sys/dev/sound/pcm/mixer.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c
index 7140da04e701..ff591cef799f 100644
--- a/sys/dev/sound/pcm/mixer.c
+++ b/sys/dev/sound/pcm/mixer.c
@@ -698,22 +698,16 @@ sysctl_hw_snd_hwvol_mixer(SYSCTL_HANDLER_ARGS)
 	struct snd_mixer *m;
 
 	m = oidp->oid_arg1;
-	mtx_lock(m->lock);
 	strlcpy(devname, snd_mixernames[m->hwvol_mixer], sizeof(devname));
-	mtx_unlock(m->lock);
 	error = sysctl_handle_string(oidp, &devname[0], sizeof(devname), req);
-	mtx_lock(m->lock);
 	if (error == 0 && req->newptr != NULL) {
-		dev = mixer_lookup(devname);
-		if (dev == -1) {
-			mtx_unlock(m->lock);
-			return EINVAL;
-		} else {
-			m->hwvol_mixer = dev;
-		}
+		if ((dev = mixer_lookup(devname)) == -1)
+			return (EINVAL);
+		mtx_lock(m->lock);
+		m->hwvol_mixer = dev;
+		mtx_unlock(m->lock);
 	}
-	mtx_unlock(m->lock);
-	return error;
+	return (error);
 }
 
 int