From: Richard Fitzgerald Date: Thu, 10 Apr 2025 10:18:12 +0000 (+0100) Subject: ASoC: wm_adsp: Use vmemdup_user() instead of open-coding X-Git-Tag: v6.16-rc1~13^2~6^2~92 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=b5d057a86e2086af0b1e6d0ca8b306be1c73a627;p=linux-block.git 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 Link: https://patch.msgid.link/20250410101812.1180539-1-rf@opensource.cirrus.com Signed-off-by: Mark Brown --- diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c index ffd826f30e15..a2e9f32209cf 100644 --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -19,7 +20,7 @@ #include #include #include -#include +#include #include #include #include @@ -415,21 +416,12 @@ static int wm_coeff_tlv_put(struct snd_kcontrol *kctl, (struct soc_bytes_ext *)kctl->private_value; struct wm_coeff_ctl *ctl = bytes_ext_to_ctl(bytes_ext); struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl; - void *scratch; - int ret = 0; + void *scratch __free(kvfree) = vmemdup_user(bytes, size); - scratch = vmalloc(size); - if (!scratch) - return -ENOMEM; + if (IS_ERR(scratch)) + return PTR_ERR(no_free_ptr(scratch)); - if (copy_from_user(scratch, bytes, size)) - ret = -EFAULT; - else - ret = cs_dsp_coeff_lock_and_write_ctrl(cs_ctl, 0, scratch, size); - - vfree(scratch); - - return ret; + return cs_dsp_coeff_lock_and_write_ctrl(cs_ctl, 0, scratch, size); } static int wm_coeff_put_acked(struct snd_kcontrol *kctl,