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
This commit is contained in:
Christos Margiolis 2024-11-03 20:02:31 +01:00
parent 98cd27c8e1
commit 66f3eb14e9

View file

@ -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