public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] most: usb: Use kzalloc_objs for endpoint address array
@ 2026-02-25 18:03 Thorsten Blum
  2026-02-25 20:56 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-02-25 18:03 UTC (permalink / raw)
  To: Parthiban Veerasooran, Christian Gromm
  Cc: linux-hardening, Thorsten Blum, linux-kernel

Replace kcalloc() with kzalloc_objs() when allocating the endpoint
address array to keep the size type-safe and match nearby allocations.
Reformat ->busy_urbs allocation to a single line. No functional change.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 drivers/most/most_usb.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c
index d2c0875727a3..6437733afee0 100644
--- a/drivers/most/most_usb.c
+++ b/drivers/most/most_usb.c
@@ -1009,13 +1009,11 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 		goto err_free_conf;
 
 	mdev->iface.channel_vector = mdev->cap;
-	mdev->ep_address =
-		kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL);
+	mdev->ep_address = kzalloc_objs(*mdev->ep_address, num_endpoints);
 	if (!mdev->ep_address)
 		goto err_free_cap;
 
-	mdev->busy_urbs =
-		kzalloc_objs(*mdev->busy_urbs, num_endpoints);
+	mdev->busy_urbs = kzalloc_objs(*mdev->busy_urbs, num_endpoints);
 	if (!mdev->busy_urbs)
 		goto err_free_ep_address;
 
-- 
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] most: usb: Use kzalloc_objs for endpoint address array
  2026-02-25 18:03 [PATCH] most: usb: Use kzalloc_objs for endpoint address array Thorsten Blum
@ 2026-02-25 20:56 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2026-02-25 20:56 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Parthiban Veerasooran, Christian Gromm, linux-hardening,
	linux-kernel

On Wed, Feb 25, 2026 at 07:03:29PM +0100, Thorsten Blum wrote:
> Replace kcalloc() with kzalloc_objs() when allocating the endpoint
> address array to keep the size type-safe and match nearby allocations.
> Reformat ->busy_urbs allocation to a single line. No functional change.
> 
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/most/most_usb.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/most/most_usb.c b/drivers/most/most_usb.c
> index d2c0875727a3..6437733afee0 100644
> --- a/drivers/most/most_usb.c
> +++ b/drivers/most/most_usb.c
> @@ -1009,13 +1009,11 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
>  		goto err_free_conf;
>  
>  	mdev->iface.channel_vector = mdev->cap;
> -	mdev->ep_address =
> -		kcalloc(num_endpoints, sizeof(*mdev->ep_address), GFP_KERNEL);
> +	mdev->ep_address = kzalloc_objs(*mdev->ep_address, num_endpoints);

This case was skipped because mdev->ep_address is "u8 *". This is a
pretty long way to go about allocating "num_endpoints"-many bytes.
Perhaps this should just be:

	mdev->ep_address = kzalloc(num_endpoints, GFP_KERNEL);

Though maybe in keeping with all the other num_endpoints allocations,
your patch is fine as-is. I'd be nice to use __counted_by_ptr() here,
but the num_endpoints is in a sub-structure, which isn't supported yet.

Reviewed-by: Kees Cook <kees@kernel.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-25 20:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25 18:03 [PATCH] most: usb: Use kzalloc_objs for endpoint address array Thorsten Blum
2026-02-25 20:56 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox