All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Outreachy kernel] [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc
  2016-02-10  1:31 [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc Janani Ravichandran
@ 2016-02-09 22:01 ` Julia Lawall
  2016-02-09 22:20   ` Janani Ravichandran
  2016-02-10  6:19 ` Sudip Mukherjee
  1 sibling, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2016-02-09 22:01 UTC (permalink / raw)
  To: Janani Ravichandran; +Cc: outreachy-kernel



On Tue, 9 Feb 2016, Janani Ravichandran wrote:

> Use kmalloc_array instead of kmalloc for arrays. Coccinelle patch used:
> 
> @@
> expression E, F;
> constant FLAG;
> @@
> 
> - kmalloc(E*F, FLAG)
> + kmalloc_array(E, F, FLAG)

Actually, your patch doesn't do exactly this.  Your patch (correctly) has 
E and F switched in the call to kmalloc_array.

> 
> Signed-off-by: Janani Ravichandran <janani.rvchndrn@gmail.com>
> ---
> Changes since v1:
>  * Corrected an error in commit message.

"an error" is not very explicit.

julia

>  drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> index 28ad63a..fb344d1 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> @@ -601,8 +601,8 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
>  	bool			bMatchWinStart = false, bPktInBuf = false;
>  	IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize);
>  
> -	prxbIndicateArray = kmalloc(sizeof(struct ieee80211_rxb *) *
> -			REORDER_WIN_SIZE, GFP_KERNEL);
> +	prxbIndicateArray = kmalloc_array(RECORDER_WIN_SIZE,
> +			sizeof(struct ieee80211_rxb *), GFP_KERNEL);
>  	if (!prxbIndicateArray)
>  		return;
>  
> -- 
> 2.5.0
> 
> -- 
> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160210013122.GA12148%40janani-Inspiron-3521.
> For more options, visit https://groups.google.com/d/optout.
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc
  2016-02-09 22:01 ` [Outreachy kernel] " Julia Lawall
@ 2016-02-09 22:20   ` Janani Ravichandran
  2016-02-09 22:35     ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Janani Ravichandran @ 2016-02-09 22:20 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: janani.rvchndrn


[-- Attachment #1.1: Type: text/plain, Size: 2776 bytes --]



On Tuesday, 9 February 2016 17:01:18 UTC-5, Julia Lawall wrote:
>
>
>
> On Tue, 9 Feb 2016, Janani Ravichandran wrote: 
>
> > Use kmalloc_array instead of kmalloc for arrays. Coccinelle patch used: 
> > 
> > @@ 
> > expression E, F; 
> > constant FLAG; 
> > @@ 
> > 
> > - kmalloc(E*F, FLAG) 
> > + kmalloc_array(E, F, FLAG) 
>
> Actually, your patch doesn't do exactly this.  Your patch (correctly) has 
> E and F switched in the call to kmalloc_array. 
>
I actually used the semantic patch to find instances where the conversion 
could be applied, 
then looked at the declaration of kmalloc_array to determine the correct 
order of 
arguments and did the change manually to make sure the number of elements 
was the 
first argument and the size of the element was the second argument.

Please let me know if I should change anything here. Thank you!

Janani

>
> > 
> > Signed-off-by: Janani Ravichandran <janani....@gmail.com <javascript:>> 
> > --- 
> > Changes since v1: 
> >  * Corrected an error in commit message. 
>
> "an error" is not very explicit. 
>
> julia 
>
> >  drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++-- 
> >  1 file changed, 2 insertions(+), 2 deletions(-) 
> > 
> > diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c 
> b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c 
> > index 28ad63a..fb344d1 100644 
> > --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c 
> > +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c 
> > @@ -601,8 +601,8 @@ static void RxReorderIndicatePacket(struct 
> ieee80211_device *ieee, 
> >          bool                        bMatchWinStart = false, bPktInBuf = 
> false; 
> >          IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is 
> %d,pTS->RxIndicateSeq is %d, WinSize is 
> %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize); 
> >   
> > -        prxbIndicateArray = kmalloc(sizeof(struct ieee80211_rxb *) * 
> > -                        REORDER_WIN_SIZE, GFP_KERNEL); 
> > +        prxbIndicateArray = kmalloc_array(RECORDER_WIN_SIZE, 
> > +                        sizeof(struct ieee80211_rxb *), GFP_KERNEL); 
> >          if (!prxbIndicateArray) 
> >                  return; 
> >   
> > -- 
> > 2.5.0 
> > 
> > -- 
> > 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 outreachy-kern...@googlegroups.com <javascript:>. 
> > To post to this group, send email to outreach...@googlegroups.com 
> <javascript:>. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/outreachy-kernel/20160210013122.GA12148%40janani-Inspiron-3521. 
>
> > For more options, visit https://groups.google.com/d/optout. 
> > 
>

[-- Attachment #1.2: Type: text/html, Size: 4835 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc
  2016-02-09 22:20   ` Janani Ravichandran
@ 2016-02-09 22:35     ` Julia Lawall
  2016-02-09 22:40       ` Janani Ravichandran
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2016-02-09 22:35 UTC (permalink / raw)
  To: Janani Ravichandran; +Cc: outreachy-kernel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 4058 bytes --]



On Tue, 9 Feb 2016, Janani Ravichandran wrote:

> 
> 
> On Tuesday, 9 February 2016 17:01:18 UTC-5, Julia Lawall wrote:
> 
> 
>       On Tue, 9 Feb 2016, Janani Ravichandran wrote:
> 
>       > Use kmalloc_array instead of kmalloc for arrays. Coccinelle
>       patch used:
>       >
>       > @@
>       > expression E, F;
>       > constant FLAG;
>       > @@
>       >
>       > - kmalloc(E*F, FLAG)
>       > + kmalloc_array(E, F, FLAG)
> 
>       Actually, your patch doesn't do exactly this.  Your patch
>       (correctly) has
>       E and F switched in the call to kmalloc_array.
> 
> I actually used the semantic patch to find instances where the conversion
> could be applied,
> then looked at the declaration of kmalloc_array to determine the correct
> order of
> arguments and did the change manually to make sure the number of elements
> was the
> first argument and the size of the element was the second argument.
> 
> Please let me know if I should change anything here. Thank you!

The best solution would be to put:

- kmalloc(sizeof(T)*F, FLAG)
+ kmalloc_array(F, sizeof(T), FLAG)

where T is declared as a type metavariable.  This way one can see 
immediately that you have thought about the order in which to put the 
arguments.

julia

> 
> Janani
> 
>       >
>       > Signed-off-by: Janani Ravichandran <janani....@gmail.com>
>       > ---
>       > Changes since v1:
>       >  * Corrected an error in commit message.
> 
>       "an error" is not very explicit.
> 
>       julia
> 
>       >  drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
>       >  1 file changed, 2 insertions(+), 2 deletions(-)
>       >
>       > diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
>       b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
>       > index 28ad63a..fb344d1 100644
>       > --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
>       > +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
>       > @@ -601,8 +601,8 @@ static void RxReorderIndicatePacket(struct
>       ieee80211_device *ieee,
>       >          bool                        bMatchWinStart = false,
>       bPktInBuf = false;
>       >          IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is
>       %d,pTS->RxIndicateSeq is %d, WinSize is
>       %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize);
>       >  
>       > -        prxbIndicateArray = kmalloc(sizeof(struct
>       ieee80211_rxb *) *
>       > -                        REORDER_WIN_SIZE, GFP_KERNEL);
>       > +        prxbIndicateArray = kmalloc_array(RECORDER_WIN_SIZE,
>       > +                        sizeof(struct ieee80211_rxb *),
>       GFP_KERNEL);
>       >          if (!prxbIndicateArray)
>       >                  return;
>       >  
>       > --
>       > 2.5.0
>       >
>       > --
>       > 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 outreachy-kern...@googlegroups.com.
>       > To post to this group, send email to
>       outreach...@googlegroups.com.
>       > To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/20160210013122.GA12148%4
>       0janani-Inspiron-3521.
>       > For more options, visit https://groups.google.com/d/optout.
>       >
> 
> --
> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/37a3f0ea-26e5-4d78-8730-
> 81b7ed756644%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc
  2016-02-09 22:35     ` Julia Lawall
@ 2016-02-09 22:40       ` Janani Ravichandran
  0 siblings, 0 replies; 6+ messages in thread
From: Janani Ravichandran @ 2016-02-09 22:40 UTC (permalink / raw)
  To: Julia Lawall; +Cc: outreachy-kernel

[-- Attachment #1: Type: text/plain, Size: 3123 bytes --]

The best solution would be to put:

>
> - kmalloc(sizeof(T)*F, FLAG)
> + kmalloc_array(F, sizeof(T), FLAG)
>
> where T is declared as a type metavariable.  This way one can see
> immediately that you have thought about the order in which to put the
> arguments.
>

Thanks, Julia. I will send another version for this

Janani.

>
> julia
>
> >
> > Janani
> >
> >       >
> >       > Signed-off-by: Janani Ravichandran <janani....@gmail.com>
> >       > ---
> >       > Changes since v1:
> >       >  * Corrected an error in commit message.
> >
> >       "an error" is not very explicit.
> >
> >       julia
> >
> >       >  drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
> >       >  1 file changed, 2 insertions(+), 2 deletions(-)
> >       >
> >       > diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> >       b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> >       > index 28ad63a..fb344d1 100644
> >       > --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> >       > +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> >       > @@ -601,8 +601,8 @@ static void RxReorderIndicatePacket(struct
> >       ieee80211_device *ieee,
> >       >          bool                        bMatchWinStart = false,
> >       bPktInBuf = false;
> >       >          IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is
> >       %d,pTS->RxIndicateSeq is %d, WinSize is
> >       %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize);
> >       >
> >       > -        prxbIndicateArray = kmalloc(sizeof(struct
> >       ieee80211_rxb *) *
> >       > -                        REORDER_WIN_SIZE, GFP_KERNEL);
> >       > +        prxbIndicateArray = kmalloc_array(RECORDER_WIN_SIZE,
> >       > +                        sizeof(struct ieee80211_rxb *),
> >       GFP_KERNEL);
> >       >          if (!prxbIndicateArray)
> >       >                  return;
> >       >
> >       > --
> >       > 2.5.0
> >       >
> >       > --
> >       > 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 outreachy-kern...@googlegroups.com.
> >       > To post to this group, send email to
> >       outreach...@googlegroups.com.
> >       > To view this discussion on the web visithttps://
> groups.google.com/d/msgid/outreachy-kernel/20160210013122.GA12148%4
> >       0janani-Inspiron-3521.
> >       > For more options, visit https://groups.google.com/d/optout.
> >       >
> >
> > --
> > 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 outreachy-kernel+unsubscribe@googlegroups.com.
> > To post to this group, send email to outreachy-kernel@googlegroups.com.
> > To view this discussion on the web visithttps://
> groups.google.com/d/msgid/outreachy-kernel/37a3f0ea-26e5-4d78-8730-
> > 81b7ed756644%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
>

[-- Attachment #2: Type: text/html, Size: 5258 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc
@ 2016-02-10  1:31 Janani Ravichandran
  2016-02-09 22:01 ` [Outreachy kernel] " Julia Lawall
  2016-02-10  6:19 ` Sudip Mukherjee
  0 siblings, 2 replies; 6+ messages in thread
From: Janani Ravichandran @ 2016-02-10  1:31 UTC (permalink / raw)
  To: outreachy-kernel

Use kmalloc_array instead of kmalloc for arrays. Coccinelle patch used:

@@
expression E, F;
constant FLAG;
@@

- kmalloc(E*F, FLAG)
+ kmalloc_array(E, F, FLAG)

Signed-off-by: Janani Ravichandran <janani.rvchndrn@gmail.com>
---
Changes since v1:
 * Corrected an error in commit message.

 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index 28ad63a..fb344d1 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -601,8 +601,8 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
 	bool			bMatchWinStart = false, bPktInBuf = false;
 	IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize);
 
-	prxbIndicateArray = kmalloc(sizeof(struct ieee80211_rxb *) *
-			REORDER_WIN_SIZE, GFP_KERNEL);
+	prxbIndicateArray = kmalloc_array(RECORDER_WIN_SIZE,
+			sizeof(struct ieee80211_rxb *), GFP_KERNEL);
 	if (!prxbIndicateArray)
 		return;
 
-- 
2.5.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Outreachy kernel] [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc
  2016-02-10  1:31 [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc Janani Ravichandran
  2016-02-09 22:01 ` [Outreachy kernel] " Julia Lawall
@ 2016-02-10  6:19 ` Sudip Mukherjee
  1 sibling, 0 replies; 6+ messages in thread
From: Sudip Mukherjee @ 2016-02-10  6:19 UTC (permalink / raw)
  To: Janani Ravichandran; +Cc: outreachy-kernel

On Tue, Feb 09, 2016 at 08:31:22PM -0500, Janani Ravichandran wrote:
> Use kmalloc_array instead of kmalloc for arrays. Coccinelle patch used:
> 
> @@
> expression E, F;
> constant FLAG;
> @@
> 
> - kmalloc(E*F, FLAG)
> + kmalloc_array(E, F, FLAG)
> 
> Signed-off-by: Janani Ravichandran <janani.rvchndrn@gmail.com>
> ---
> Changes since v1:
>  * Corrected an error in commit message.
> 
>  drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> index 28ad63a..fb344d1 100644
> --- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> +++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
> @@ -601,8 +601,8 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
>  	bool			bMatchWinStart = false, bPktInBuf = false;
>  	IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n",__func__,SeqNum,pTS->RxIndicateSeq,WinSize);
>  
> -	prxbIndicateArray = kmalloc(sizeof(struct ieee80211_rxb *) *
> -			REORDER_WIN_SIZE, GFP_KERNEL);
> +	prxbIndicateArray = kmalloc_array(RECORDER_WIN_SIZE,

something is wrong. coccinelle should not change REORDER_WIN_SIZE to
RECORDER_WIN_SIZE...

and you did not build tested it before sending.

regards
sudip


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-10  6:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-10  1:31 [PATCH v2] staging: rtl8192u: Use kmalloc_array instead of kmalloc Janani Ravichandran
2016-02-09 22:01 ` [Outreachy kernel] " Julia Lawall
2016-02-09 22:20   ` Janani Ravichandran
2016-02-09 22:35     ` Julia Lawall
2016-02-09 22:40       ` Janani Ravichandran
2016-02-10  6:19 ` Sudip Mukherjee

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.