aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier Carrasco <[email protected]>2024-06-19 21:42:45 +0200
committerJohan Hovold <[email protected]>2024-07-05 14:01:43 +0200
commitdf8c0b8a03e871431587a13a6765cb4c601e1573 (patch)
treece46c80dc8dca02d2394bdb6bbbb2dd177565250
parent55a15b3a713a3f24360cf9d8dcfd2a3e337321d6 (diff)
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]>
-rw-r--r--drivers/usb/serial/garmin_gps.c3
1 files changed, 1 insertions, 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;