]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: usb: fpc: replace kmalloc_array followed by copy_from_user with memdup_array_user
authorPedro Demarchi Gomes <pedrodemargomes@gmail.com>
Tue, 7 Oct 2025 12:00:57 +0000 (09:00 -0300)
committerTakashi Iwai <tiwai@suse.de>
Tue, 7 Oct 2025 12:14:32 +0000 (14:14 +0200)
Replace kmalloc_array() followed by copy_from_user() with
memdup_array_user() to improve and simplify fcp_ioctl_set_meter_map().

No functional changes intended.

Signed-off-by: Pedro Demarchi Gomes <pedrodemargomes@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/fcp.c

index 5ee8d8b660581cccbf52b9df7dfad9d1c9789045..11e9a96b46ffe5491f1b04b5cac6a35f8f7c6416 100644 (file)
@@ -641,12 +641,9 @@ static int fcp_ioctl_set_meter_map(struct usb_mixer_interface *mixer,
                return -EINVAL;
 
        /* Allocate and copy the map data */
-       tmp_map = kmalloc_array(map.map_size, sizeof(s16), GFP_KERNEL);
-       if (!tmp_map)
-               return -ENOMEM;
-
-       if (copy_from_user(tmp_map, arg->map, map.map_size * sizeof(s16)))
-               return -EFAULT;
+       tmp_map = memdup_array_user(arg->map, map.map_size, sizeof(s16));
+       if (IS_ERR(tmp_map))
+               return PTR_ERR(tmp_map);
 
        err = validate_meter_map(tmp_map, map.map_size, map.meter_slots);
        if (err < 0)