alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Vinod Koul <vinod.koul@intel.com>
To: alsa-devel@alsa-project.org, tiwai@suse.de
Cc: broonie@kernel.org, lgirdwood@gmail.com,
	Vinod Koul <vinod.koul@intel.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/9] ALSA: Compress - dont use lock for all ioctls
Date: Tue, 27 Aug 2013 12:10:31 +0530	[thread overview]
Message-ID: <1377585639-29516-2-git-send-email-vinod.koul@intel.com> (raw)
In-Reply-To: <1377585639-29516-1-git-send-email-vinod.koul@intel.com>

Some simple ioctls like timsetamp query, capabities query can be done anytime
and should not be under the stream lock. Move these to
snd_compress_simple_iotcls() which is invoked without lock held

While at it, improve readblity a bit by sprinkling some empty lines

Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Cc: <stable@vger.kernel.org>
---
 sound/core/compress_offload.c |   79 ++++++++++++++++++++++++++++++-----------
 1 files changed, 58 insertions(+), 21 deletions(-)

diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 99db892..868aefd 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -729,70 +729,107 @@ static int snd_compr_partial_drain(struct snd_compr_stream *stream)
 	return retval;
 }
 
-static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
+static int snd_compress_simple_ioctls(struct file *file,
+				struct snd_compr_stream *stream,
+				unsigned int cmd, unsigned long arg)
 {
-	struct snd_compr_file *data = f->private_data;
-	struct snd_compr_stream *stream;
 	int retval = -ENOTTY;
 
-	if (snd_BUG_ON(!data))
-		return -EFAULT;
-	stream = &data->stream;
-	if (snd_BUG_ON(!stream))
-		return -EFAULT;
-	mutex_lock(&stream->device->lock);
 	switch (_IOC_NR(cmd)) {
 	case _IOC_NR(SNDRV_COMPRESS_IOCTL_VERSION):
 		put_user(SNDRV_COMPRESS_VERSION,
 				(int __user *)arg) ? -EFAULT : 0;
 		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_GET_CAPS):
 		retval = snd_compr_get_caps(stream, arg);
 		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_GET_CODEC_CAPS):
 		retval = snd_compr_get_codec_caps(stream, arg);
 		break;
+
+	case _IOC_NR(SNDRV_COMPRESS_TSTAMP):
+		retval = snd_compr_tstamp(stream, arg);
+		break;
+
+	case _IOC_NR(SNDRV_COMPRESS_AVAIL):
+		retval = snd_compr_ioctl_avail(stream, arg);
+		break;
+
+		/* drain and partial drain need special handling
+	 * we need to drop the locks here as the streams would get blocked on the
+	 * dsp to get drained. The locking would be handled in respective
+	 * function here
+	 */
+	case _IOC_NR(SNDRV_COMPRESS_DRAIN):
+		retval = snd_compr_drain(stream);
+		break;
+
+	case _IOC_NR(SNDRV_COMPRESS_PARTIAL_DRAIN):
+		retval = snd_compr_partial_drain(stream);
+		break;
+	}
+
+	return retval;
+}
+
+static long snd_compr_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
+{
+	struct snd_compr_file *data = f->private_data;
+	struct snd_compr_stream *stream;
+	int retval = -ENOTTY;
+
+	if (snd_BUG_ON(!data))
+		return -EFAULT;
+	stream = &data->stream;
+	if (snd_BUG_ON(!stream))
+		return -EFAULT;
+
+	mutex_lock(&stream->device->lock);
+	switch (_IOC_NR(cmd)) {
 	case _IOC_NR(SNDRV_COMPRESS_SET_PARAMS):
 		retval = snd_compr_set_params(stream, arg);
 		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_GET_PARAMS):
 		retval = snd_compr_get_params(stream, arg);
 		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_SET_METADATA):
 		retval = snd_compr_set_metadata(stream, arg);
 		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_GET_METADATA):
 		retval = snd_compr_get_metadata(stream, arg);
 		break;
-	case _IOC_NR(SNDRV_COMPRESS_TSTAMP):
-		retval = snd_compr_tstamp(stream, arg);
-		break;
-	case _IOC_NR(SNDRV_COMPRESS_AVAIL):
-		retval = snd_compr_ioctl_avail(stream, arg);
-		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_PAUSE):
 		retval = snd_compr_pause(stream);
 		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_RESUME):
 		retval = snd_compr_resume(stream);
 		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_START):
 		retval = snd_compr_start(stream);
 		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_STOP):
 		retval = snd_compr_stop(stream);
 		break;
-	case _IOC_NR(SNDRV_COMPRESS_DRAIN):
-		retval = snd_compr_drain(stream);
-		break;
-	case _IOC_NR(SNDRV_COMPRESS_PARTIAL_DRAIN):
-		retval = snd_compr_partial_drain(stream);
-		break;
+
 	case _IOC_NR(SNDRV_COMPRESS_NEXT_TRACK):
 		retval = snd_compr_next_track(stream);
 		break;
 
+	default:
+		mutex_unlock(&stream->device->lock);
+		return snd_compress_simple_ioctls(f, stream, cmd, arg);
+
 	}
+
 	mutex_unlock(&stream->device->lock);
 	return retval;
 }
-- 
1.7.0.4

  reply	other threads:[~2013-08-27  6:40 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-27  6:40 [PATCH 0/9] ALSA: compress offfload fixes Vinod Koul
2013-08-27  6:40 ` Vinod Koul [this message]
2013-08-27 10:22   ` [PATCH 1/9] ALSA: Compress - dont use lock for all ioctls Takashi Iwai
2013-08-27  9:44     ` Vinod Koul
2013-08-27 11:00       ` Takashi Iwai
2013-08-27  6:40 ` [PATCH 2/9] ALSA: compress: use mutex in drain Vinod Koul
2013-08-27 10:25   ` Takashi Iwai
2013-08-27  9:47     ` Vinod Koul
2013-08-27 10:53       ` Takashi Iwai
2013-08-27 10:16         ` Vinod Koul
2013-08-27 12:23           ` Takashi Iwai
2013-08-27 13:09             ` Vinod Koul
2013-08-27 14:03               ` Takashi Iwai
2013-08-27 14:10                 ` Vinod Koul
2013-08-27  6:40 ` [PATCH 3/9] ASoC: compress: dont aquire lock for draining states Vinod Koul
2013-08-27  6:40 ` [PATCH 4/9] ALSA: compress: use snprint instread of sprintf Vinod Koul
2013-08-27  6:40 ` [PATCH 5/9] ALSA: compres: wakeup the poll thread on pause Vinod Koul
2013-08-27  6:40 ` [PATCH 6/9] ALSA: compress: dont write when stream is paused Vinod Koul
2013-08-27  6:40 ` [PATCH 7/9] ALSA: compress: allow write when stream is setup Vinod Koul
2013-08-27  6:40 ` [PATCH 8/9] ALSA: compress: call pointer callback and updates under a lock Vinod Koul
2013-08-27 10:31   ` Takashi Iwai
2013-08-27  9:48     ` Vinod Koul
2013-08-27 11:03       ` Takashi Iwai
2013-08-27  6:40 ` [PATCH 9/9] ALSA: compress: use rate values for passing sampling rates Vinod Koul
2013-08-27 10:30   ` Takashi Iwai
2013-08-27 13:29   ` Mark Brown
2013-08-27 13:26     ` Vinod Koul
2013-08-27 14:27       ` Mark Brown
2013-08-27 10:46 ` [PATCH 0/9] ALSA: compress offfload fixes Takashi Iwai
2013-08-27 10:09   ` Vinod Koul
2013-08-27 12:32     ` Takashi Iwai
2013-08-27 13:14       ` Vinod Koul
2013-08-27 14:05         ` Takashi Iwai
2013-08-27 13:30           ` Vinod Koul
2013-08-27 14:22             ` Takashi Iwai
2013-08-27 13:41               ` Vinod Koul
2013-08-27 14:41                 ` Takashi Iwai
2013-08-27 14:11                   ` Vinod Koul
2013-08-27 13:28       ` Mark Brown
2013-08-27 13:18         ` Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1377585639-29516-2-git-send-email-vinod.koul@intel.com \
    --to=vinod.koul@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).