git: d27972ec911d - stable/14 - sound: Get rid of snddev_info->devcount

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Fri, 17 May 2024 19:30:50 UTC
The branch stable/14 has been updated by christos:

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

commit d27972ec911d09379bfbd400a7e7e7ebd4a595ec
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-04-18 20:35:06 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-05-17 19:30:01 +0000

    sound: Get rid of snddev_info->devcount
    
    snddev_info->devcount keeps track of the total number of channels for a
    given device. However, it is redundant to have it, since it is only used
    in sound_oss_sysinfo() to populate the "numaudios" field, and we also
    keep track of the channel counts in the playcount, pvchancount, reccount
    and rvchancount fields anyway. We can simply sum those fields together
    instead of updating a separate variable upon every channel
    addition/deletion.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D44852
    
    (cherry picked from commit 4d2be7be3837d66ba242a0a7fd51632c3f89285d)
---
 sys/dev/sound/pcm/sound.c | 7 +------
 sys/dev/sound/pcm/sound.h | 5 ++++-
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c
index 83248efd3f37..92ff041d0fb9 100644
--- a/sys/dev/sound/pcm/sound.c
+++ b/sys/dev/sound/pcm/sound.c
@@ -602,8 +602,6 @@ pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch)
 		break;
 	}
 
-	d->devcount++;
-
 	return (0);
 }
 
@@ -644,8 +642,6 @@ pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch)
 		break;
 	}
 
-	d->devcount--;
-
 	return (0);
 }
 
@@ -974,7 +970,6 @@ pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
 		d->flags |= SD_F_BITPERFECT;
 
 	d->devinfo = devinfo;
-	d->devcount = 0;
 	d->reccount = 0;
 	d->playcount = 0;
 	d->pvchancount = 0;
@@ -1137,7 +1132,7 @@ sound_oss_sysinfo(oss_sysinfo *si)
 		PCM_UNLOCKASSERT(d);
 		PCM_LOCK(d);
 
-		si->numaudios += d->devcount;
+		si->numaudios += PCM_CHANCOUNT(d);
 		++ncards;
 
 		CHN_FOREACH(c, d, channels.pcm) {
diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h
index b48aed7c2d6e..3b725603ee2b 100644
--- a/sys/dev/sound/pcm/sound.h
+++ b/sys/dev/sound/pcm/sound.h
@@ -175,6 +175,9 @@ struct snd_mixer;
 
 #define	PCM_DETACHING(x)	((x)->flags & SD_F_DETACHING)
 
+#define	PCM_CHANCOUNT(d)	\
+	(d->playcount + d->pvchancount + d->reccount + d->rvchancount)
+
 /* many variables should be reduced to a range. Here define a macro */
 #define RANGE(var, low, high) (var) = \
 	(((var)<(low))? (low) : ((var)>(high))? (high) : (var))
@@ -367,7 +370,7 @@ struct snddev_info {
 			} opened;
 		} pcm;
 	} channels;
-	unsigned devcount, playcount, reccount, pvchancount, rvchancount ;
+	unsigned playcount, reccount, pvchancount, rvchancount;
 	unsigned flags;
 	unsigned int bufsz;
 	void *devinfo;