]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
USB: serial: garmin_gps: use struct_size() to allocate pkt
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Wed, 19 Jun 2024 19:42:45 +0000 (21:42 +0200)
committerJohan Hovold <johan@kernel.org>
Fri, 5 Jul 2024 12:01:43 +0000 (14:01 +0200)
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>
drivers/usb/serial/garmin_gps.c

index 57df6ad183ff03c53a224d6322cd8979ea26e2f1..6d6ec7eed87c921218670bb2c68b18677b15af2d 100644 (file)
@@ -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;