From: Javier Carrasco Date: Wed, 19 Jun 2024 19:42:45 +0000 (+0200) Subject: USB: serial: garmin_gps: use struct_size() to allocate pkt X-Git-Tag: v6.11-rc3~4^2~15^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df8c0b8a03e871431587a13a6765cb4c601e1573;p=thirdparty%2Fkernel%2Flinux.git 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 Signed-off-by: Javier Carrasco Reviewed-by: Gustavo A. R. Silva Reviewed-by: Kees Cook Signed-off-by: Johan Hovold --- diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c index 57df6ad183ff0..6d6ec7eed87c9 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;