Staging: lustre: obdclass: Use kasprintf instead of kzalloc and sprintf
authorShraddha Barke <shraddha.6596@gmail.com>
Fri, 4 Sep 2015 06:38:42 +0000 (12:08 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 13 Sep 2015 01:24:48 +0000 (18:24 -0700)
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/obdclass/obd_config.c

index d399cae2059e98f3ba7f50d60bd8a988ac3f6bac..7a5e87cec66ed1eb1c389fe1c669d4445cad545b 100644 (file)
@@ -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);