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-28 14:02:39 +0000
commita9f454a9c79810d60261d03dbec73c29396bf128 (patch)
tree9f9f00a1d8be47bfe2600b80a646c464e7ca14f6
parentfe90ad2d2444616d01d0d5396c0687635d637364 (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 (cherry picked from commit 3deae7b786743193531f4e69527e789de52644c5)
-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,