Skip to content

Commit df8c0b8

Browse files
javiercarrascocruzjhovold
authored andcommitted
USB: serial: garmin_gps: use struct_size() to allocate pkt
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> Reviewed-by: Kees Cook <kees@kernel.org> Signed-off-by: Johan Hovold <johan@kernel.org>
1 parent 55a15b3 commit df8c0b8

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

drivers/usb/serial/garmin_gps.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ static int pkt_add(struct garmin_data *garmin_data_p,
267267

268268
/* process only packets containing data ... */
269269
if (data_length) {
270-
pkt = kmalloc(sizeof(struct garmin_packet)+data_length,
271-
GFP_ATOMIC);
270+
pkt = kmalloc(struct_size(pkt, data, data_length), GFP_ATOMIC);
272271
if (!pkt)
273272
return 0;
274273

0 commit comments

Comments
 (0)