]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: usb-audio: Use kmemdup_array instead of kmemdup for multiple allocation
authorShen Lichuan <shenlichuan@vivo.com>
Mon, 26 Aug 2024 04:34:54 +0000 (12:34 +0800)
committerTakashi Iwai <tiwai@suse.de>
Mon, 26 Aug 2024 08:32:12 +0000 (10:32 +0200)
Let the kmemdup_array() take care about multiplication
and possible overflows.

Using kmemdup_array() is more appropriate and makes the code
easier to audit.

Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
Link: https://patch.msgid.link/20240826043454.3198-1-shenlichuan@vivo.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/quirks.c

index e7b68c67852e92ef851d7f820dfd6c522e2c0e24..53c69f3069c460c11289a3a5a9f78db9ff41b910 100644 (file)
@@ -167,8 +167,8 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
                return -EINVAL;
        }
        if (fp->nr_rates > 0) {
-               rate_table = kmemdup(fp->rate_table,
-                                    sizeof(int) * fp->nr_rates, GFP_KERNEL);
+               rate_table = kmemdup_array(fp->rate_table, fp->nr_rates, sizeof(int),
+                                          GFP_KERNEL);
                if (!rate_table) {
                        kfree(fp);
                        return -ENOMEM;