Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Mar 2020 08:25:33 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r358878 - stable/11/sys/dev/sound/pcm
Message-ID:  <202003110825.02B8PXCv064682@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Wed Mar 11 08:25:33 2020
New Revision: 358878
URL: https://svnweb.freebsd.org/changeset/base/358878

Log:
  MFC r358629:
  Implement a detaching flag for the sound(4) subsystem to take
  appropriate actions when we are trying to detach an audio device,
  but cannot because someone is using it.
  
  This avoids applications having to wait for the DSP read data
  timeout before they receive any error indication.
  Tested with virtual_oss(8).
  
  Remove some unused definitions while at it.
  
  PR:		194727
  Sponsored by:	Mellanox Technologies

Modified:
  stable/11/sys/dev/sound/pcm/dsp.c
  stable/11/sys/dev/sound/pcm/mixer.c
  stable/11/sys/dev/sound/pcm/sound.c
  stable/11/sys/dev/sound/pcm/sound.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/sound/pcm/dsp.c
==============================================================================
--- stable/11/sys/dev/sound/pcm/dsp.c	Wed Mar 11 08:24:50 2020	(r358877)
+++ stable/11/sys/dev/sound/pcm/dsp.c	Wed Mar 11 08:25:33 2020	(r358878)
@@ -458,7 +458,7 @@ dsp_open(struct cdev *i_dev, int flags, int mode, stru
 		return (ENODEV);
 
 	d = dsp_get_info(i_dev);
-	if (!PCM_REGISTERED(d))
+	if (PCM_DETACHING(d) || !PCM_REGISTERED(d))
 		return (EBADF);
 
 	PCM_GIANT_ENTER(d);
@@ -828,7 +828,7 @@ dsp_io_ops(struct cdev *i_dev, struct uio *buf)
 	    ("%s(): io train wreck!", __func__));
 
 	d = dsp_get_info(i_dev);
-	if (!DSP_REGISTERED(d, i_dev))
+	if (PCM_DETACHING(d) || !DSP_REGISTERED(d, i_dev))
 		return (EBADF);
 
 	PCM_GIANT_ENTER(d);
@@ -1073,7 +1073,7 @@ dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg,
 	int *arg_i, ret, tmp;
 
 	d = dsp_get_info(i_dev);
-	if (!DSP_REGISTERED(d, i_dev))
+	if (PCM_DETACHING(d) || !DSP_REGISTERED(d, i_dev))
 		return (EBADF);
 
 	PCM_GIANT_ENTER(d);
