From: Thorsten Blum <thorsten.blum@linux.dev>
To: Ian Abbott <abbotti@mev.co.uk>,
H Hartley Sweeten <hsweeten@visionengravers.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jann Horn <jannh@google.com>, Jens Axboe <axboe@kernel.dk>
Cc: Thorsten Blum <thorsten.blum@linux.dev>, linux-kernel@vger.kernel.org
Subject: [PATCH] comedi: Replace kcalloc + copy_from_user with memdup_array_user
Date: Wed, 17 Sep 2025 15:13:47 +0200 [thread overview]
Message-ID: <20250917131349.117642-2-thorsten.blum@linux.dev> (raw)
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>
---
drivers/comedi/comedi_fops.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/drivers/comedi/comedi_fops.c b/drivers/comedi/comedi_fops.c
index 7e2f2b1a1c36..dea698e509b1 100644
--- a/drivers/comedi/comedi_fops.c
+++ b/drivers/comedi/comedi_fops.c
@@ -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);
--
2.51.0
next reply other threads:[~2025-09-17 13:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 13:13 Thorsten Blum [this message]
2025-09-17 13:41 ` [PATCH] comedi: Replace kcalloc + copy_from_user with memdup_array_user Ian Abbott
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250917131349.117642-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=abbotti@mev.co.uk \
--cc=axboe@kernel.dk \
--cc=gregkh@linuxfoundation.org \
--cc=hsweeten@visionengravers.com \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.