Page MenuHomeFreeBSD

sound: Get rid of snddev_info->devcount
ClosedPublic

Authored by christos on Apr 18 2024, 6:07 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, May 14, 9:08 AM
Unknown Object (File)
Sat, Apr 27, 3:39 PM
Unknown Object (File)
Fri, Apr 26, 11:59 PM
Unknown Object (File)
Sat, Apr 20, 5:52 PM
Unknown Object (File)
Apr 19 2024, 8:00 AM
Subscribers

Details

Summary

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

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/dev/sound/pcm/sound.h
179

I added this in the header file in case it is useful outside sound.c in the future. We could also have it in sound.c, or just not have it at all and calculate the sum directly in sound_oss_sysinfo(), but I thought it'd be good to have it like this.

sys/dev/sound/pcm/sound.c
605

What if the channel type is not one of the four counted above? Is that possible at all?

sys/dev/sound/pcm/sound.h
373
christos added inline comments.
sys/dev/sound/pcm/sound.c
605

Not really possible, no. We can only have hw channels or vchans. I do not really know what the default case is here for. pcm_chn_add() is always called after pcm_chn_create(), and if pcm_chn_create() fails (one of the reasons being that the channel type is not one of the ones listed above), pcm_chn_add() won't get called in the first place. So I think it's safe to assume that it's not possible to end up with a type other than those.

markj added inline comments.
sys/dev/sound/pcm/sound.c
605

Perhaps we should assert that the default case is never reached? (Add __assert_unreachable() in that case.)

This revision is now accepted and ready to land.Apr 18 2024, 8:29 PM
sys/dev/sound/pcm/sound.c
605

I have to think about whether it to do this or clean up the control flow of these functions in general, so I will leave it as is for now.

This revision was automatically updated to reflect the committed changes.