git: 3397443e50d2 - stable/14 - sound: Remove PCM_DETACHING(), SD_F_DETACHING and SD_F_DYING

From: Christos Margiolis <christos_at_FreeBSD.org>
Date: Fri, 29 Nov 2024 12:28:24 UTC
The branch stable/14 has been updated by christos:

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

commit 3397443e50d2a34c953cb3d13fe2c2fb50e4ea7c
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-11-26 14:48:30 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-11-29 12:28:06 +0000

    sound: Remove PCM_DETACHING(), SD_F_DETACHING and SD_F_DYING
    
    Since SD_F_REGISTERED is cleared at the same time SD_F_DETACHING and
    SD_F_DYING are set, and since PCM_DETACHING() is always used in
    conjuction with PCM_REGISTERED()/DSP_REGISTERED(), it is enough to just
    check SD_F_REGISTERED.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      2 days
    Reviewed by:    dev_submerge.ch, markj
    Differential Revision:  https://reviews.freebsd.org/D47463
    
    (cherry picked from commit 6d4c59e26189a8c19fd0832e89f9b089330cbfcb)
---
 sys/dev/sound/pcm/dsp.c   | 12 ++++++------
 sys/dev/sound/pcm/mixer.c | 10 +++++-----
 sys/dev/sound/pcm/sound.c |  2 --
 sys/dev/sound/pcm/sound.h | 48 ++++++++++++++++++++---------------------------
 4 files changed, 31 insertions(+), 41 deletions(-)

diff --git a/sys/dev/sound/pcm/dsp.c b/sys/dev/sound/pcm/dsp.c
index 0f19f064a227..ccf240681a25 100644
--- a/sys/dev/sound/pcm/dsp.c
+++ b/sys/dev/sound/pcm/dsp.c
@@ -177,7 +177,7 @@ dsp_close(void *data)
 
 	d = priv->sc;
 	/* At this point pcm_unregister() will destroy all channels anyway. */
-	if (!DSP_REGISTERED(d) || PCM_DETACHING(d))
+	if (!DSP_REGISTERED(d))
 		goto skip;
 
 	PCM_GIANT_ENTER(d);
@@ -264,7 +264,7 @@ dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
 		return (ENODEV);
 
 	d = i_dev->si_drv1;
-	if (!DSP_REGISTERED(d) || PCM_DETACHING(d))
+	if (!DSP_REGISTERED(d))
 		return (EBADF);
 
 	priv = malloc(sizeof(*priv), M_DEVBUF, M_WAITOK | M_ZERO);
@@ -445,7 +445,7 @@ dsp_io_ops(struct dsp_cdevpriv *priv, struct uio *buf)
 	    ("%s(): io train wreck!", __func__));
 
 	d = priv->sc;
-	if (!DSP_REGISTERED(d) || PCM_DETACHING(d))
+	if (!DSP_REGISTERED(d))
 		return (EBADF);
 
 	PCM_GIANT_ENTER(d);
@@ -664,7 +664,7 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
 		return (err);
 
 	d = priv->sc;
-	if (!DSP_REGISTERED(d) || PCM_DETACHING(d))
+	if (!DSP_REGISTERED(d))
 		return (EBADF);
 
 	PCM_GIANT_ENTER(d);
@@ -1783,7 +1783,7 @@ dsp_poll(struct cdev *i_dev, int events, struct thread *td)
 	if ((err = devfs_get_cdevpriv((void **)&priv)) != 0)
 		return (err);
 	d = priv->sc;
