public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Parthiban Veerasooran <parthiban.veerasooran@microchip.com>,
	Christian Gromm <christian.gromm@microchip.com>,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] most: usb: Use kzalloc_objs for endpoint address array
Date: Wed, 25 Feb 2026 12:56:00 -0800	[thread overview]
Message-ID: <202602251250.D5F6E027@keescook> (raw)
In-Reply-To: <20260225180329.712101-2-thorsten.blum@linux.dev>

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

      reply	other threads:[~2026-02-25 20:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=202602251250.D5F6E027@keescook \
    --to=kees@kernel.org \
    --cc=christian.gromm@microchip.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=parthiban.veerasooran@microchip.com \
    --cc=thorsten.blum@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox