Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Oct 2024 11:21:36 GMT
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: 1f4d968a299e - stable/14 - sound: Move root feeder initialization to separate function
Message-ID:  <202410201121.49KBLaEK062773@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by christos:

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

commit 1f4d968a299ea74f10276761932c2ece28531975
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-10-18 08:39:58 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-10-20 11:21:05 +0000

    sound: Move root feeder initialization to separate function
    
    feeder_register() is currently a SYSINIT in order to create the root
    feeder, which happens only when feedercnt is 0. Separating the root
    feeder registration makes the code more readable.
    
    No functional change intended.
    
    While here, fix some style errors.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 days
    Reviewed by:    dev_submerge.ch, zlei, markj
    Differential Revision:  https://reviews.freebsd.org/D46821
    
    (cherry picked from commit 97570db05ced435f4fb1c6a67bdb16966ce5e4d9)
---
 sys/dev/sound/pcm/feeder.c | 69 +++++++++++++++++++++++++---------------------
 1 file changed, 38 insertions(+), 31 deletions(-)

diff --git a/sys/dev/sound/pcm/feeder.c b/sys/dev/sound/pcm/feeder.c
index 87437c6d00b5..c6f93ac54036 100644
--- a/sys/dev/sound/pcm/feeder.c
+++ b/sys/dev/sound/pcm/feeder.c
@@ -48,51 +48,55 @@ struct feedertab_entry {
 	int idx;
 };
 static SLIST_HEAD(, feedertab_entry) feedertab;
+static int feedercnt = 0;
 
 /*****************************************************************************/
 
-void
-feeder_register(void *p)
+static void
+feeder_register_root(void *p)
 {
-	static int feedercnt = 0;
-
 	struct feeder_class *fc = p;
 	struct feedertab_entry *fte;
-	int i;
-
-	if (feedercnt == 0) {
-		KASSERT(fc->desc == NULL, ("first feeder not root: %s", fc->name));
-
-		SLIST_INIT(&feedertab);
-		fte = malloc(sizeof(*fte), M_FEEDER, M_NOWAIT | M_ZERO);
-		if (fte == NULL) {
-			printf("can't allocate memory for root feeder: %s\n",
-			    fc->name);
 
-			return;
-		}
-		fte->feederclass = fc;
-		fte->desc = NULL;
-		fte->idx = feedercnt;
-		SLIST_INSERT_HEAD(&feedertab, fte, link);
-		feedercnt++;
-
-		/* we've got our root feeder so don't veto pcm loading anymore */
-		pcm_veto_load = 0;
+	MPASS(feedercnt == 0);
+	KASSERT(fc->desc == NULL, ("first feeder not root: %s", fc->name));
 
+	SLIST_INIT(&feedertab);
+	fte = malloc(sizeof(*fte), M_FEEDER, M_NOWAIT | M_ZERO);
+	if (fte == NULL) {
+		printf("can't allocate memory for root feeder: %s\n", fc->name);
 		return;
 	}
+	fte->feederclass = fc;
+	fte->desc = NULL;
+	fte->idx = feedercnt;
+	SLIST_INSERT_HEAD(&feedertab, fte, link);
+	feedercnt++;
+
+	/* we've got our root feeder so don't veto pcm loading anymore */
+	pcm_veto_load = 0;
+}
+
+void
+feeder_register(void *p)
+{
+	struct feeder_class *fc = p;
+	struct feedertab_entry *fte;
+	int i;
 
 	KASSERT(fc->desc != NULL, ("feeder '%s' has no descriptor", fc->name));
 
-	/* beyond this point failure is non-fatal but may result in some translations being unavailable */
+	/*
+	 * beyond this point failure is non-fatal but may result in some
+	 * translations being unavailable
+	 */
 	i = 0;
 	while ((feedercnt < MAXFEEDERS) && (fc->desc[i].type > 0)) {
-		/* printf("adding feeder %s, %x -> %x\n", fc->name, fc->desc[i].in, fc->desc[i].out); */
 		fte = malloc(sizeof(*fte), M_FEEDER, M_NOWAIT | M_ZERO);
 		if (fte == NULL) {
-			printf("can't allocate memory for feeder '%s', %x -> %x\n", fc->name, fc->desc[i].in, fc->desc[i].out);
-
+			printf("can't allocate memory for feeder '%s', "
+			    "%x -> %x\n",
+			    fc->name, fc->desc[i].in, fc->desc[i].out);
 			return;
 		}
 		fte->feederclass = fc;
@@ -103,8 +107,10 @@ feeder_register(void *p)
 		i++;
 	}
 	feedercnt++;
-	if (feedercnt >= MAXFEEDERS)
-		printf("MAXFEEDERS (%d >= %d) exceeded\n", feedercnt, MAXFEEDERS);
+	if (feedercnt >= MAXFEEDERS) {
+		printf("MAXFEEDERS (%d >= %d) exceeded\n",
+		    feedercnt, MAXFEEDERS);
+	}
 }
 
 static void
@@ -469,5 +475,6 @@ static struct feeder_class feeder_root_class = {
 	.desc =		NULL,
 	.data =		NULL,
 };
-SYSINIT(feeder_root, SI_SUB_DRIVERS, SI_ORDER_FIRST, feeder_register, &feeder_root_class);
+SYSINIT(feeder_root, SI_SUB_DRIVERS, SI_ORDER_FIRST, feeder_register_root,
+    &feeder_root_class);
 SYSUNINIT(feeder_root, SI_SUB_DRIVERS, SI_ORDER_FIRST, feeder_unregisterall, NULL);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202410201121.49KBLaEK062773>