staging: rtl8192u: Prefer using kmalloc_array
PATCH 1/1 staging: rtl8192u: Prefer using kmalloc_array
Use kmalloc_array instead of kmalloc for arrays to prevent integer overflows.
This was done using Coccinelle:
@@
expression e1, e2;
constant C;
type t;
@@
(
- kmalloc(sizeof(e1)*e2, C)
+ kmalloc_array(e2, sizeof(e1), C)
|
- kmalloc(e2*sizeof(e1), C)
+ kmalloc_array(e2, sizeof(e1), C)
|
- kmalloc(e2*sizeof(t), C)
+ kmalloc_array(e2, sizeof(t), C)
|
- kmalloc(sizeof(t)*e2, C)
+ kmalloc_array(e2, sizeof(t), C)
)
--- drivers/staging/rtl8192u/r8192U_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192u/r8192U_core.c +2 -2
@@ -1730,8 +1730,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev) {struct r8192_priv *priv =ieee80211_priv (dev); - priv->rx_urb =kmalloc (sizeof (struct urb *) * (MAX_RX_URB +1 ), -GFP_KERNEL ); + priv->rx_urb =kmalloc_array ((MAX_RX_URB +1 ),sizeof (struct urb *), +GFP_KERNEL );if (priv->rx_urb ==NULL )return -ENOMEM ;
--
2.1.4
Quoted 2 lines · Bhaktipriya Shridhar
Use
kmalloc_arrayinstead of kmalloc for arrays to prevent integer overflows.
No integer overflow is possible here, because the values involved are small constants. Greg has preferred to keep kmalloc in this case.
julia
Quoted 50 lines
This was done using Coccinelle:
@@
expression e1, e2;
constant C;
type t;
@@
(
-kmalloc(sizeof(e1)*e2, C)
+kmalloc_array(e2, sizeof(e1), C)
|
-kmalloc(e2*sizeof(e1), C)
+kmalloc_array(e2, sizeof(e1), C)
|
-kmalloc(e2*sizeof(t), C)
+kmalloc_array(e2, sizeof(t), C)
|
-kmalloc(sizeof(t)*e2, C)
+kmalloc_array(e2, sizeof(t), C)
)Signed-off-by Bhaktipriya Shridhar <[email protected]>--- drivers/staging/rtl8192u/r8192U_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/staging/rtl8192u/r8192U_core.c +2
-3@@ -1730,8 +1730,8 @@ static short rtl8192_usb_initendpoints(struct net_device *dev) {struct r8192_priv *priv =ieee80211_priv (dev); - priv->rx_urb =kmalloc (sizeof (struct urb *) * (MAX_RX_URB +1 ), -GFP_KERNEL ); + priv->rx_urb =kmalloc_array ((MAX_RX_URB +1 ),sizeof (struct urb *), +GFP_KERNEL );if (priv->rx_urb ==NULL )return -ENOMEM ; --2.1.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160221113352.GA28141%40Karyakshetra.
For more options, visit https://groups.google.com/d/optout.