Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

comedi: Replace kcalloc + copy_from_user with memdup_array_user

Replace kcalloc() followed by copy_from_user() with memdup_array_user()
to improve and simplify comedi_unlocked_ioctl().

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://patch.msgid.link/20250917131349.117642-2-thorsten.blum@linux.dev
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thorsten Blum and committed by
Greg Kroah-Hartman
48d45ae4 9fd2eb9e

+4 -9
+4 -9
drivers/comedi/comedi_fops.c
··· 2284 2284 rc = check_insnlist_len(dev, insnlist.n_insns); 2285 2285 if (rc) 2286 2286 break; 2287 - insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL); 2288 - if (!insns) { 2289 - rc = -ENOMEM; 2290 - break; 2291 - } 2292 - if (copy_from_user(insns, insnlist.insns, 2293 - sizeof(*insns) * insnlist.n_insns)) { 2294 - rc = -EFAULT; 2295 - kfree(insns); 2287 + insns = memdup_array_user(insnlist.insns, insnlist.n_insns, 2288 + sizeof(*insns)); 2289 + if (IS_ERR(insns)) { 2290 + rc = PTR_ERR(insns); 2296 2291 break; 2297 2292 } 2298 2293 rc = do_insnlist_ioctl(dev, insns, insnlist.n_insns, file);