@@ -2168,9 +2168,11 @@ dsp_poll(struct cdev *i_dev, int events, struct thread
 	int ret, e;
 
 	d = dsp_get_info(i_dev);
-	if (!DSP_REGISTERED(d, i_dev))
-		return (EBADF);
-
+	if (PCM_DETACHING(d) || !DSP_REGISTERED(d, i_dev)) {
+		/* XXX many clients don't understand POLLNVAL */
+		return (events & (POLLHUP | POLLPRI | POLLIN |
+		    POLLRDNORM | POLLOUT | POLLWRNORM));
+	}
 	PCM_GIANT_ENTER(d);
 
 	wrch = NULL;
@@ -2241,7 +2243,7 @@ dsp_mmap_single(struct cdev *i_dev, vm_ooffset_t *offs
 		return (EINVAL);
 
 	d = dsp_get_info(i_dev);
-	if (!DSP_REGISTERED(d, i_dev))
+	if (PCM_DETACHING(d) || !DSP_REGISTERED(d, i_dev))
 		return (EINVAL);
 
 	PCM_GIANT_ENTER(d);

Modified: stable/11/sys/dev/sound/pcm/mixer.c
==============================================================================
--- stable/11/sys/dev/sound/pcm/mixer.c	Wed Mar 11 08:24:50 2020	(r358877)
+++ stable/11/sys/dev/sound/pcm/mixer.c	Wed Mar 11 08:25:33 2020	(r358878)
@@ -151,7 +151,7 @@ mixer_set_softpcmvol(struct snd_mixer *m, struct sndde
 	struct pcm_channel *c;
 	int dropmtx, acquiremtx;
 
-	if (!PCM_REGISTERED(d))
+	if (PCM_DETACHING(d) || !PCM_REGISTERED(d))
 		return (EINVAL);
 
 	if (mtx_owned(m->lock))
@@ -204,7 +204,7 @@ mixer_set_eq(struct snd_mixer *m, struct snddev_info *
 	else
 		return (EINVAL);
 
-	if (!PCM_REGISTERED(d))
+	if (PCM_DETACHING(d) || !PCM_REGISTERED(d))
 		return (EINVAL);
 
 	if (mtx_owned(m->lock))
@@ -1044,7 +1044,7 @@ mixer_open(struct cdev *i_dev, int flags, int mode, st
 
 	m = i_dev->si_drv1;
 	d = device_get_softc(m->dev);
-	if (!PCM_REGISTERED(d))
+	if (PCM_DETACHING(d) || !PCM_REGISTERED(d))
 		return (EBADF);
 
 	/* XXX Need Giant magic entry ??? */
@@ -1200,7 +1200,7 @@ mixer_ioctl(struct cdev *i_dev, u_long cmd, caddr_t ar
 		return (EBADF);
 
 	d = device_get_softc(((struct snd_mixer *)i_dev->si_drv1)->dev);
-	if (!PCM_REGISTERED(d))
+	if (PCM_DETACHING(d) || !PCM_REGISTERED(d))
 		return (EBADF);
 
 	PCM_GIANT_ENTER(d);
@@ -1409,7 +1409,7 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo 
 	for (i = 0; pcm_devclass != NULL &&
 	    i < devclass_get_maxunit(pcm_devclass); i++) {
 		d = devclass_get_softc(pcm_devclass, i);
-		if (!PCM_REGISTERED(d))
+		if (PCM_DETACHING(d) || !PCM_REGISTERED(d))
 			continue;
 
 		/* XXX Need Giant magic entry */

Modified: stable/11/sys/dev/sound/pcm/sound.c
==============================================================================
--- stable/11/sys/dev/sound/pcm/sound.c	Wed Mar 11 08:24:50 2020	(r358877)
+++ stable/11/sys/dev/sound/pcm/sound.c	Wed Mar 11 08:25:33 2020	(r358878)
@@ -1156,6 +1156,8 @@ pcm_unregister(device_t dev)
 	PCM_LOCK(d);
 	PCM_WAIT(d);
 
+	d->flags |= SD_F_DETACHING;
+	
 	if (d->inprog != 0) {
 		device_printf(dev, "unregister: operation in progress\n");
 		PCM_UNLOCK(d);

Modified: stable/11/sys/dev/sound/pcm/sound.h
==============================================================================
--- stable/11/sys/dev/sound/pcm/sound.h	Wed Mar 11 08:24:50 2020	(r358877)
+++ stable/11/sys/dev/sound/pcm/sound.h	Wed Mar 11 08:25:33 2020	(r358878)
@@ -128,15 +128,8 @@ struct snd_mixer;
 #define SD_F_SIMPLEX		0x00000001
 #define SD_F_AUTOVCHAN		0x00000002
 #define SD_F_SOFTPCMVOL		0x00000004
-/*
- * Obsolete due to better matrixing
- */
-#if 0
-#define SD_F_PSWAPLR		0x00000008
-#define SD_F_RSWAPLR		0x00000010
-#endif
 #define SD_F_DYING		0x00000008
-#define SD_F_SUICIDE		0x00000010
+#define SD_F_DETACHING		0x00000010
 #define SD_F_BUSY		0x00000020
 #define SD_F_MPSAFE		0x00000040
 #define SD_F_REGISTERED		0x00000080
@@ -162,7 +155,7 @@ struct snd_mixer;
 				"\002AUTOVCHAN"				\
 				"\003SOFTPCMVOL"			\
 				"\004DYING"				\
-				"\005SUICIDE"				\
+				"\005DETACHING"				\
 				"\006BUSY"				\
 				"\007MPSAFE"				\
 				"\010REGISTERED"			\
@@ -180,6 +173,8 @@ struct snd_mixer;
 				 !((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)
 
 /* many variables should be reduced to a range. Here define a macro */
 #define RANGE(var, low, high) (var) = \



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