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 <[email protected]> Signed-off-by: Javier Carrasco <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Johan Hovold <[email protected]>
1 parent 55a15b3 commit df8c0b8

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

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)