aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristos Margiolis <christos@FreeBSD.org>2026-02-21 11:36:58 +0000
committerChristos Margiolis <christos@FreeBSD.org>2026-02-21 11:36:58 +0000
commit3deae7b786743193531f4e69527e789de52644c5 (patch)
tree08b04671fb0815dfa109549d9b43dc1b5bd0e5c8
parent5c8af592f69a31da94c45722dcd74afcf0ab375e (diff)
sound: Detect unsupported formats
This way we can avoid edge-cases like 8af6aee96ed609456900c6dd92dafabac5e89c0a ("virtual_oss(8): Remove floating point formats from preference list"). Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D55403
-rw-r--r--sys/dev/sound/pcm/channel.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c
index 011dc1427c2e..b74f76fd21ca 100644
--- a/sys/dev/sound/pcm/channel.c
+++ b/sys/dev/sound/pcm/channel.c
@@ -2092,9 +2092,23 @@ chn_setspeed(struct pcm_channel *c, uint32_t speed)
int
chn_setformat(struct pcm_channel *c, uint32_t format)
{
- uint32_t oldformat, oldspeed;
+ uint32_t oldformat, oldspeed, x;
int ret;
+ /*
+ * Detect unsupported formats. This checks if the format is supported
+ * in the first place, and that no more than 1 format is specified at
+ * the same time.
+ */
+ x = format & AFMT_CONVERTIBLE;
+ if ((x & (x - 1)) != 0) {
+ if (snd_verbose > 3) {
+ device_printf(c->dev, "%s(): Unsupported format: "
+ "0x%08x\n", __func__, format);
+ }
+ return (EINVAL);
+ }
+
/* XXX force stereo */
if ((format & AFMT_PASSTHROUGH) && AFMT_CHANNEL(format) < 2) {
format = SND_FORMAT(format, AFMT_PASSTHROUGH_CHANNEL,