diff mbox

[1/2] ALSA: compress: Use memdup_user() rather than duplicating its implementation

Message ID 375fcd8c-ebb5-5f63-f094-347559c5b9c1@users.sourceforge.net (mailing list archive)
State New, archived
Headers show

Commit Message

SF Markus Elfring Aug. 21, 2016, 7:43 p.m. UTC
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 21 Aug 2016 21:02:06 +0200

Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/core/compress_offload.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

Comments

Vinod Koul Aug. 22, 2016, 5:01 a.m. UTC | #1
On Sun, Aug 21, 2016 at 09:43:22PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 21 Aug 2016 21:02:06 +0200
> 
> Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
> 
> This issue was detected by using the Coccinelle software.

It usually helps to have Coccinelle script in changelog.

But nevertheless

Acked-by: Vinod Koul <vinod.koul@intel.com>

> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  sound/core/compress_offload.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
> index 2c49848..583d407 100644
> --- a/sound/core/compress_offload.c
> +++ b/sound/core/compress_offload.c
> @@ -553,13 +553,9 @@ snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
>  		 * 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;
> -		}
> +		params = memdup_user((void __user *)arg, sizeof(*params));
> +		if (IS_ERR(params))
> +			return PTR_ERR(params);
>  
>  		retval = snd_compress_check_input(params);
>  		if (retval)
> -- 
> 2.9.3
>
Takashi Iwai Aug. 22, 2016, 12:05 p.m. UTC | #2
On Sun, 21 Aug 2016 21:43:22 +0200,
SF Markus Elfring wrote:
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sun, 21 Aug 2016 21:02:06 +0200
> 
> Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
> 
> This issue was detected by using the Coccinelle software.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Applied this one, but the second patch won't be, since other people
seem to disagree with the usefulness.


thanks,

Takashi
Vinod Koul Aug. 23, 2016, 3:55 a.m. UTC | #3
On Mon, Aug 22, 2016 at 02:05:43PM +0200, Takashi Iwai wrote:
> On Sun, 21 Aug 2016 21:43:22 +0200,
> SF Markus Elfring wrote:
> > 
> > From: Markus Elfring <elfring@users.sourceforge.net>
> > Date: Sun, 21 Aug 2016 21:02:06 +0200
> > 
> > Reuse existing functionality from memdup_user() instead of keeping
> > duplicate source code.
> > 
> > This issue was detected by using the Coccinelle software.
> > 
> > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> 
> Applied this one, but the second patch won't be, since other people
> seem to disagree with the usefulness.

I see a v2 as well discarding patch 2 here and some other changes
diff mbox

Patch

diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c
index 2c49848..583d407 100644
--- a/sound/core/compress_offload.c
+++ b/sound/core/compress_offload.c
@@ -553,13 +553,9 @@  snd_compr_set_params(struct snd_compr_stream *stream, unsigned long arg)
 		 * 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;
-		}
+		params = memdup_user((void __user *)arg, sizeof(*params));
+		if (IS_ERR(params))
+			return PTR_ERR(params);
 
 		retval = snd_compress_check_input(params);
 		if (retval)