@@ -327,21 +327,16 @@ static int snd_pcm_hw_refine_user(struct snd_pcm_substream *substream,
327327 struct snd_pcm_hw_params * params ;
328328 int err ;
329329
330- params = kmalloc (sizeof (* params ), GFP_KERNEL );
331- if (!params ) {
332- err = - ENOMEM ;
333- goto out ;
334- }
335- if (copy_from_user (params , _params , sizeof (* params ))) {
336- err = - EFAULT ;
337- goto out ;
338- }
330+ params = memdup_user (_params , sizeof (* params ));
331+ if (IS_ERR (params ))
332+ return PTR_ERR (params );
333+
339334 err = snd_pcm_hw_refine (substream , params );
340335 if (copy_to_user (_params , params , sizeof (* params ))) {
341336 if (!err )
342337 err = - EFAULT ;
343338 }
344- out :
339+
345340 kfree (params );
346341 return err ;
347342}
@@ -465,21 +460,16 @@ static int snd_pcm_hw_params_user(struct snd_pcm_substream *substream,
465460 struct snd_pcm_hw_params * params ;
466461 int err ;
467462
468- params = kmalloc (sizeof (* params ), GFP_KERNEL );
469- if (!params ) {
470- err = - ENOMEM ;
471- goto out ;
472- }
473- if (copy_from_user (params , _params , sizeof (* params ))) {
474- err = - EFAULT ;
475- goto out ;
476- }
463+ params = memdup_user (_params , sizeof (* params ));
464+ if (IS_ERR (params ))
465+ return PTR_ERR (params );
466+
477467 err = snd_pcm_hw_params (substream , params );
478468 if (copy_to_user (_params , params , sizeof (* params ))) {
479469 if (!err )
480470 err = - EFAULT ;
481471 }
482- out :
472+
483473 kfree (params );
484474 return err ;
485475}
@@ -2593,13 +2583,11 @@ static int snd_pcm_playback_ioctl1(struct file *file,
25932583 return - EFAULT ;
25942584 if (copy_from_user (& xfern , _xfern , sizeof (xfern )))
25952585 return - EFAULT ;
2596- bufs = kmalloc (sizeof (void * ) * runtime -> channels , GFP_KERNEL );
2597- if (bufs == NULL )
2598- return - ENOMEM ;
2599- if (copy_from_user (bufs , xfern .bufs , sizeof (void * ) * runtime -> channels )) {
2600- kfree (bufs );
2601- return - EFAULT ;
2602- }
2586+
2587+ bufs = memdup_user (xfern .bufs ,
2588+ sizeof (void * ) * runtime -> channels );
2589+ if (IS_ERR (bufs ))
2590+ return PTR_ERR (bufs );
26032591 result = snd_pcm_lib_writev (substream , bufs , xfern .frames );
26042592 kfree (bufs );
26052593 __put_user (result , & _xfern -> result );
@@ -2675,13 +2663,11 @@ static int snd_pcm_capture_ioctl1(struct file *file,
26752663 return - EFAULT ;
26762664 if (copy_from_user (& xfern , _xfern , sizeof (xfern )))
26772665 return - EFAULT ;
2678- bufs = kmalloc (sizeof (void * ) * runtime -> channels , GFP_KERNEL );
2679- if (bufs == NULL )
2680- return - ENOMEM ;
2681- if (copy_from_user (bufs , xfern .bufs , sizeof (void * ) * runtime -> channels )) {
2682- kfree (bufs );
2683- return - EFAULT ;
2684- }
2666+
2667+ bufs = memdup_user (xfern .bufs ,
2668+ sizeof (void * ) * runtime -> channels );
2669+ if (IS_ERR (bufs ))
2670+ return PTR_ERR (bufs );
26852671 result = snd_pcm_lib_readv (substream , bufs , xfern .frames );
26862672 kfree (bufs );
26872673 __put_user (result , & _xfern -> result );
@@ -3312,18 +3298,12 @@ static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream,
33123298 int err ;
33133299
33143300 params = kmalloc (sizeof (* params ), GFP_KERNEL );
3315- if (!params ) {
3316- err = - ENOMEM ;
3317- goto out ;
3318- }
3319- oparams = kmalloc (sizeof (* oparams ), GFP_KERNEL );
3320- if (!oparams ) {
3321- err = - ENOMEM ;
3322- goto out ;
3323- }
3301+ if (!params )
3302+ return - ENOMEM ;
33243303
3325- if (copy_from_user (oparams , _oparams , sizeof (* oparams ))) {
3326- err = - EFAULT ;
3304+ oparams = memdup_user (_oparams , sizeof (* oparams ));
3305+ if (IS_ERR (oparams )) {
3306+ err = PTR_ERR (oparams );
33273307 goto out ;
33283308 }
33293309 snd_pcm_hw_convert_from_old_params (params , oparams );
@@ -3333,9 +3313,10 @@ static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream,
33333313 if (!err )
33343314 err = - EFAULT ;
33353315 }
3316+
3317+ kfree (oparams );
33363318out :
33373319 kfree (params );
3338- kfree (oparams );
33393320 return err ;
33403321}
33413322
@@ -3347,17 +3328,12 @@ static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream,
33473328 int err ;
33483329
33493330 params = kmalloc (sizeof (* params ), GFP_KERNEL );
3350- if (!params ) {
3351- err = - ENOMEM ;
3352- goto out ;
3353- }
3354- oparams = kmalloc (sizeof (* oparams ), GFP_KERNEL );
3355- if (!oparams ) {
3356- err = - ENOMEM ;
3357- goto out ;
3358- }
3359- if (copy_from_user (oparams , _oparams , sizeof (* oparams ))) {
3360- err = - EFAULT ;
3331+ if (!params )
3332+ return - ENOMEM ;
3333+
3334+ oparams = memdup_user (_oparams , sizeof (* oparams ));
3335+ if (IS_ERR (oparams )) {
3336+ err = PTR_ERR (oparams );
33613337 goto out ;
33623338 }
33633339 snd_pcm_hw_convert_from_old_params (params , oparams );
@@ -3367,9 +3343,10 @@ static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream,
33673343 if (!err )
33683344 err = - EFAULT ;
33693345 }
3346+
3347+ kfree (oparams );
33703348out :
33713349 kfree (params );
3372- kfree (oparams );
33733350 return err ;
33743351}
33753352#endif /* CONFIG_SND_SUPPORT_OLD_API */
0 commit comments