-	if (!DSP_REGISTERED(d) || PCM_DETACHING(d)) {
+	if (!DSP_REGISTERED(d)) {
 		/* XXX many clients don't understand POLLNVAL */
 		return (events & (POLLHUP | POLLPRI | POLLIN |
 		    POLLRDNORM | POLLOUT | POLLWRNORM));
@@ -1865,7 +1865,7 @@ dsp_mmap_single(struct cdev *i_dev, vm_ooffset_t *offset,
 	if ((err = devfs_get_cdevpriv((void **)&priv)) != 0)
 		return (err);
 	d = priv->sc;
-	if (!DSP_REGISTERED(d) || PCM_DETACHING(d))
+	if (!DSP_REGISTERED(d))
 		return (EINVAL);
 
 	PCM_GIANT_ENTER(d);
diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c
index 6d74fa975f03..b5b5814e667b 100644
--- a/sys/dev/sound/pcm/mixer.c
+++ b/sys/dev/sound/pcm/mixer.c
@@ -146,7 +146,7 @@ mixer_set_softpcmvol(struct snd_mixer *m, struct snddev_info *d,
 	struct pcm_channel *c;
 	int dropmtx, acquiremtx;
 
-	if (!PCM_REGISTERED(d) || PCM_DETACHING(d))
+	if (!PCM_REGISTERED(d))
 		return (EINVAL);
 
 	if (mtx_owned(m->lock))
@@ -199,7 +199,7 @@ mixer_set_eq(struct snd_mixer *m, struct snddev_info *d,
 	else
 		return (EINVAL);
 
-	if (!PCM_REGISTERED(d) || PCM_DETACHING(d))
+	if (!PCM_REGISTERED(d))
 		return (EINVAL);
 
 	if (mtx_owned(m->lock))
@@ -1053,7 +1053,7 @@ mixer_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
 
 	m = i_dev->si_drv1;
 	d = device_get_softc(m->dev);
-	if (!PCM_REGISTERED(d) || PCM_DETACHING(d))
+	if (!PCM_REGISTERED(d))
 		return (EBADF);
 
 	/* XXX Need Giant magic entry ??? */
@@ -1209,7 +1209,7 @@ mixer_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
 		return (EBADF);
 
 	d = device_get_softc(((struct snd_mixer *)i_dev->si_drv1)->dev);
-	if (!PCM_REGISTERED(d) || PCM_DETACHING(d))
+	if (!PCM_REGISTERED(d))
 		return (EBADF);
 
 	PCM_GIANT_ENTER(d);
@@ -1447,7 +1447,7 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
 	for (i = 0; pcm_devclass != NULL &&
 	    i < devclass_get_maxunit(pcm_devclass); i++) {
 		d = devclass_get_softc(pcm_devclass, i);
-		if (!PCM_REGISTERED(d) || PCM_DETACHING(d)) {
+		if (!PCM_REGISTERED(d)) {
 			if ((mi->dev == -1 && i == snd_unit) || mi->dev == i) {
 				mixer_oss_mixerinfo_unavail(mi, i);
 				return (0);
diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c
index ebd2e2d697f8..44ba4805462d 100644
--- a/sys/dev/sound/pcm/sound.c
+++ b/sys/dev/sound/pcm/sound.c
@@ -535,8 +535,6 @@ pcm_unregister(device_t dev)
 	PCM_LOCK(d);
 	PCM_WAIT(d);
 
-	d->flags |= SD_F_DETACHING;
-	d->flags |= SD_F_DYING;
 	d->flags &= ~SD_F_REGISTERED;
 
 	PCM_ACQUIRE(d);
diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h
index c5013e76034a..467adad2ddff 100644
--- a/sys/dev/sound/pcm/sound.h
+++ b/sys/dev/sound/pcm/sound.h
@@ -104,17 +104,15 @@ struct snd_mixer;
 #define SD_F_SIMPLEX		0x00000001
 #define SD_F_AUTOVCHAN		0x00000002
 #define SD_F_SOFTPCMVOL		0x00000004
-#define SD_F_DYING		0x00000008
-#define SD_F_DETACHING		0x00000010
-#define SD_F_BUSY		0x00000020
-#define SD_F_MPSAFE		0x00000040
-#define SD_F_REGISTERED		0x00000080
-#define SD_F_BITPERFECT		0x00000100
-#define SD_F_VPC		0x00000200	/* volume-per-channel */
-#define SD_F_EQ			0x00000400	/* EQ */
-#define SD_F_EQ_ENABLED		0x00000800	/* EQ enabled */
-#define SD_F_EQ_BYPASSED	0x00001000	/* EQ bypassed */
-#define SD_F_EQ_PC		0x00002000	/* EQ per-channel */
+#define SD_F_BUSY		0x00000008
+#define SD_F_MPSAFE		0x00000010
+#define SD_F_REGISTERED		0x00000020
+#define SD_F_BITPERFECT		0x00000040
+#define SD_F_VPC		0x00000080	/* volume-per-channel */
+#define SD_F_EQ			0x00000100	/* EQ */
+#define SD_F_EQ_ENABLED		0x00000200	/* EQ enabled */
+#define SD_F_EQ_BYPASSED	0x00000400	/* EQ bypassed */
+#define SD_F_EQ_PC		0x00000800	/* EQ per-channel */
 
 #define SD_F_EQ_DEFAULT		(SD_F_EQ | SD_F_EQ_ENABLED)
 #define SD_F_EQ_MASK		(SD_F_EQ | SD_F_EQ_ENABLED |		\
@@ -127,26 +125,20 @@ struct snd_mixer;
 				"\001SIMPLEX"				\
 				"\002AUTOVCHAN"				\
 				"\003SOFTPCMVOL"			\
-				"\004DYING"				\
-				"\005DETACHING"				\
-				"\006BUSY"				\
-				"\007MPSAFE"				\
-				"\010REGISTERED"			\
-				"\011BITPERFECT"			\
-				"\012VPC"				\
-				"\013EQ"				\
-				"\014EQ_ENABLED"			\
-				"\015EQ_BYPASSED"			\
-				"\016EQ_PC"				\
+				"\004BUSY"				\
+				"\005MPSAFE"				\
+				"\006REGISTERED"			\
+				"\007BITPERFECT"			\
+				"\010VPC"				\
+				"\011EQ"				\
+				"\012EQ_ENABLED"			\
+				"\013EQ_BYPASSED"			\
+				"\014EQ_PC"				\
 				"\035PRIO_RD"				\
 				"\036PRIO_WR"
 
-#define PCM_ALIVE(x)		((x) != NULL && (x)->lock != NULL &&	\
-				 !((x)->flags & SD_F_DYING))
-#define PCM_REGISTERED(x)	(PCM_ALIVE(x) &&			\
-				 ((x)->flags & SD_F_REGISTERED))
-
-#define	PCM_DETACHING(x)	((x)->flags & SD_F_DETACHING)
+#define PCM_ALIVE(x)		((x) != NULL && (x)->lock != NULL)
+#define PCM_REGISTERED(x)	(PCM_ALIVE(x) && ((x)->flags & SD_F_REGISTERED))
 
 #define	PCM_CHANCOUNT(d)	\
 	(d->playcount + d->pvchancount + d->reccount + d->rvchancount)