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>
This commit is contained in:
Richard Fitzgerald 2025-04-10 11:18:12 +01:00 committed by Mark Brown
parent f4f20f7a50
commit b5d057a86e
No known key found for this signature in database
GPG key ID: 24D68B725D5487D0

View file

@ -8,6 +8,7 @@
*/ */
#include <linux/array_size.h> #include <linux/array_size.h>
#include <linux/cleanup.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
@ -19,7 +20,7 @@
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vmalloc.h> #include <linux/string.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <sound/core.h> #include <sound/core.h>
@ -415,21 +416,12 @@ static int wm_coeff_tlv_put(struct snd_kcontrol *kctl,
(struct soc_bytes_ext *)kctl->private_value; (struct soc_bytes_ext *)kctl->private_value;
struct wm_coeff_ctl *ctl = bytes_ext_to_ctl(bytes_ext); struct wm_coeff_ctl *ctl = bytes_ext_to_ctl(bytes_ext);
struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl; struct cs_dsp_coeff_ctl *cs_ctl = ctl->cs_ctl;
void *scratch; void *scratch __free(kvfree) = vmemdup_user(bytes, size);
int ret = 0;
scratch = vmalloc(size); if (IS_ERR(scratch))
if (!scratch) return PTR_ERR(no_free_ptr(scratch));
return -ENOMEM;
if (copy_from_user(scratch, bytes, size)) return cs_dsp_coeff_lock_and_write_ctrl(cs_ctl, 0, scratch, size);
ret = -EFAULT;
else
ret = cs_dsp_coeff_lock_and_write_ctrl(cs_ctl, 0, scratch, size);
vfree(scratch);
return ret;
} }
static int wm_coeff_put_acked(struct snd_kcontrol *kctl, static int wm_coeff_put_acked(struct snd_kcontrol *kctl,