git: 18457e7e25c5 - main - sound: Bail out early if a format is not supported

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Tue, 18 Feb 2025 19:37:38 UTC
The branch main has been updated by christos:

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

commit 18457e7e25c55b8834e886fd925ec3b11b79d1b6
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2025-02-18 19:36:48 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2025-02-18 19:37:22 +0000

    sound: Bail out early if a format is not supported
    
    If a format is unsupported, the feeder_build_* functions will fail
    anyway, so bail out early to avoid unnecessary computation.
    
    This is also needed by a series of upcoming patches to the feeder
    framework.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D48031
---
 sys/dev/sound/pcm/feeder_chain.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sys/dev/sound/pcm/feeder_chain.c b/sys/dev/sound/pcm/feeder_chain.c
index 588bae2ff281..1c4ddca6cdd5 100644
--- a/sys/dev/sound/pcm/feeder_chain.c
+++ b/sys/dev/sound/pcm/feeder_chain.c
@@ -718,6 +718,17 @@ feeder_chain(struct pcm_channel *c)
 		c->format = cdesc.target.afmt;
 		c->speed  = cdesc.target.rate;
 	} else {
+		/*
+		 * Bail out early if we do not support either of those formats.
+		 */
+		if ((cdesc.origin.afmt & AFMT_CONVERTIBLE) == 0 ||
+		    (cdesc.target.afmt & AFMT_CONVERTIBLE) == 0) {
+			device_printf(c->dev,
+			    "%s(): unsupported formats: in=0x%08x, out=0x%08x\n",
+			    __func__, cdesc.origin.afmt, cdesc.target.afmt);
+			return (ENODEV);
+		}
+
 		/* hwfmt is not convertible, so 'dummy' it. */
 		if (hwfmt & AFMT_PASSTHROUGH)
 			cdesc.dummy = 1;