Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: wm_adsp: Use vmemdup_user() instead of open-coding

Use vmemdup_user() to get a copy of the user buffer in wm_coeff_tlv_put().

Apart from simplifying the code and avoiding open-coding, it means we
also automatically benefit from any security enhancements in the code
behind vmemdup_user().

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Link: https://patch.msgid.link/20250410101812.1180539-1-rf@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Richard Fitzgerald and committed by
Mark Brown
b5d057a8 f4f20f7a

+6 -14
+6 -14
sound/soc/codecs/wm_adsp.c
··· 8 8 */ 9 9 10 10 #include <linux/array_size.h> 11 + #include <linux/cleanup.h> 11 12 #include <linux/ctype.h> 12 13 #include <linux/module.h> 13 14 #include <linux/moduleparam.h> ··· 20 19 #include <linux/regmap.h> 21 20 #include <linux/regulator/consumer.h> 22 21 #include <linux/slab.h> 23 - #include <linux/vmalloc.h> 22 + #include <linux/string.h> 24 23 #include <linux/workqueue.h> 25 24 #include <linux/debugfs.h> 26 25 #include <sound/core.h> ··· 416 415 (struct soc_bytes_ext *)kctl->private_value; 417 416 struct wm_coeff_ctl *ctl = bytes_ext_to_ctl(bytes_ext); 418 417 struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl; 419 - void *scratch; 420 - int ret = 0; 418 + void *scratch __free(kvfree) = vmemdup_user(bytes, size); 421 419 422 - scratch = vmalloc(size); 423 - if (!scratch) 424 - return -ENOMEM; 420 + if (IS_ERR(scratch)) 421 + return PTR_ERR(no_free_ptr(scratch)); 425 422 426 - if (copy_from_user(scratch, bytes, size)) 427 - ret = -EFAULT; 428 - else 429 - ret = cs_dsp_coeff_lock_and_write_ctrl(cs_ctl, 0, scratch, size); 430 - 431 - vfree(scratch); 432 - 433 - return ret; 423 + return cs_dsp_coeff_lock_and_write_ctrl(cs_ctl, 0, scratch, size); 434 424 } 435 425 436 426 static int wm_coeff_put_acked(struct snd_kcontrol *kctl,