From d27972ec911d09379bfbd400a7e7e7ebd4a595ec Mon Sep 17 00:00:00 2001 From: Christos Margiolis Date: Thu, 18 Apr 2024 22:35:06 +0200 Subject: [PATCH] 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 83248efd3f3..92ff041d0fb 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 b48aed7c2d6..3b725603ee2 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;