diff mbox

[RFC,21/21] ALSA: pcm: return error immediately at refine ioctl

Message ID 20170514085756.22382-22-o-takashi@sakamocchi.jp (mailing list archive)
State New, archived
Headers show

Commit Message

Takashi Sakamoto May 14, 2017, 8:57 a.m. UTC
When refining parameters of runtime of PCM substream, helper functions can
return error but invalid data is copied to userspace. This copying is
useless.

This commit handles the error immediately. Old hw_refine/hw_params
implementation include the same issue and this commit modifies them.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
 sound/core/pcm_native.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
diff mbox

Patch

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 05230f4..c8d2b85 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -614,13 +614,16 @@  static int snd_pcm_hw_refine_user(struct snd_pcm_substream *substream,
 		return PTR_ERR(params);
 
 	err = snd_pcm_hw_refine(substream, params);
-	if (err >= 0)
-		err = fixup_unreferenced_params(substream, params);
-	if (copy_to_user(_params, params, sizeof(*params))) {
-		if (!err)
-			err = -EFAULT;
-	}
+	if (err < 0)
+		goto end;
 
+	err = fixup_unreferenced_params(substream, params);
+	if (err < 0)
+		goto end;
+
+	if (copy_to_user(_params, params, sizeof(*params)))
+		err = -EFAULT;
+end:
 	kfree(params);
 	return err;
 }
@@ -3759,9 +3762,9 @@  static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream,
 	}
 	snd_pcm_hw_convert_from_old_params(params, oparams);
 	err = snd_pcm_hw_refine(substream, params);
-	snd_pcm_hw_convert_to_old_params(oparams, params);
-	if (copy_to_user(_oparams, oparams, sizeof(*oparams))) {
-		if (!err)
+	if (err >= 0) {
+		snd_pcm_hw_convert_to_old_params(oparams, params);
+		if (copy_to_user(_oparams, oparams, sizeof(*oparams)))
 			err = -EFAULT;
 	}
 
@@ -3789,9 +3792,9 @@  static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream,
 	}
 	snd_pcm_hw_convert_from_old_params(params, oparams);
 	err = snd_pcm_hw_params(substream, params);
-	snd_pcm_hw_convert_to_old_params(oparams, params);
-	if (copy_to_user(_oparams, oparams, sizeof(*oparams))) {
-		if (!err)
+	if (err >= 0) {
+		snd_pcm_hw_convert_to_old_params(oparams, params);
+		if (copy_to_user(_oparams, oparams, sizeof(*oparams)))
 			err = -EFAULT;
 	}