Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755539AbbHFLCK (ORCPT ); Thu, 6 Aug 2015 07:02:10 -0400 Received: from mail-pd0-f175.google.com ([209.85.192.175]:36258 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754673AbbHFLCG (ORCPT ); Thu, 6 Aug 2015 07:02:06 -0400 From: Shraddha Barke To: Andreas Dilger , Julia Lawall , Greg Kroah-Hartman , Greg Donald , Joe Perches , HPDD-discuss@ml01.01.org, linux-kernel@vger.kernel.org, Oleg Drokin Cc: Shraddha Barke Subject: [PATCH] Staging: lustre: obdclass: Use kasprintf instead of kzalloc and sprintf Date: Thu, 6 Aug 2015 16:31:50 +0530 Message-Id: <1438858910-14384-1-git-send-email-shraddha.6596@gmail.com> X-Mailer: git-send-email 2.1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1686 Lines: 55 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 --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/