From patchwork Sat Sep 19 11:01:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 11786959 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4B56B59D for ; Sat, 19 Sep 2020 11:02:15 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 010482158C for ; Sat, 19 Sep 2020 11:02:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 010482158C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5972E152B927C; Sat, 19 Sep 2020 04:02:14 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.32; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3895C152B9276 for ; Sat, 19 Sep 2020 04:02:02 -0700 (PDT) Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 0B7B4FB3D20829E1D781; Sat, 19 Sep 2020 19:02:00 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.177.253) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Sat, 19 Sep 2020 19:01:53 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel Subject: [PATCH v2 1/1] libnvdimm/namespace: avoid repeated judgment in nvdimm_namespace_disk_name() Date: Sat, 19 Sep 2020 19:01:46 +0800 Message-ID: <20200919110146.3909-1-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: TAC7GQBIYXJCZHXPVV5XHDIRDUHEDIWH X-Message-ID-Hash: TAC7GQBIYXJCZHXPVV5XHDIRDUHEDIWH X-MailFrom: thunder.leizhen@huawei.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Zhen Lei , Libin , Kefeng Wang X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: 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; }