All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Staging: Modify argument of sizeof() to pointer variables.
@ 2016-09-16 20:47 Sandhya Bankar
  2016-09-16 20:50 ` [PATCH 1/2] Staging: android: " Sandhya Bankar
  2016-09-16 20:53 ` [PATCH 2/2] Staging: lustre: " Sandhya Bankar
  0 siblings, 2 replies; 6+ messages in thread
From: Sandhya Bankar @ 2016-09-16 20:47 UTC (permalink / raw)
  To: outreachy-kernel
  Cc: gregkh, labbott, sumit.semwal, arve, riandrews, oleg.drokin,
	andreas.dilger, jsimmons

Modify arguments of sizeof() to pointer variables.
The destination of the allocation has type struct **, so the 
elements of the array should have pointer type, not structure type.

These changes are made using below Coccinelle script:
 
@disable sizeof_type_expr@
type T;
T **x;
@@

  x =
  <+...sizeof(
- T
+ *x
  )...+>


Sandhya Bankar (2):
  Staging: android: Modify argument of sizeof() to pointer variables.
  Staging: lustre: Modify argument of sizeof() to pointer variables.

 drivers/staging/android/ion/hisilicon/hi6220_ion.c |    2 +-
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)



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

* [PATCH 1/2] Staging: android: Modify argument of sizeof() to pointer variables.
  2016-09-16 20:47 [PATCH 0/2] Staging: Modify argument of sizeof() to pointer variables Sandhya Bankar
@ 2016-09-16 20:50 ` Sandhya Bankar
  2016-09-17 18:27   ` [Outreachy kernel] " Greg KH
  2016-09-16 20:53 ` [PATCH 2/2] Staging: lustre: " Sandhya Bankar
  1 sibling, 1 reply; 6+ messages in thread
From: Sandhya Bankar @ 2016-09-16 20:50 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: gregkh, labbott, sumit.semwal, arve, riandrews

Modify arguments of sizeof() to pointer variables.
The destination of the allocation has type struct **, so the
elements of the array should have pointer type, not structure type.

These changes are made using below Coccinelle script:

@disable sizeof_type_expr@
type T;
T **x;
@@

  x =
  <+...sizeof(
- T
+ *x
  )...+>

Signed-off-by: Sandhya Bankar <bankarsandhya512@gmail.com>
---
 drivers/staging/android/ion/hisilicon/hi6220_ion.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/android/ion/hisilicon/hi6220_ion.c b/drivers/staging/android/ion/hisilicon/hi6220_ion.c
index 659aa71..4f0dd4b 100755
--- a/drivers/staging/android/ion/hisilicon/hi6220_ion.c
+++ b/drivers/staging/android/ion/hisilicon/hi6220_ion.c
@@ -57,7 +57,7 @@ static int hi6220_ion_probe(struct platform_device *pdev)
 		return PTR_ERR(ipdev->data);
 
 	ipdev->heaps = devm_kzalloc(&pdev->dev,
-				sizeof(struct ion_heap)*ipdev->data->nr,
+				sizeof(*ipdev->heaps)*ipdev->data->nr,
 				GFP_KERNEL);
 	if (!ipdev->heaps) {
 		ion_destroy_platform_data(ipdev->data);
-- 
1.7.1



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

* [PATCH 2/2] Staging: lustre: Modify argument of sizeof() to pointer variables.
  2016-09-16 20:47 [PATCH 0/2] Staging: Modify argument of sizeof() to pointer variables Sandhya Bankar
  2016-09-16 20:50 ` [PATCH 1/2] Staging: android: " Sandhya Bankar
@ 2016-09-16 20:53 ` Sandhya Bankar
  2016-09-17  8:49   ` [Outreachy kernel] " Julia Lawall
  1 sibling, 1 reply; 6+ messages in thread
From: Sandhya Bankar @ 2016-09-16 20:53 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: oleg.drokin, andreas.dilger, jsimmons, gregkh

Modify arguments of sizeof() to pointer variables.
The destination of the allocation has type struct **, so the
elements of the array should have pointer type, not structure type.

These changes are made using below Coccinelle script:

@disable sizeof_type_expr@
type T;
T **x;
@@

  x =
  <+...sizeof(
- T
+ *x
  )...+>

