* [PATCH] comedi: Replace kcalloc + copy_from_user with memdup_array_user
@ 2025-09-17 13:13 Thorsten Blum
2025-09-17 13:41 ` Ian Abbott
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-09-17 13:13 UTC (permalink / raw)
To: Ian Abbott, H Hartley Sweeten, Greg Kroah-Hartman, Jann Horn,
Jens Axboe
Cc: Thorsten Blum, linux-kernel
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] comedi: Replace kcalloc + copy_from_user with memdup_array_user
2025-09-17 13:13 [PATCH] comedi: Replace kcalloc + copy_from_user with memdup_array_user Thorsten Blum
@ 2025-09-17 13:41 ` Ian Abbott
0 siblings, 0 replies; 2+ messages in thread
From: Ian Abbott @ 2025-09-17 13:41 UTC (permalink / raw)
To: Thorsten Blum, H Hartley Sweeten, Greg Kroah-Hartman, Jann Horn,
Jens Axboe
Cc: linux-kernel
On 17/09/2025 14:13, Thorsten Blum wrote:
> 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);
Looks good to me. Thanks!
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
--
-=( Ian Abbott <abbotti@mev.co.uk> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-17 14:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-17 13:13 [PATCH] comedi: Replace kcalloc + copy_from_user with memdup_array_user Thorsten Blum
2025-09-17 13:41 ` Ian Abbott
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.