* [PATCH] drivers/usb: misc: use kmalloc_array() instead of kmalloc() to prevent overflow
@ 2026-01-29 9:32 jindongyang
2026-02-05 16:12 ` Greg KH
0 siblings, 1 reply; 2+ messages in thread
From: jindongyang @ 2026-01-29 9:32 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, linux-kernel, jindongyang
Documentation/process/deprecated.rst recommends against the use of
kmalloc with dynamic size calculations due to the risk of overflow.
Replace kmalloc() with kmalloc_array() in adutux.c to make the
intended allocation size clearer and avoid potential overflow issues.
No functional change intended.
Signed-off-by: jindongyang <jindongyang@kylinos.cn>
---
drivers/usb/misc/adutux.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index ed6a19254d2f..000a3ade7432 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -680,7 +680,7 @@ static int adu_probe(struct usb_interface *interface,
in_end_size = usb_endpoint_maxp(dev->interrupt_in_endpoint);
out_end_size = usb_endpoint_maxp(dev->interrupt_out_endpoint);
- dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL);
+ dev->read_buffer_primary = kmalloc_array(4, in_end_size, GFP_KERNEL);
if (!dev->read_buffer_primary)
goto error;
@@ -690,7 +690,7 @@ static int adu_probe(struct usb_interface *interface,
memset(dev->read_buffer_primary + (2 * in_end_size), 'c', in_end_size);
memset(dev->read_buffer_primary + (3 * in_end_size), 'd', in_end_size);
- dev->read_buffer_secondary = kmalloc((4 * in_end_size), GFP_KERNEL);
+ dev->read_buffer_secondary = kmalloc_array(4, in_end_size, GFP_KERNEL);
if (!dev->read_buffer_secondary)
goto error;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drivers/usb: misc: use kmalloc_array() instead of kmalloc() to prevent overflow
2026-01-29 9:32 [PATCH] drivers/usb: misc: use kmalloc_array() instead of kmalloc() to prevent overflow jindongyang
@ 2026-02-05 16:12 ` Greg KH
0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-02-05 16:12 UTC (permalink / raw)
To: jindongyang; +Cc: linux-usb, linux-kernel
On Thu, Jan 29, 2026 at 05:32:02PM +0800, jindongyang wrote:
> Documentation/process/deprecated.rst recommends against the use of
> kmalloc with dynamic size calculations due to the risk of overflow.
>
> Replace kmalloc() with kmalloc_array() in adutux.c to make the
> intended allocation size clearer and avoid potential overflow issues.
>
> No functional change intended.
>
> Signed-off-by: jindongyang <jindongyang@kylinos.cn>
We need a name here, not an email alias.
> ---
> drivers/usb/misc/adutux.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
> index ed6a19254d2f..000a3ade7432 100644
> --- a/drivers/usb/misc/adutux.c
> +++ b/drivers/usb/misc/adutux.c
> @@ -680,7 +680,7 @@ static int adu_probe(struct usb_interface *interface,
> in_end_size = usb_endpoint_maxp(dev->interrupt_in_endpoint);
> out_end_size = usb_endpoint_maxp(dev->interrupt_out_endpoint);
>
> - dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL);
> + dev->read_buffer_primary = kmalloc_array(4, in_end_size, GFP_KERNEL);
This really doesn't do anything, as there can't be an overflow, right?
So please don't imply that there is in the changelog and subject line.
This is just a "janitorial" patch that does not do anything different.
So there is not really a need for it that I can determine, correct?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-05 16:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-29 9:32 [PATCH] drivers/usb: misc: use kmalloc_array() instead of kmalloc() to prevent overflow jindongyang
2026-02-05 16:12 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox