usb: host: ehci-sched: Use struct_size() in kzalloc()
Subsystems (2)
PATCH 1/1 usb: host: ehci-sched: Use struct_size() in kzalloc()
Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows.
Also, address the following sparse warning:drivers/usb/host/ehci-sched.c:1168:40: warning: using sizeof on a flexible structure
Signed-off-by Gustavo A. R. Silva <[email protected]>
--- drivers/usb/host/ehci-sched.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/host/ehci-sched.c +1 -3
@@ -1165,10 +1165,8 @@ static struct ehci_iso_sched * iso_sched_alloc(unsigned packets, gfp_t mem_flags) {struct ehci_iso_sched *iso_sched; -int size =sizeof (*iso_sched); - size += packets *sizeof (struct ehci_iso_packet ); - iso_sched =kzalloc (size, mem_flags); + iso_sched =kzalloc (struct_size (iso_sched, packet, packets), mem_flags);if (likely (iso_sched !=NULL ))INIT_LIST_HEAD (&iso_sched->td_list);
Signature · 1 line
2.27.0
Quoted 11 lines · Gustavo A. R. Silva
Make use of the
struct_size()helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows.Also, address the following sparse warning:
drivers/usb/host/ehci-sched.c:1168:40: warning: using sizeof on a flexible structureSigned-off-by Gustavo A. R. Silva <[email protected]>---
Acked-by Alan Stern <[email protected]>
Quoted 22 lines
drivers/usb/host/ehci-sched.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/usb/host/ehci-sched.c +1
-3@@ -1165,10 +1165,8 @@ static struct ehci_iso_sched * iso_sched_alloc(unsigned packets, gfp_t mem_flags) {struct ehci_iso_sched *iso_sched; -int size =sizeof (*iso_sched); - size += packets *sizeof (struct ehci_iso_packet ); - iso_sched =kzalloc (size, mem_flags); + iso_sched =kzalloc (struct_size (iso_sched, packet, packets), mem_flags);if (likely (iso_sched !=NULL ))INIT_LIST_HEAD (&iso_sched->td_list);Signature · 1 line
2.27.0