git: 2f31a5eb75f1 - main - sound: Remove nmix variable from mixer_oss_mixerinfo()

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Thu, 09 May 2024 19:08:43 UTC
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=2f31a5eb75f1e47b5c49f574e8ce48d2c863e9d3

commit 2f31a5eb75f1e47b5c49f574e8ce48d2c863e9d3
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-05-09 19:07:48 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-05-09 19:07:48 +0000

    sound: Remove nmix variable from mixer_oss_mixerinfo()
    
    nmix is used to compare against oss_mixerinfo->dev, which is a
    user-supplied value to select the mixer device (if not -1, in which case
    we'll select the default one) we want to fetch the information of. It is
    also used to set oss_mixerinfo->dev in case it is -1.
    
    However, nmix is at best redundant, since we have the loop counter
    already (i), and confusing at worst.
    
    For example, suppose a system with 3 mixer devices. We call
    SNDCTL_MIXERINFO with oss_mixerinfo->dev=1, meaning we want to get
    information for /dev/mixer1. Suppose /dev/mixer0 detaches while inside
    the loop, so we'll hit the loop's "continue" case, and nmix won't get
    incremented (i.e will stay 0 for now). At this point nmix counts 1
    device less, so when it reaches 1, we'll be fetching /dev/mixer2's
    information instead of /dev/mixer1's.
    
    This is also true in case the mixer device disappears prior to the call
    to mixer_oss_mixerinfo().
    
    Simply remove nmix and use the loop counter to both set
    oss_mixerinfo->dev and check against it in case a non -1 value is
    supplied.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
    Reviewed by:    dev_submerge.ch
    Differential Revision:  https://reviews.freebsd.org/D45135
---
 sys/dev/sound/pcm/mixer.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c
index 4e67a0227506..a37b94dce43a 100644
--- a/sys/dev/sound/pcm/mixer.c
+++ b/sys/dev/sound/pcm/mixer.c
@@ -1431,7 +1431,7 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
 {
 	struct snddev_info *d;
 	struct snd_mixer *m;
-	int nmix, i;
+	int i;
 
 	/*
 	 * If probing the device handling the ioctl, make sure it's a mixer
@@ -1442,7 +1442,6 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
 
 	d = NULL;
 	m = NULL;
-	nmix = 0;
 
 	/*
 	 * There's a 1:1 relationship between mixers and PCM devices, so
@@ -1462,7 +1461,7 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
 
 		if (d->mixer_dev != NULL && d->mixer_dev->si_drv1 != NULL &&
 		    ((mi->dev == -1 && d->mixer_dev == i_dev) ||
-		    mi->dev == nmix)) {
+		    mi->dev == i)) {
 			m = d->mixer_dev->si_drv1;
 			mtx_lock(m->lock);
 
@@ -1474,7 +1473,7 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
 			 *   sure to unlock when existing.
 			 */
 			bzero((void *)mi, sizeof(*mi));
-			mi->dev = nmix;
+			mi->dev = i;
 			snprintf(mi->id, sizeof(mi->id), "mixer%d", i);
 			strlcpy(mi->name, m->name, sizeof(mi->name));
 			mi->modify_counter = m->modify_counter;
@@ -1538,8 +1537,7 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
 			mi->legacy_device = i;
 			 */
 			mtx_unlock(m->lock);
-		} else
-			++nmix;
+		}
 
 		PCM_UNLOCK(d);