git: 00c066cd575d - stable/14 - sound: Move sysctl and /dev/dspX creation to pcm_setstatus()

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Tue, 05 Nov 2024 21:45:33 UTC
The branch stable/14 has been updated by christos:

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

commit 00c066cd575dedf34a1aa76ed29489604f4a9c9d
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-11-03 19:02:31 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-11-05 21:44:41 +0000

    sound: Move sysctl and /dev/dspX creation to pcm_setstatus()
    
    Create the sysctl and /dev/dsp* nodes in pcm_setstatus(), which is
    responsible for finalizing the device initialization, instead of doing
    this in the middle of the initialization.
    
    For the sysctl creation specifically, move them into pcm_sysinit(),
    since this is where we create the rest of the sysctl nodes anyway.
    
    A side effect of this change is, that we avoid the possibility of racing
    in between pcm_register() and pcm_setstatus() by accessing /dev/dspX or
    the sysctls within that window.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Reviewed by:    dev_submerge.ch, markj
    Differential Revision:  https://reviews.freebsd.org/D47322
    
    (cherry picked from commit 66f3eb14e955d3917f817ff346d33d839679c2cf)
---
 sys/dev/sound/pcm/sound.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c
index 948cbd0b8fb9..5ca38ca622c9 100644
--- a/sys/dev/sound/pcm/sound.c
+++ b/sys/dev/sound/pcm/sound.c
@@ -316,7 +316,7 @@ pcm_setstatus(device_t dev, char *str)
 	else if (snd_unit_auto == 1)
 		snd_unit = pcm_best_unit(snd_unit);
 
-	return (0);
+	return (dsp_make_dev(dev));
 }
 
 uint32_t
@@ -433,6 +433,15 @@ pcm_sysinit(device_t dev)
 
 	mode = pcm_mode_init(d);
 
+	sysctl_ctx_init(&d->play_sysctl_ctx);
+	d->play_sysctl_tree = SYSCTL_ADD_NODE(&d->play_sysctl_ctx,
+	    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "play",
+	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "playback channels node");
+	sysctl_ctx_init(&d->rec_sysctl_ctx);
+	d->rec_sysctl_tree = SYSCTL_ADD_NODE(&d->rec_sysctl_ctx,
+	    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "rec",
+	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "recording channels node");
+
 	/* XXX: a user should be able to set this with a control tool, the
 	   sysadmin then needs min+max sysctls for this */
 	SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
@@ -497,21 +506,12 @@ pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
 	if ((numplay == 0 || numrec == 0) && numplay != numrec)
 		d->flags |= SD_F_SIMPLEX;
 
-	sysctl_ctx_init(&d->play_sysctl_ctx);
-	d->play_sysctl_tree = SYSCTL_ADD_NODE(&d->play_sysctl_ctx,
-	    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "play",
-	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "playback channels node");
-	sysctl_ctx_init(&d->rec_sysctl_ctx);
-	d->rec_sysctl_tree = SYSCTL_ADD_NODE(&d->rec_sysctl_ctx,
-	    SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "rec",
-	    CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "recording channels node");
-
 	if (numplay > 0 || numrec > 0)
 		d->flags |= SD_F_AUTOVCHAN;
 
 	sndstat_register(dev, d->status);
 
-	return (dsp_make_dev(dev));
+	return (0);
 }
 
 int