Skip to contentSkip to conversation

staging: lustre: Use kasprintf.

PATCH In review Navya Sri Nizamkari 2 participants 3 messages Mar 1, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: lustre: Use kasprintf.

This patch uses kasprintf as it combines kmalloc and sprintf, and takes care of the size calculation itself.

The semantic patch that makes this change is as follows:

// <smpl>
@@
expression a,flag;
expression list args;
statement S;
@@

a =
- \(kmalloc\|kzalloc\)(...,flag)
+ kasprintf(flag,args)
<... when != a
if (a == NULL || ...) S
...>
- sprintf(a,args);

---
Changes in v2:
-Change arguments of kasprintf to the right ones.

 drivers/staging/lustre/lustre/llite/llite_lib.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/llite/llite_lib.c +2 -4
index 0c1b583..26e8626 100644
@@ -978,19 +978,17 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
 	CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
 	       lprof->lp_md, lprof->lp_dt);
 
-	dt = kzalloc(strlen(lprof->lp_dt) + instlen + 2, GFP_NOFS);
+	dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
 	if (!dt) {
 		err = -ENOMEM;
 		goto out_free;
 	}
-	sprintf(dt, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
 
-	md = kzalloc(strlen(lprof->lp_md) + instlen + 2, GFP_NOFS);
+	md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
 	if (!md) {
 		err = -ENOMEM;
 		goto out_free;
 	}
-	sprintf(md, "%s-%p", lprof->lp_md, cfg->cfg_instance);
 
 	/* connections, registrations, sb setup */
 	err = client_common_fill_super(sb, md, dt, mnt);
Signature · 1 line
1.9.1
Acked-by on v2 1/1
#1 lore raw
Quoted 13 lines · Navya Sri Nizamkari

This patch uses kasprintf as it combines kmalloc and sprintf, and takes care of the size calculation itself.

The semantic patch that makes this change is as follows:

// <smpl>
@@
expression a,flag;
expression list args;
statement S;
@@

a =

Review

Quoted 6 lines
(quoted diff) +1 -2
-  \(kmalloc\|kzalloc\)(...,flag)
+  kasprintf(flag,args)
  <... when != a
  if (a == NULL || ...) S
  ...>
- sprintf(a,args);

Nice :)

Quoted 45 lines

---
Changes in v2:
-Change arguments of kasprintf to the right ones.

 drivers/staging/lustre/lustre/llite/llite_lib.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/lustre/lustre/llite/llite_lib.c +2 -5
index 0c1b583..26e8626 100644
@@ -978,19 +978,17 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
 	CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
 	       lprof->lp_md, lprof->lp_dt);
 
-	dt = kzalloc(strlen(lprof->lp_dt) + instlen + 2, GFP_NOFS);
+	dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
 	if (!dt) {
 		err = -ENOMEM;
 		goto out_free;
 	}
-	sprintf(dt, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
 
-	md = kzalloc(strlen(lprof->lp_md) + instlen + 2, GFP_NOFS);
+	md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
 	if (!md) {
 		err = -ENOMEM;
 		goto out_free;
 	}
-	sprintf(md, "%s-%p", lprof->lp_md, cfg->cfg_instance);
 
 	/* connections, registrations, sb setup */
 	err = client_common_fill_super(sb, md, dt, mnt);
--

1.9.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 [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/20150301073759.GA21185%40localhost.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
Quoted 86 lines · Julia Lawall
Quoted 13 lines · Navya Sri Nizamkari

This patch uses kasprintf as it combines kmalloc and sprintf, and takes care of the size calculation itself.

The semantic patch that makes this change is as follows:

// <smpl>
@@
expression a,flag;
expression list args;
statement S;
@@

a =

Review

Quoted 6 lines
(quoted diff) +1 -2
-  \(kmalloc\|kzalloc\)(...,flag) 
+  kasprintf(flag,args) 
  <... when != a 
  if (a == NULL || ...) S 
  ...> 
- sprintf(a,args); 

Nice :)

Acked-by Julia Lawall <[email protected] <javascript:>>

Thank You :)

Review

Quoted 10 lines
Signed-off-by Navya Sri Nizamkari <[email protected] <javascript:>>

---
Changes in v2:
-Change arguments of kasprintf to the right ones.

 drivers/staging/lustre/lustre/llite/llite_lib.c | 6 ++---- 
 1 file changed, 2 insertions(+), 4 deletions(-) 
(quoted diff) +0 -0

b/drivers/staging/lustre/lustre/llite/llite_lib.c

drivers/staging/lustre/lustre/llite/llite_lib.c int ll_fill_super(struct super_block *sb, struct

Quoted 4 lines

index 0c1b583..26e8626 100644

drivers/staging/lustre/lustre/llite/llite_lib.c +0 -0
@@ -978,19 +978,17 @@ int ll_fill_super(struct super_block *sb, struct 

vfsmount *mnt)

drivers/staging/lustre/lustre/llite/llite_lib.c int ll_fill_super(struct super_block *sb, struct · line 978

Quoted 1 line
drivers/staging/lustre/lustre/llite/llite_lib.c +0 -0
         CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", 

profilenm,

drivers/staging/lustre/lustre/llite/llite_lib.c int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)

Quoted 4 lines
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
                lprof->lp_md, lprof->lp_dt); 
 
-        dt = kzalloc(strlen(lprof->lp_dt) + instlen + 2, GFP_NOFS); 
+        dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, 

cfg->cfg_instance);

drivers/staging/lustre/lustre/llite/llite_lib.c int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)

Quoted 8 lines
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -2
         if (!dt) { 
                 err = -ENOMEM; 
                 goto out_free; 
         } 
-        sprintf(dt, "%s-%p", lprof->lp_dt, cfg->cfg_instance); 
 
-        md = kzalloc(strlen(lprof->lp_md) + instlen + 2, GFP_NOFS); 
+        md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, 

cfg->cfg_instance);

Quoted 13 lines
drivers/staging/lustre/lustre/llite/llite_lib.c +0 -1
         if (!md) { 
                 err = -ENOMEM; 
                 goto out_free; 
         } 
-        sprintf(md, "%s-%p", lprof->lp_md, cfg->cfg_instance); 
 
         /* connections, registrations, sb setup */ 
         err = client_common_fill_super(sb, md, dt, mnt); 
Signature · 4 lines
1.9.1 

-- 
You received this message because you are subscribed to the Google 

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected] <javascript:>.

Quoted 1 line

To post to this group, send email to [email protected]

<javascript:>.

Quoted 1 line

To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/20150301073759.GA21185%40localhost.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.