git: 0611b649eb20 - stable/14 - sound: Bail out early if a format is not supported

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Tue, 25 Feb 2025 12:17:32 UTC
The branch stable/14 has been updated by christos:

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

commit 0611b649eb20b258b31af7356b53a40f772529d1
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2025-02-18 19:36:48 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2025-02-25 12:17:15 +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
    
    (cherry picked from commit 18457e7e25c55b8834e886fd925ec3b11b79d1b6)
---
 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;