git: a9e27006db60 - stable/14 - sound: Simplify feeder_remove()

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Mon, 29 Jul 2024 15:35:27 UTC
The branch stable/14 has been updated by christos:

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

commit a9e27006db60edc60ffbe650b077abf64a42c025
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-07-27 11:55:57 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-07-29 15:34:55 +0000

    sound: Simplify feeder_remove()
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 days
    Reviewed by:    dev_submerge.ch, markj, emaste
    Differential Revision:  https://reviews.freebsd.org/D46100
    
    (cherry picked from commit 00172d20070a544e0514cce9f94475c5525fd15e)
---
 sys/dev/sound/pcm/channel.c      |  6 ++----
 sys/dev/sound/pcm/feeder.c       | 14 ++++++--------
 sys/dev/sound/pcm/feeder.h       |  2 +-
 sys/dev/sound/pcm/feeder_chain.c |  3 +--
 4 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c
index ce4fb7222ddb..e0fd24805a21 100644
--- a/sys/dev/sound/pcm/channel.c
+++ b/sys/dev/sound/pcm/channel.c
@@ -1324,8 +1324,7 @@ chn_init(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls,
 	return (c);
 
 fail:
-	while (feeder_remove(c) == 0)
-		;
+	feeder_remove(c);
 	if (c->devinfo && CHANNEL_FREE(c->methods, c->devinfo))
 		sndbuf_free(b);
 	if (bs)
@@ -1356,8 +1355,7 @@ chn_kill(struct pcm_channel *c)
 		chn_trigger(c, PCMTRIG_ABORT);
 		CHN_UNLOCK(c);
 	}
-	while (feeder_remove(c) == 0)
-		;
+	feeder_remove(c);
 	if (CHANNEL_FREE(c->methods, c->devinfo))
 		sndbuf_free(b);
 	sndbuf_destroy(bs);
diff --git a/sys/dev/sound/pcm/feeder.c b/sys/dev/sound/pcm/feeder.c
index ad6966331f02..716eb07feaae 100644
--- a/sys/dev/sound/pcm/feeder.c
+++ b/sys/dev/sound/pcm/feeder.c
@@ -248,18 +248,16 @@ feeder_add(struct pcm_channel *c, struct feeder_class *fc, struct pcm_feederdesc
 	return 0;
 }
 
-int
+void
 feeder_remove(struct pcm_channel *c)
 {
 	struct pcm_feeder *f;
 
-	if (c->feeder == NULL)
-		return -1;
-	f = c->feeder;
-	c->feeder = c->feeder->source;
-	feeder_destroy(f);
-
-	return 0;
+	while (c->feeder != NULL) {
+		f = c->feeder;
+		c->feeder = c->feeder->source;
+		feeder_destroy(f);
+	}
 }
 
 struct pcm_feeder *
diff --git a/sys/dev/sound/pcm/feeder.h b/sys/dev/sound/pcm/feeder.h
index f2a865d3d2f9..1e240d934e94 100644
--- a/sys/dev/sound/pcm/feeder.h
+++ b/sys/dev/sound/pcm/feeder.h
@@ -60,7 +60,7 @@ u_int32_t snd_fmtbest(u_int32_t fmt, u_int32_t *fmts);
 
 int feeder_add(struct pcm_channel *c, struct feeder_class *fc,
     struct pcm_feederdesc *desc);
-int feeder_remove(struct pcm_channel *c);
+void feeder_remove(struct pcm_channel *c);
 struct pcm_feeder *feeder_find(struct pcm_channel *c, u_int32_t type);
 void feeder_printchain(struct pcm_feeder *head);
 int feeder_chain(struct pcm_channel *);
diff --git a/sys/dev/sound/pcm/feeder_chain.c b/sys/dev/sound/pcm/feeder_chain.c
index 555cd86d60e5..588bae2ff281 100644
--- a/sys/dev/sound/pcm/feeder_chain.c
+++ b/sys/dev/sound/pcm/feeder_chain.c
@@ -588,8 +588,7 @@ feeder_chain(struct pcm_channel *c)
 	CHN_LOCKASSERT(c);
 
 	/* Remove everything first. */
-	while (feeder_remove(c) == 0)
-		;
+	feeder_remove(c);
 
 	KASSERT(c->feeder == NULL, ("feeder chain not empty"));