usb: xhci-mtk: Use struct_size() helper in create_sch_ep()
Subsystems (4)
PATCH 1/1 usb: xhci-mtk: Use struct_size() helper in create_sch_ep()
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 worst scenario, could lead to heap overflows.
Also, address the following sparse warnings:drivers/usb/host/xhci-mtk-sch.c:265:20: warning: using sizeof on a flexible structure
--- drivers/usb/host/xhci-mtk-sch.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/usb/host/xhci-mtk-sch.c +3 -4
@@ -248,7 +248,6 @@ create_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev,struct mu3h_sch_bw_info *bw_info;struct mu3h_sch_tt *tt =NULL ;u32 len_bw_budget_table; -size_t mem_size; bw_info =get_bw_info (mtk, udev, ep);if (!bw_info)
@@ -262,9 +261,9 @@ create_sch_ep(struct xhci_hcd_mtk *mtk, struct usb_device *udev,else len_bw_budget_table =1 ; - mem_size =sizeof (struct mu3h_sch_ep_info ) + - len_bw_budget_table *sizeof (u32); - sch_ep =kzalloc (mem_size,GFP_KERNEL ); + sch_ep =kzalloc (struct_size (sch_ep, bw_budget_table, + len_bw_budget_table), +GFP_KERNEL );if (!sch_ep)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.27.0
Quoted 34 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 worst scenario, could lead to heap overflows.Also, address the following sparse warnings:
drivers/usb/host/xhci-mtk-sch.c:265:20: warning: using sizeof on a flexible structureSigned-off-by Gustavo A. R. Silva <[email protected]>--- drivers/usb/host/xhci-mtk-sch.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/usb/host/xhci- renamed from drivers/usb/host/xhci-mtk-sch.c +0
-0
mtk-sch.c
indexedbfa82c6565..f3139ce7b0a9100644drivers/usb/host/xhci-mtk-sch.c +0
-1@@ -248,7 +248,6 @@ create_sch_ep(struct xhci_hcd_mtk *mtk, structusb_device *udev, struct mu3h_sch_bw_info *bw_info;struct mu3h_sch_tt *tt =NULL ;u32 len_bw_budget_table; -size_t mem_size; bw_info =get_bw_info (mtk, udev, ep);drivers/usb/host/xhci-mtk-sch.c +0
-0if (!bw_info)@@ -262,9 +261,9 @@ create_sch_ep(struct xhci_hcd_mtk *mtk, structusb_device *udev, else
drivers/usb/host/xhci-mtk-sch.c create_sch_ep(struct xhci_hcd_mtk *mtk, struct · line 269
Quoted 10 lines
drivers/usb/host/xhci-mtk-sch.c +3
-3len_bw_budget_table =1 ; - mem_size =sizeof (struct mu3h_sch_ep_info ) + - len_bw_budget_table *sizeof (u32); - sch_ep =kzalloc (mem_size,GFP_KERNEL ); + sch_ep =kzalloc (struct_size (sch_ep, bw_budget_table, + len_bw_budget_table), +GFP_KERNEL );if (!sch_ep)return ERR_PTR (-ENOMEM );
Thanks a lot
Quoted 1 line
Il 20/01/22 02:55, Gustavo A. R. Silva ha scritto:
Quoted 11 lines
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 worst scenario, could lead to heap overflows.Also, address the following sparse warnings:
drivers/usb/host/xhci-mtk-sch.c:265:20: warning: using sizeof on a flexible structure