From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5D1FC43464 for ; Sat, 19 Sep 2020 09:37:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2EA721582 for ; Sat, 19 Sep 2020 09:37:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726222AbgISJhJ (ORCPT ); Sat, 19 Sep 2020 05:37:09 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:13768 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726097AbgISJhJ (ORCPT ); Sat, 19 Sep 2020 05:37:09 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D23E5170A5BB9ACD5BC3; Sat, 19 Sep 2020 17:37:05 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.177.253) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Sat, 19 Sep 2020 17:36:56 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel CC: Zhen Lei , Libin , Kefeng Wang Subject: [PATCH v2 1/1] libnvdimm/namespace: avoid repeated judgment in nvdimm_namespace_disk_name() Date: Sat, 19 Sep 2020 17:36:29 +0800 Message-ID: <20200919093629.3792-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The judgment (suffix ? suffix : "") appears three times, we do this just because the initial value of local variable "suffix" is NULL, should be replaced with empty string "" to avoid null pointer reference. It's easy to get rid of it as below: - const char *suffix = NULL; + const char *suffix = ""; To avoid having rows that exceed 80 columns, add a new local variable "region_id". No functional change, but it can reduce the code size. Before: text data bss dec hex filename 41749 3697 16 45462 b196 drivers/nvdimm/namespace_devs.o After: text data bss dec hex filename 41653 3697 16 45366 b136 drivers/nvdimm/namespace_devs.o Signed-off-by: Zhen Lei --- v1 --> v2: 1. Only the title and description are modified. v1: https://lore.kernel.org/patchwork/patch/1292584/ drivers/nvdimm/namespace_devs.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 6da67f4d641a27c..ef2800c5da4c99c 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -157,7 +157,8 @@ const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns, char *name) { struct nd_region *nd_region = to_nd_region(ndns->dev.parent); - const char *suffix = NULL; + const char *suffix = ""; + int region_id = nd_region->id; if (ndns->claim && is_nd_btt(ndns->claim)) suffix = "s"; @@ -173,17 +174,14 @@ const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns, } if (nsidx) - sprintf(name, "pmem%d.%d%s", nd_region->id, nsidx, - suffix ? suffix : ""); + sprintf(name, "pmem%d.%d%s", region_id, nsidx, suffix); else - sprintf(name, "pmem%d%s", nd_region->id, - suffix ? suffix : ""); + sprintf(name, "pmem%d%s", region_id, suffix); } else if (is_namespace_blk(&ndns->dev)) { struct nd_namespace_blk *nsblk; nsblk = to_nd_namespace_blk(&ndns->dev); - sprintf(name, "ndblk%d.%d%s", nd_region->id, nsblk->id, - suffix ? suffix : ""); + sprintf(name, "ndblk%d.%d%s", region_id, nsblk->id, suffix); } else { return NULL; } -- 1.8.3