mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 3/5] drivers/scsi : Correct the size argument to kmalloc
@ 2009-12-29 19:16 Julia Lawall
  2009-12-29 20:02 ` Rolf Eike Beer
  0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2009-12-29 19:16 UTC (permalink / raw)
  To: James.Bottomley, linux-scsi, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

In each case, the destination of the allocation has type struct **, so the
elements of the array should have pointer type, not structure type.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@disable sizeof_type_expr@
type T;
T **x;
@@

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

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/scsi/aic94xx/aic94xx_init.c |    4 ++--
 drivers/scsi/ch.c                   |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff -u -p a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -687,9 +687,9 @@ static int asd_register_sas_ha(struct as
 {
 	int i;
 	struct asd_sas_phy   **sas_phys =
-		kmalloc(ASD_MAX_PHYS * sizeof(struct asd_sas_phy), GFP_KERNEL);
+		kmalloc(ASD_MAX_PHYS * sizeof(*sas_phys), GFP_KERNEL);
 	struct asd_sas_port  **sas_ports =
-		kmalloc(ASD_MAX_PHYS * sizeof(struct asd_sas_port), GFP_KERNEL);
+		kmalloc(ASD_MAX_PHYS * sizeof(*sas_ports), GFP_KERNEL);
 
 	if (!sas_phys || !sas_ports) {
 		kfree(sas_phys);
diff -u -p a/drivers/scsi/ch.c b/drivers/scsi/ch.c
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -351,7 +351,7 @@ ch_readconfig(scsi_changer *ch)
 	}
 
 	/* look up the devices of the data transfer elements */
-	ch->dt = kmalloc(ch->counts[CHET_DT]*sizeof(struct scsi_device),
+	ch->dt = kmalloc(ch->counts[CHET_DT]*sizeof(*ch->dt),
 			 GFP_KERNEL);
 
 	if (!ch->dt) {

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

* Re: [PATCH 3/5] drivers/scsi : Correct the size argument to kmalloc
  2009-12-29 19:16 [PATCH 3/5] drivers/scsi : Correct the size argument to kmalloc Julia Lawall
@ 2009-12-29 20:02 ` Rolf Eike Beer
  2009-12-29 20:04   ` Julia Lawall
  2009-12-29 20:13   ` Julia Lawall
  0 siblings, 2 replies; 6+ messages in thread
From: Rolf Eike Beer @ 2009-12-29 20:02 UTC (permalink / raw)
  To: Julia Lawall; +Cc: James.Bottomley, linux-scsi, linux-kernel, kernel-janitors

[-- Attachment #1: Type: Text/Plain, Size: 261 bytes --]

Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> In each case, the destination of the allocation has type struct **, so the
> elements of the array should have pointer type, not structure type.

Maybe they should even by kcalloc'ed?

Eike

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: [PATCH 3/5] drivers/scsi : Correct the size argument to kmalloc
  2009-12-29 20:02 ` Rolf Eike Beer
@ 2009-12-29 20:04   ` Julia Lawall
  2009-12-29 21:23     ` Joe Perches
  2009-12-29 20:13   ` Julia Lawall
  1 sibling, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2009-12-29 20:04 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: James.Bottomley, linux-scsi, linux-kernel, kernel-janitors

On Tue, 29 Dec 2009, Rolf Eike Beer wrote:

> Julia Lawall wrote:
> > From: Julia Lawall <julia@diku.dk>
> > 
> > In each case, the destination of the allocation has type struct **, so the
> > elements of the array should have pointer type, not structure type.
> 
> Maybe they should even by kcalloc'ed?

I thought about that, but in response to another patch someone seemed to 
think kcalloc was not very useful.  But I can certainly change it in this 
case.

julia

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

* Re: [PATCH 3/5] drivers/scsi : Correct the size argument to kmalloc
  2009-12-29 20:02 ` Rolf Eike Beer
  2009-12-29 20:04   ` Julia Lawall
@ 2009-12-29 20:13   ` Julia Lawall
  1 sibling, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2009-12-29 20:13 UTC (permalink / raw)
  To: Rolf Eike Beer; +Cc: James.Bottomley, linux-scsi, linux-kernel, kernel-janitors

From: Julia Lawall <julia@diku.dk>

In each case, the destination of the allocation has type struct **, so the
elements of the array should have pointer type, not structure type.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@disable sizeof_type_expr@
type T;
T **x;
@@

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

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/scsi/aic94xx/aic94xx_init.c |    4 ++--
 drivers/scsi/ch.c                   |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff -u -p a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -687,9 +687,9 @@ static int asd_register_sas_ha(struct as
 {
 	int i;
 	struct asd_sas_phy   **sas_phys =
-		kmalloc(ASD_MAX_PHYS * sizeof(struct asd_sas_phy), GFP_KERNEL);
+		kcalloc(ASD_MAX_PHYS, sizeof(*sas_phys), GFP_KERNEL);
 	struct asd_sas_port  **sas_ports =
-		kmalloc(ASD_MAX_PHYS * sizeof(struct asd_sas_port), GFP_KERNEL);
+		kcalloc(ASD_MAX_PHYS, sizeof(*sas_ports), GFP_KERNEL);
 
 	if (!sas_phys || !sas_ports) {
 		kfree(sas_phys);
diff -u -p a/drivers/scsi/ch.c b/drivers/scsi/ch.c
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -351,7 +351,7 @@ ch_readconfig(scsi_changer *ch)
 	}
 
 	/* look up the devices of the data transfer elements */
-	ch->dt = kmalloc(ch->counts[CHET_DT]*sizeof(struct scsi_device),
+	ch->dt = kcalloc(ch->counts[CHET_DT], sizeof(*ch->dt),
 			 GFP_KERNEL);
 
 	if (!ch->dt) {

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

* Re: [PATCH 3/5] drivers/scsi : Correct the size argument to kmalloc
  2009-12-29 20:04   ` Julia Lawall
@ 2009-12-29 21:23     ` Joe Perches
  2009-12-30 11:29       ` Julia Lawall
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2009-12-29 21:23 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Rolf Eike Beer, James.Bottomley, linux-scsi, linux-kernel,
	kernel-janitors

On Tue, 2009-12-29 at 21:04 +0100, Julia Lawall wrote:
> On Tue, 29 Dec 2009, Rolf Eike Beer wrote:
> > Julia Lawall wrote:
> > > From: Julia Lawall <julia@diku.dk>
> > > In each case, the destination of the allocation has type struct **, so the
> > > elements of the array should have pointer type, not structure type.
> > Maybe they should even by kcalloc'ed?
> I thought about that, but in response to another patch someone seemed to 
> think kcalloc was not very useful.  But I can certainly change it in this 
> case.

I think kcalloc is useful and should be used when the
allocated array of elements needs to be zeroed.

It appears the uses in 1/5 and 3/5 don't need it but
maybe patch 2/5 and 4/5 should use kcalloc.



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

* Re: [PATCH 3/5] drivers/scsi : Correct the size argument to kmalloc
  2009-12-29 21:23     ` Joe Perches
@ 2009-12-30 11:29       ` Julia Lawall
  0 siblings, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2009-12-30 11:29 UTC (permalink / raw)
  To: Joe Perches
  Cc: Rolf Eike Beer, James.Bottomley, linux-scsi, linux-kernel,
	kernel-janitors

On Tue, 29 Dec 2009, Joe Perches wrote:

> On Tue, 2009-12-29 at 21:04 +0100, Julia Lawall wrote:
> > On Tue, 29 Dec 2009, Rolf Eike Beer wrote:
> > > Julia Lawall wrote:
> > > > From: Julia Lawall <julia@diku.dk>
> > > > In each case, the destination of the allocation has type struct **, so the
> > > > elements of the array should have pointer type, not structure type.
> > > Maybe they should even by kcalloc'ed?
> > I thought about that, but in response to another patch someone seemed to 
> > think kcalloc was not very useful.  But I can certainly change it in this 
> > case.
> 
> I think kcalloc is useful and should be used when the
> allocated array of elements needs to be zeroed.
> 
> It appears the uses in 1/5 and 3/5 don't need it but
> maybe patch 2/5 and 4/5 should use kcalloc.

I will look into changing them too.

julia

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

end of thread, other threads:[~2009-12-30 11:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-29 19:16 [PATCH 3/5] drivers/scsi : Correct the size argument to kmalloc Julia Lawall
2009-12-29 20:02 ` Rolf Eike Beer
2009-12-29 20:04   ` Julia Lawall
2009-12-29 21:23     ` Joe Perches
2009-12-30 11:29       ` Julia Lawall
2009-12-29 20:13   ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®