Signed-off-by: Sandhya Bankar <bankarsandhya512@gmail.com>
---
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index c7a5d49..5f17c82 100755
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -2206,7 +2206,7 @@ static int kiblnd_net_init_pools(struct kib_net *net, lnet_ni_t *ni, __u32 *cpts
 	 * number of CPTs that exist, i.e net->ibn_fmr_ps[cpt].
 	 */
 	net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
-					   sizeof(struct kib_fmr_poolset));
+					   sizeof(*net->ibn_fmr_ps));
 	if (!net->ibn_fmr_ps) {
 		CERROR("Failed to allocate FMR pool array\n");
 		rc = -ENOMEM;
@@ -2234,7 +2234,7 @@ static int kiblnd_net_init_pools(struct kib_net *net, lnet_ni_t *ni, __u32 *cpts
 	 * number of CPTs that exist, i.e net->ibn_tx_ps[cpt].
 	 */
 	net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
-					  sizeof(struct kib_tx_poolset));
+					  sizeof(*net->ibn_tx_ps));
 	if (!net->ibn_tx_ps) {
 		CERROR("Failed to allocate tx pool array\n");
 		rc = -ENOMEM;
-- 
1.7.1



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

* Re: [Outreachy kernel] [PATCH 2/2] Staging: lustre: Modify argument of sizeof() to pointer variables.
  2016-09-16 20:53 ` [PATCH 2/2] Staging: lustre: " Sandhya Bankar
@ 2016-09-17  8:49   ` Julia Lawall
       [not found]     ` <6B5E7F24-CAC2-49CB-B717-6D64C40CFE82@intel.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2016-09-17  8:49 UTC (permalink / raw)
  To: Sandhya Bankar
  Cc: outreachy-kernel, oleg.drokin, andreas.dilger, jsimmons, gregkh



On Sat, 17 Sep 2016, Sandhya Bankar wrote:

> Modify arguments of sizeof() to pointer variables.
> The destination of the allocation has type struct **, so the
> elements of the array should have pointer type, not structure type.
>
> These changes are made using below Coccinelle script:
>
> @disable sizeof_type_expr@
> type T;
> T **x;
> @@
>
>   x =
>   <+...sizeof(
> - T
> + *x
>   )...+>
>
> Signed-off-by: Sandhya Bankar <bankarsandhya512@gmail.com>
> ---
>  .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> index c7a5d49..5f17c82 100755
> --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> @@ -2206,7 +2206,7 @@ static int kiblnd_net_init_pools(struct kib_net *net, lnet_ni_t *ni, __u32 *cpts
>  	 * number of CPTs that exist, i.e net->ibn_fmr_ps[cpt].
>  	 */
>  	net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
> -					   sizeof(struct kib_fmr_poolset));
> +					   sizeof(*net->ibn_fmr_ps));

Did you check on what cfs_percpt_alloc actually does with this
information?  This is not an obvious case, like kmalloc.  The commit
message should explain what the function does with the size information
and why the change is correct.

julia

>  	if (!net->ibn_fmr_ps) {
>  		CERROR("Failed to allocate FMR pool array\n");
>  		rc = -ENOMEM;
> @@ -2234,7 +2234,7 @@ static int kiblnd_net_init_pools(struct kib_net *net, lnet_ni_t *ni, __u32 *cpts
>  	 * number of CPTs that exist, i.e net->ibn_tx_ps[cpt].
>  	 */
>  	net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
> -					  sizeof(struct kib_tx_poolset));
> +					  sizeof(*net->ibn_tx_ps));
>  	if (!net->ibn_tx_ps) {
>  		CERROR("Failed to allocate tx pool array\n");
>  		rc = -ENOMEM;
> --
> 1.7.1
>
> --
> 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/84439d72e1db653a0e7511e9a29c5b2c23703eab.1474055668.git.bankarsandhya512%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>


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

* Re: [Outreachy kernel] [PATCH 1/2] Staging: android: Modify argument of sizeof() to pointer variables.
  2016-09-16 20:50 ` [PATCH 1/2] Staging: android: " Sandhya Bankar
@ 2016-09-17 18:27   ` Greg KH
  0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2016-09-17 18:27 UTC (permalink / raw)
  To: Sandhya Bankar; +Cc: outreachy-kernel, labbott, sumit.semwal, arve, riandrews

On Sat, Sep 17, 2016 at 02:20:59AM +0530, Sandhya Bankar wrote:
> Modify arguments of sizeof() to pointer variables.
> The destination of the allocation has type struct **, so the
> elements of the array should have pointer type, not structure type.
> 
> These changes are made using below Coccinelle script:
> 
> @disable sizeof_type_expr@
> type T;
> T **x;
> @@
> 
>   x =
>   <+...sizeof(
> - T
> + *x
>   )...+>
> 
> Signed-off-by: Sandhya Bankar <bankarsandhya512@gmail.com>
> ---
>  drivers/staging/android/ion/hisilicon/hi6220_ion.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/staging/android/ion/hisilicon/hi6220_ion.c b/drivers/staging/android/ion/hisilicon/hi6220_ion.c
> index 659aa71..4f0dd4b 100755
> --- a/drivers/staging/android/ion/hisilicon/hi6220_ion.c
> +++ b/drivers/staging/android/ion/hisilicon/hi6220_ion.c
> @@ -57,7 +57,7 @@ static int hi6220_ion_probe(struct platform_device *pdev)
>  		return PTR_ERR(ipdev->data);
>  
>  	ipdev->heaps = devm_kzalloc(&pdev->dev,
> -				sizeof(struct ion_heap)*ipdev->data->nr,
> +				sizeof(*ipdev->heaps)*ipdev->data->nr,

You just changed the size of the memory you allocated, please always be
_VERY_ careful when making a change like this.  The original code is
correct, please leave it as-is.

thanks,

greg k-h


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

* Re: [Outreachy kernel] [PATCH 2/2] Staging: lustre: Modify argument of sizeof() to pointer variables.
       [not found]       ` <alpine.LFD.2.20.1609182113040.31599@casper.infradead.org>
@ 2016-09-19 15:37         ` sandhya bankar
  0 siblings, 0 replies; 6+ messages in thread
From: sandhya bankar @ 2016-09-19 15:37 UTC (permalink / raw)
  To: James Simmons
  Cc: Dilger, Andreas, Julia Lawall, outreachy-kernel@googlegroups.com,
	Drokin, Oleg, gregkh@linuxfoundation.org

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

I will update and send patch after a compile test as per your suggestion.

On Mon, Sep 19, 2016 at 1:43 AM, James Simmons <jsimmons@infradead.org>
wrote:

>
> > > On Sat, 17 Sep 2016, Sandhya Bankar wrote:
> > >
> > >> Modify arguments of sizeof() to pointer variables.
> > >> The destination of the allocation has type struct **, so the
> > >> elements of the array should have pointer type, not structure type.
> > >>
> > >> These changes are made using below Coccinelle script:
> > >>
> > >> @disable sizeof_type_expr@
> > >> type T;
> > >> T **x;
> > >> @@
> > >>
> > >>  x =
> > >>  <+...sizeof(
> > >> - T
> > >> + *x
> > >>  )...+>
> > >>
> > >> Signed-off-by: Sandhya Bankar <bankarsandhya512@gmail.com>
> > >> ---
> > >> .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |    4 ++--
> > >> 1 files changed, 2 insertions(+), 2 deletions(-)
> > >>
> > >> diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> > >> index c7a5d49..5f17c82 100755
> > >> --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> > >> +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
> > >> @@ -2206,7 +2206,7 @@ static int kiblnd_net_init_pools(struct kib_net
> *net, lnet_ni_t *ni, __u32 *cpts
> > >>     * number of CPTs that exist, i.e net->ibn_fmr_ps[cpt].
> > >>     */
> > >>    net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
> > >> -                                     sizeof(struct kib_fmr_poolset));
> > >> +                                     sizeof(*net->ibn_fmr_ps));
> > >
> > > Did you check on what cfs_percpt_alloc actually does with this
> > > information?  This is not an obvious case, like kmalloc.  The commit
> > > message should explain what the function does with the size information
> > > and why the change is correct.
> >
> > Julia,
> > thanks for the sharp eyes.  Indeed cfs_percpt_alloc() allocates an array
> > of structs and returns the pointer to the array, so the current code is
> > correct.
> >
> > Sandhya,
> > That said, I also prefer the sizeof(*<type>) usage rather than the
> > sizeof(struct name) usage, since the former will continue to work if
> > <type> changes for some reason.  Could you please update your patch like:
> >
> >       net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
> >                                          sizeof(**net->ibn_fmr_ps));
> >
> > which should work, though I'm not 100% positive (needs a compile test
> > at least, as any patch does).
> >
> > >>    if (!net->ibn_fmr_ps) {
> > >>            CERROR("Failed to allocate FMR pool array\n");
> > >>            rc = -ENOMEM;
> > >> @@ -2234,7 +2234,7 @@ static int kiblnd_net_init_pools(struct kib_net
> *net, lnet_ni_t *ni, __u32 *cpts
> > >>     * number of CPTs that exist, i.e net->ibn_tx_ps[cpt].
> > >>     */
> > >>    net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
> > >> -                                    sizeof(struct kib_tx_poolset));
> > >> +                                    sizeof(*net->ibn_tx_ps));
> >
> > Similarly:
> >
> >       net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
> >                                         sizeof(**net->ibn_tx_ps));
> >
>
> I have the hardware to test this. Just CC when you have a new patch ready.
>
> > Cheers, Andreas
> >
> > >>    if (!net->ibn_tx_ps) {
> > >>            CERROR("Failed to allocate tx pool array\n");
> > >>            rc = -ENOMEM;
> > >> --
> > >> 1.7.1
> > >>
> > >> --
> > >> 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/84439d72e1db653a0e7511e9a29c5b
> 2c23703eab.1474055668.git.bankarsandhya512%40gmail.com.
> > >> For more options, visit https://groups.google.com/d/optout.
> > >>
> >
> >
>

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

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

end of thread, other threads:[~2016-09-19 15:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-16 20:47 [PATCH 0/2] Staging: Modify argument of sizeof() to pointer variables Sandhya Bankar
2016-09-16 20:50 ` [PATCH 1/2] Staging: android: " Sandhya Bankar
2016-09-17 18:27   ` [Outreachy kernel] " Greg KH
2016-09-16 20:53 ` [PATCH 2/2] Staging: lustre: " Sandhya Bankar
2016-09-17  8:49   ` [Outreachy kernel] " Julia Lawall
     [not found]     ` <6B5E7F24-CAC2-49CB-B717-6D64C40CFE82@intel.com>
     [not found]       ` <alpine.LFD.2.20.1609182113040.31599@casper.infradead.org>
2016-09-19 15:37         ` sandhya bankar

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.