public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Javier Carrasco <javier.carrasco.cruz@gmail.com>,
	Johan Hovold <johan@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH v2 2/2] USB: serial: garmin_gps: use struct_size to allocate pkt
Date: Wed, 19 Jun 2024 13:55:43 -0600	[thread overview]
Message-ID: <d3c2ac49-b8c3-4add-98ad-d06924b33d65@embeddedor.com> (raw)
In-Reply-To: <20240619-garmin_gps_counted_by-v2-2-f82f10ebbf28@gmail.com>



On 19/06/24 21:42, Javier Carrasco wrote:
> Use the struct_size macro to calculate the size of the pkt, which
> includes a trailing flexible array.
> 
> Suggested-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
>   drivers/usb/serial/garmin_gps.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
> index 57df6ad183ff..6d6ec7eed87c 100644
> --- a/drivers/usb/serial/garmin_gps.c
> +++ b/drivers/usb/serial/garmin_gps.c
> @@ -267,8 +267,7 @@ static int pkt_add(struct garmin_data *garmin_data_p,
>   
>   	/* process only packets containing data ... */
>   	if (data_length) {
> -		pkt = kmalloc(sizeof(struct garmin_packet)+data_length,
> -								GFP_ATOMIC);
> +		pkt = kmalloc(struct_size(pkt, data, data_length), GFP_ATOMIC);
>   		if (!pkt)
>   			return 0;
>   
> 

  reply	other threads:[~2024-06-19 19:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19 19:42 [PATCH v2 0/2] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by Javier Carrasco
2024-06-19 19:42 ` [PATCH v2 1/2] " Javier Carrasco
2024-06-19 19:56   ` Gustavo A. R. Silva
2024-06-19 20:34   ` Kees Cook
2024-06-19 19:42 ` [PATCH v2 2/2] USB: serial: garmin_gps: use struct_size to allocate pkt Javier Carrasco
2024-06-19 19:55   ` Gustavo A. R. Silva [this message]
2024-06-19 20:33   ` Kees Cook
2024-07-05 12:04 ` [PATCH v2 0/2] USB: serial: garmin_gps: annotate struct garmin_packet with __counted_by Johan Hovold

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=d3c2ac49-b8c3-4add-98ad-d06924b33d65@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavoars@kernel.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=johan@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    /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