Skip to contentSkip to conversation

preferred form for passing a size to memory allocation routines

PATCH In review anish 2 participants 3 messages May 15, 2011 – May 16, 2011 Staging

lore
Share & tools
lore

anish

author
#0 lore raw

PATCH 2/3 preferred form for passing a size to memory allocation routines

The preferred form for passing a size of a struct is the following:

         p = kmalloc(sizeof(*p), ...);

Please refer Documentation/Codingstyle chapter 14

---
drivers/staging/sm7xx/smtcfb.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/sm7xx/smtcfb.c
index c1b8228..d1dd387 100644

drivers/staging/sm7xx/smtcfb.c +0 -0
@@ -684,7 +684,7 @@ static struct smtcfb_info *smtc_alloc_fb_info(struct

pci_dev *dev,
{
struct smtcfb_info *sfb;

- sfb = kzalloc(sizeof(struct smtcfb_info), GFP_KERNEL);
+ sfb = kzalloc(sizeof(*sfb), GFP_KERNEL);

if (!sfb)
return NULL;

Signature · 1 line
1.7.0.4
Acked-by on v1 2/3
#1 lore raw
Quoted 6 lines · anish

The preferred form for passing a size of a struct is the following:

         p = kmalloc(sizeof(*p), ...);

Please refer Documentation/Codingstyle chapter 14

- sfb = kzalloc(sizeof(struct smtcfb_info), GFP_KERNEL);
+ sfb = kzalloc(sizeof(*sfb), GFP_KERNEL);

Hi anish,
Good catch ;)

author
#2 lore raw

PATCH 2/3 preferred form for passing a size to memory allocation routines[staging sm7xx]

In reply to anish

The preferred form for passing a size of a struct is the following:

         p = kmalloc(sizeof(*p), ...);

Please refer Documentation/Codingstyle chapter 14

---
 drivers/staging/sm7xx/smtcfb.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/sm7xx/smtcfb.c +1 -1
index 1aca0cb..c41d2f7 100644
@@ -714,7 +714,7 @@ static struct smtcfb_info *smtc_alloc_fb_info(struct pci_dev *dev,
 {
 	struct smtcfb_info *sfb;
 
-	sfb = kzalloc(sizeof(struct smtcfb_info), GFP_KERNEL);
+	sfb = kzalloc(sizeof(*sfb), GFP_KERNEL);
 
 	if (!sfb)
 		return NULL;
Signature · 1 line
1.7.0.4