lkml.org 
[lkml]   [2022]   [Jan]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH][next] usb: dwc2: Use flex_array_size() helper
Make use of the flex_array_size() helper to calculate the size of a
flexible array member within an enclosing structure.

This helper offers defense-in-depth against potential integer
overflows, while at the same time makes it explicitly clear that
we are dealing with a flexible array member.

Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/usb/dwc2/hcd.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index f63a27d11fac..2c21498662cd 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -4054,8 +4054,9 @@ struct dwc2_tt *dwc2_host_get_tt_info(struct dwc2_hsotg *hsotg, void *context,
* For single_tt we need one schedule. For multi_tt
* we need one per port.
*/
- bitmap_size = DWC2_ELEMENTS_PER_LS_BITMAP *
- sizeof(dwc_tt->periodic_bitmaps[0]);
+ bitmap_size =
+ flex_array_size(dwc_tt, periodic_bitmaps,
+ DWC2_ELEMENTS_PER_LS_BITMAP);
if (urb->dev->tt->multi)
bitmap_size *= urb->dev->tt->hub->maxchild;

--
2.27.0
\
 
 \ /
  Last update: 2022-01-11 08:49    [W:0.065 / U:0.180 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site