From: Shraddha Barke <shraddha.6596@gmail.com>
To: Andreas Dilger <andreas.dilger@intel.com>,
Julia Lawall <Julia.Lawall@lip6.fr>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Greg Donald <gdonald@gmail.com>, Joe Perches <joe@perches.com>,
HPDD-discuss@ml01.01.org, linux-kernel@vger.kernel.org,
Oleg Drokin <oleg.drokin@intel.com>
Cc: Shraddha Barke <shraddha.6596@gmail.com>
Subject: [PATCH] Staging: lustre: obdclass: Use kasprintf instead of kzalloc and sprintf
Date: Thu, 6 Aug 2015 16:31:50 +0530 [thread overview]
Message-ID: <1438858910-14384-1-git-send-email-shraddha.6596@gmail.com> (raw)
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: Shraddha Barke <shraddha.6596@gmail.com>
---
drivers/staging/lustre/lustre/obdclass/obd_config.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
index 93805ac..e0470c0 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
@@ -1455,14 +1455,13 @@ int class_config_llog_handler(const struct lu_env *env,
inst = 1;
inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
sizeof(clli->cfg_instance) * 2 + 4;
- inst_name = kzalloc(inst_len, GFP_NOFS);
+ inst_name = kasprintf(GFP_NOFS, "%s-%p",
+ lustre_cfg_string(lcfg, 0),
+ clli->cfg_instance);
if (!inst_name) {
rc = -ENOMEM;
goto out;
}
- sprintf(inst_name, "%s-%p",
- lustre_cfg_string(lcfg, 0),
- clli->cfg_instance);
lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
lcfg->lcfg_command, inst_name);
--
2.1.0
reply other threads:[~2015-08-06 11:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1438858910-14384-1-git-send-email-shraddha.6596@gmail.com \
--to=shraddha.6596@gmail.com \
--cc=HPDD-discuss@ml01.01.org \
--cc=Julia.Lawall@lip6.fr \
--cc=andreas.dilger@intel.com \
--cc=gdonald@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg.drokin@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).