alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: alsa-devel@alsa-project.org, Jaroslav Kysela <perex@perex.cz>,
	Joe Perches <joe@perches.com>, Takashi Iwai <tiwai@suse.com>,
	Vinod Koul <vinod.koul@intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org,
	Julia Lawall <julia.lawall@lip6.fr>
Subject: [PATCH v2 1/2] ALSA: compress: Restructure source code around an if statement in snd_compr_set_params()
Date: Mon, 22 Aug 2016 10:38:25 +0200	[thread overview]
Message-ID: <89765506-60f0-8319-5806-29476a36f9f3@users.sourceforge.net> (raw)
In-Reply-To: <14b1efe1-3c1c-4c36-bfc2-19947c190412@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 22 Aug 2016 10:01:52 +0200

* Reverse a condition check.

* Reduce the indentation one level then for some source code
  from a previous if branch.

Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/core/compress_offload.c | 62 +++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 32 deletions(-)

diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 2c49848..a10d139 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -548,43 +548,41 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 	struct snd_compr_params *params;
 	int retval;
 
-	if (stream->runtime->state == SNDRV_PCM_STATE_OPEN) {
-		/*
-		 * we should allow parameter change only when stream has been
-		 * opened not in other cases
-		 */
-		params = kmalloc(sizeof(*params), GFP_KERNEL);
-		if (!params)
-			return -ENOMEM;
-		if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
-			retval = -EFAULT;
-			goto out;
-		}
+	if (stream->runtime->state != SNDRV_PCM_STATE_OPEN)
+		return -EPERM;
+	/*
+	 * we should allow parameter change only when stream has been
+	 * opened not in other cases
+	 */
+	params = kmalloc(sizeof(*params), GFP_KERNEL);
+	if (!params)
+		return -ENOMEM;
+	if (copy_from_user(params, (void __user *)arg, sizeof(*params))) {
+		retval = -EFAULT;
+		goto out;
+	}
 
-		retval = snd_compress_check_input(params);
-		if (retval)
-			goto out;
+	retval = snd_compress_check_input(params);
+	if (retval)
+		goto out;
 
-		retval = snd_compr_allocate_buffer(stream, params);
-		if (retval) {
-			retval = -ENOMEM;
-			goto out;
-		}
+	retval = snd_compr_allocate_buffer(stream, params);
+	if (retval) {
+		retval = -ENOMEM;
+		goto out;
+	}
 
-		retval = stream->ops->set_params(stream, params);
-		if (retval)
-			goto out;
+	retval = stream->ops->set_params(stream, params);
+	if (retval)
+		goto out;
 
-		stream->metadata_set = false;
-		stream->next_track = false;
+	stream->metadata_set = false;
+	stream->next_track = false;
 
-		if (stream->direction == SND_COMPRESS_PLAYBACK)
-			stream->runtime->state = SNDRV_PCM_STATE_SETUP;
-		else
-			stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
-	} else {
-		return -EPERM;
-	}
+	if (stream->direction == SND_COMPRESS_PLAYBACK)
+		stream->runtime->state = SNDRV_PCM_STATE_SETUP;
+	else
+		stream->runtime->state = SNDRV_PCM_STATE_PREPARED;
 out:
 	kfree(params);
 	return retval;
-- 
2.9.3

  reply	other threads:[~2016-08-22  8:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <566ABCD9.1060404@users.sourceforge.net>
2016-08-21 19:41 ` [PATCH 0/2] ALSA: compress: Fine-tuning for snd_compr_set_params() SF Markus Elfring
2016-08-21 19:43   ` [PATCH 1/2] ALSA: compress: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
2016-08-22  5:01     ` Vinod Koul
2016-08-22 12:05     ` [alsa-devel] " Takashi Iwai
2016-08-23  3:55       ` Vinod Koul
2016-08-21 19:45   ` [PATCH 2/2] ALSA: compress: Reduce the scope for two variables in snd_compr_set_params() SF Markus Elfring
2016-08-21 19:51     ` Joe Perches
2016-08-22  8:34       ` [PATCH v2 0/2] ALSA: compress: Fine-tuning for snd_compr_set_params() SF Markus Elfring
2016-08-22  8:38         ` SF Markus Elfring [this message]
2016-08-22  8:40         ` [PATCH v2 2/2] ALSA: compress: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
2016-08-23  4:04         ` [PATCH v2 0/2] ALSA: compress: Fine-tuning for snd_compr_set_params() Vinod Koul
2016-08-21 20:36     ` [PATCH 2/2] ALSA: compress: Reduce the scope for two variables in snd_compr_set_params() Julia Lawall
2016-08-22  5:01       ` Vinod Koul
2016-08-22  7:20     ` walter harms

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=89765506-60f0-8319-5806-29476a36f9f3@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=joe@perches.com \
    --cc=julia.lawall@lip6.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=vinod.koul@intel.com \
    /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).