Commit 4f016420 authored by Shraddha Barke's avatar Shraddha Barke Committed by Greg Kroah-Hartman

Staging: lustre: obdclass: Use kasprintf

This patch uses kasprintf which combines kzalloc and sprintf.
kasprintf also takes care of the size calculation.

Semantic patch used is as follows:

@@
expression a,flag;
expression list args;
statement S;
@@

 a =
- \(kmalloc\|kzalloc\)(...,flag)
+ kasprintf (flag,args)
  <... when != a
  if (a == NULL || ...) S
  ...>
- sprintf(a,args);
Signed-off-by: default avatarShraddha Barke <shraddha.6596@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 91f2208c
...@@ -247,13 +247,13 @@ int lustre_start_mgc(struct super_block *sb) ...@@ -247,13 +247,13 @@ int lustre_start_mgc(struct super_block *sb)
mutex_lock(&mgc_start_lock); mutex_lock(&mgc_start_lock);
len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1; len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
mgcname = kzalloc(len, GFP_NOFS); mgcname = kasprintf(GFP_NOFS,
niduuid = kzalloc(len + 2, GFP_NOFS); "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
niduuid = kasprintf(GFP_NOFS, "%s_%x", mgcname, i);
if (!mgcname || !niduuid) { if (!mgcname || !niduuid) {
rc = -ENOMEM; rc = -ENOMEM;
goto out_free; goto out_free;
} }
sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : ""; mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
...@@ -326,7 +326,6 @@ int lustre_start_mgc(struct super_block *sb) ...@@ -326,7 +326,6 @@ int lustre_start_mgc(struct super_block *sb)
/* Add the primary nids for the MGS */ /* Add the primary nids for the MGS */
i = 0; i = 0;
sprintf(niduuid, "%s_%x", mgcname, i);
if (IS_SERVER(lsi)) { if (IS_SERVER(lsi)) {
ptr = lsi->lsi_lmd->lmd_mgs; ptr = lsi->lsi_lmd->lmd_mgs;
if (IS_MGS(lsi)) { if (IS_MGS(lsi)) {
...@@ -1120,10 +1119,9 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd) ...@@ -1120,10 +1119,9 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
/* Remove leading /s from fsname */ /* Remove leading /s from fsname */
while (*++s1 == '/') ; while (*++s1 == '/') ;
/* Freed in lustre_free_lsi */ /* Freed in lustre_free_lsi */
lmd->lmd_profile = kzalloc(strlen(s1) + 8, GFP_NOFS); lmd->lmd_profile = kasprintf(GFP_NOFS, "%s-client", s1);
if (!lmd->lmd_profile) if (!lmd->lmd_profile)
return -ENOMEM; return -ENOMEM;
sprintf(lmd->lmd_profile, "%s-client", s1);
} }
/* Freed in lustre_free_lsi */ /* Freed in lustre_free_lsi */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment