linux/drivers/usb/core
Gustavo A. R. Silva 5ebf5c8903 usb: core: config: Use struct_size() in kzalloc()
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
    int stuff;
    struct boo entry[];
};

size = sizeof(struct foo) + count * sizeof(struct boo);
instance = kzalloc(size, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

Notice that, in this case, variable len is not necessary, hence
it is removed.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-19 14:41:38 +01:00
..
buffer.c USB: Removing NULL check for pool since dma_pool_destroy is safe 2018-09-10 20:01:04 +02:00
config.c usb: core: config: Use struct_size() in kzalloc() 2019-02-19 14:41:38 +01:00
devices.c Remove 'type' argument from access_ok() function 2019-01-03 18:57:57 -08:00
devio.c usb: devio: update max count of DPs per interval for ISOC 2019-01-07 17:35:00 +01:00
driver.c USB: Consolidate LPM checks to avoid enabling LPM twice 2019-01-18 10:02:56 +01:00
endpoint.c USB: core: move existing SPDX tags to top of the file 2017-11-03 10:12:26 +01:00
file.c USB: core: move existing SPDX tags to top of the file 2017-11-03 10:12:26 +01:00
generic.c USB: Fix configuration selection issues introduced in v4.20.0 2019-02-08 10:22:39 +01:00
hcd-pci.c usb: Don't die twice if PCI xhci host is not responding in resume 2018-09-05 14:36:53 +02:00
hcd.c usb: core: comply to PHY framework 2019-01-30 09:22:35 +01:00
hub.c usb: handle warm-reset port requests on hub resume 2019-02-08 10:21:22 +01:00
hub.h usb: hub: add retry routine after intr URB submit error 2019-01-18 09:58:04 +01:00
Kconfig USB: add missing SPDX lines to Kconfig and Makefiles 2019-01-22 09:08:17 +01:00
ledtrig-usbport.c USB: leds: fix regression in usbport led trigger 2019-01-18 09:55:05 +01:00
Makefile usb: core: add a wrapper for the USB PHYs on the HCD 2018-03-09 09:43:53 -08:00
message.c USB: Consolidate LPM checks to avoid enabling LPM twice 2019-01-18 10:02:56 +01:00
notify.c USB: core: move existing SPDX tags to top of the file 2017-11-03 10:12:26 +01:00
of.c usb: Change usb_of_get_companion_dev() place to usb/common 2018-09-10 20:40:29 +02:00
otg_whitelist.h USB: core: Remove redundant license text 2017-11-04 11:55:39 +01:00
phy.c usb: core: comply to PHY framework 2019-01-30 09:22:35 +01:00
phy.h usb: core: comply to PHY framework 2019-01-30 09:22:35 +01:00
port.c usb: export firmware port location in sysfs 2018-10-02 12:05:30 -07:00
quirks.c USB: Add USB_QUIRK_DELAY_CTRL_MSG quirk for Corsair K70 RGB 2019-01-07 17:29:28 +01:00
sysfs.c USB: Add new USB LPM helpers 2019-01-18 10:02:56 +01:00
urb.c USB: core: urb: Use struct_size() in kmalloc() 2019-01-08 16:46:46 +01:00
usb-acpi.c usb: clarify ACPI spec version and section number for _UPC & _PLD 2018-03-09 09:37:10 -08:00
usb.c USB: check usb_get_extra_descriptor for proper size 2018-12-05 21:20:14 +01:00
usb.h USB: Add new USB LPM helpers 2019-01-18 10:02:56 +01:00