Commit 48d45ae4 authored by Thorsten Blum's avatar Thorsten Blum Committed by Greg Kroah-Hartman
Browse files

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: default avatarThorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Link: https://patch.msgid.link/20250917131349.117642-2-thorsten.blum@linux.dev


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9fd2eb9e
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -2284,15 +2284,10 @@ static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
		rc = check_insnlist_len(dev, insnlist.n_insns);
		if (rc)
			break;
		insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL);
		if (!insns) {
			rc = -ENOMEM;
			break;
		}
		if (copy_from_user(insns, insnlist.insns,
				   sizeof(*insns) * insnlist.n_insns)) {
			rc = -EFAULT;
			kfree(insns);
		insns = memdup_array_user(insnlist.insns, insnlist.n_insns,
					  sizeof(*insns));
		if (IS_ERR(insns)) {
			rc = PTR_ERR(insns);
			break;
		}
		rc = do_insnlist_ioctl(dev, insns, insnlist.n_insns, file);