Skip to contentSkip to conversation

ALSA: usb: fpc: replace kmalloc_array followed by copy_from_user with memdup_array_user

PATCH In review Pedro Demarchi Gomes 2 participants 2 messages Oct 7, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: usb: fpc: replace kmalloc_array followed by copy_from_user with memdup_array_user

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.

---
 sound/usb/fcp.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
sound/usb/fcp.c +3 -6
index 5ee8d8b66058..11e9a96b46ff 100644
@@ -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)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · Pedro Demarchi Gomes

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.

Applied now. Thanks.

Takashi