Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Feb 2026 14:02:47 +0000
From:      Christos Margiolis <christos@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: a9f454a9c798 - stable/15 - sound: Detect unsupported formats
Message-ID:  <69a2f587.2247a.16865864@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/15 has been updated by christos:

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

commit a9f454a9c79810d60261d03dbec73c29396bf128
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2026-02-21 11:36:58 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2026-02-28 14:02:39 +0000

    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)
---
 sys/dev/sound/pcm/channel.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

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,


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69a2f587.2247a.16865864>