From patchwork Thu Aug 20 02:16:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 11725365 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 98EB01392 for ; Thu, 20 Aug 2020 02:17:38 +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 82185207DA for ; Thu, 20 Aug 2020 02:17:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82185207DA 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 4E51D13524464; Wed, 19 Aug 2020 19:17:35 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.190; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 5537C13515B51 for ; Wed, 19 Aug 2020 19:17:28 -0700 (PDT) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 8D4DB9D049F6803AC068; Thu, 20 Aug 2020 10:17:25 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 10:17:15 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel Subject: [PATCH v3 1/7] libnvdimm: fix memory leaks in of_pmem.c Date: Thu, 20 Aug 2020 10:16:35 +0800 Message-ID: <20200820021641.3188-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820021641.3188-1-thunder.leizhen@huawei.com> References: <20200820021641.3188-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: JTNFGVGGQ5TNEMNIXDQLGERNNMDFVVPT X-Message-ID-Hash: JTNFGVGGQ5TNEMNIXDQLGERNNMDFVVPT 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 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: Currently, in the last error path of of_pmem_region_probe() and in of_pmem_region_remove(), free the memory allocated by kstrdup() is missing. Add kfree(priv->bus_desc.provider_name) to fix it. Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Zhen Lei Reviewed-by: Oliver O'Halloran --- drivers/nvdimm/of_pmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 10dbdcdfb9ce913..1292ffca7b2ecc0 100644 --- a/drivers/nvdimm/of_pmem.c +++ b/drivers/nvdimm/of_pmem.c @@ -36,6 +36,7 @@ static int of_pmem_region_probe(struct platform_device *pdev) priv->bus = bus = nvdimm_bus_register(&pdev->dev, &priv->bus_desc); if (!bus) { + kfree(priv->bus_desc.provider_name); kfree(priv); return -ENODEV; } @@ -83,6 +84,7 @@ static int of_pmem_region_remove(struct platform_device *pdev) struct of_pmem_private *priv = platform_get_drvdata(pdev); nvdimm_bus_unregister(priv->bus); + kfree(priv->bus_desc.provider_name); kfree(priv); return 0; From patchwork Thu Aug 20 02:16:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 11725353 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 EA8A5618 for ; Thu, 20 Aug 2020 02:17:31 +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 B06F0207DA for ; Thu, 20 Aug 2020 02:17:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B06F0207DA 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 70C8A13515B4C; Wed, 19 Aug 2020 19:17:31 -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 1253413515B49 for ; Wed, 19 Aug 2020 19:17:27 -0700 (PDT) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A5BDCA7ED0E18AAC94CE; Thu, 20 Aug 2020 10:17:25 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 10:17:16 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel Subject: [PATCH v3 2/7] libnvdimm: add sanity check for provider_name in of_pmem_region_probe() Date: Thu, 20 Aug 2020 10:16:36 +0800 Message-ID: <20200820021641.3188-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820021641.3188-1-thunder.leizhen@huawei.com> References: <20200820021641.3188-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: TZPOTNF6DNCRJGJJOMO2DL53HCPMFZVE X-Message-ID-Hash: TZPOTNF6DNCRJGJJOMO2DL53HCPMFZVE 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 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: kstrdup() may return NULL because of no memory, check it. Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Zhen Lei --- drivers/nvdimm/of_pmem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 1292ffca7b2ecc0..13c4c274ca6ea88 100644 --- a/drivers/nvdimm/of_pmem.c +++ b/drivers/nvdimm/of_pmem.c @@ -31,6 +31,11 @@ static int of_pmem_region_probe(struct platform_device *pdev) return -ENOMEM; priv->bus_desc.provider_name = kstrdup(pdev->name, GFP_KERNEL); + if (!priv->bus_desc.provider_name) { + kfree(priv); + return -ENOMEM; + } + priv->bus_desc.module = THIS_MODULE; priv->bus_desc.of_node = np; From patchwork Thu Aug 20 02:16:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 11725359 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 13A57618 for ; Thu, 20 Aug 2020 02:17:35 +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 F1118207DA for ; Thu, 20 Aug 2020 02:17:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F1118207DA 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 E460C13515B57; Wed, 19 Aug 2020 19:17:33 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.191; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 15D5913515B4C for ; Wed, 19 Aug 2020 19:17:28 -0700 (PDT) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7CAFCCB9F432A03DC917; Thu, 20 Aug 2020 10:17:25 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 10:17:17 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel Subject: [PATCH v3 3/7] libnvdimm: simplify walk_to_nvdimm_bus() Date: Thu, 20 Aug 2020 10:16:37 +0800 Message-ID: <20200820021641.3188-4-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820021641.3188-1-thunder.leizhen@huawei.com> References: <20200820021641.3188-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: ZD7DWU7JHLCO6WGPKKUPOEUX5BHS7R4X X-Message-ID-Hash: ZD7DWU7JHLCO6WGPKKUPOEUX5BHS7R4X 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 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: Return as soon as nvdimm_bus device has been found, make us no need to check "dev" or "!dev" in subsequent code. No functional change. Signed-off-by: Zhen Lei --- drivers/nvdimm/bus.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c index 955265656b96c73..1d89114cb6ab93e 100644 --- a/drivers/nvdimm/bus.c +++ b/drivers/nvdimm/bus.c @@ -316,10 +316,9 @@ struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev) for (dev = nd_dev; dev; dev = dev->parent) if (is_nvdimm_bus(dev)) - break; - dev_WARN_ONCE(nd_dev, !dev, "invalid dev, not on nd bus\n"); - if (dev) - return to_nvdimm_bus(dev); + return to_nvdimm_bus(dev); + + dev_WARN_ONCE(nd_dev, 1, "invalid dev, not on nd bus\n"); return NULL; } From patchwork Thu Aug 20 02:16:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 11725361 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 43BC5618 for ; Thu, 20 Aug 2020 02:17:36 +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 22D82207DA for ; Thu, 20 Aug 2020 02:17:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22D82207DA 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 0D7D913515B5C; Wed, 19 Aug 2020 19:17:34 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.191; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 1715A13515B4D for ; Wed, 19 Aug 2020 19:17:28 -0700 (PDT) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 755E8A4661290D22C777; Thu, 20 Aug 2020 10:17:25 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 10:17:17 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel Subject: [PATCH v3 4/7] libnvdimm: reduce an unnecessary if branch in nd_region_create() Date: Thu, 20 Aug 2020 10:16:38 +0800 Message-ID: <20200820021641.3188-5-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820021641.3188-1-thunder.leizhen@huawei.com> References: <20200820021641.3188-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: R7OQX67VPHUZFR2EUETX5OJLI5B3EUXY X-Message-ID-Hash: R7OQX67VPHUZFR2EUETX5OJLI5B3EUXY 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 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: if (ndr_desc->flush) 1) nd_region->flush = ndr_desc->flush; else 2) nd_region->flush = NULL; When entering the "else" branch, the value of ndr_desc->flush is NULL. After replaced "NULL" with "ndr_desc->flush" at 2), we will find that it becomes the same to 1). So the above code snippet can be reduced to one statement: nd_region->flush = ndr_desc->flush; No functional change. Signed-off-by: Zhen Lei --- drivers/nvdimm/region_devs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index ef23119db574663..7cf9c7d857909ce 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -1131,10 +1131,7 @@ static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus, nd_region->ndr_size = resource_size(ndr_desc->res); nd_region->ndr_start = ndr_desc->res->start; nd_region->align = default_align(nd_region); - if (ndr_desc->flush) - nd_region->flush = ndr_desc->flush; - else - nd_region->flush = NULL; + nd_region->flush = ndr_desc->flush; nd_device_register(dev); From patchwork Thu Aug 20 02:16:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 11725357 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 BCE9D618 for ; Thu, 20 Aug 2020 02:17:33 +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 94D3822B3F for ; Thu, 20 Aug 2020 02:17:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94D3822B3F 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 B59CC13515B55; Wed, 19 Aug 2020 19:17:32 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.191; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 134E313515B4A for ; Wed, 19 Aug 2020 19:17:28 -0700 (PDT) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 71C0CF8ADFE834B79346; Thu, 20 Aug 2020 10:17:25 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 10:17:18 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel Subject: [PATCH v3 5/7] libnvdimm: reduce an unnecessary if branch in nd_region_activate() Date: Thu, 20 Aug 2020 10:16:39 +0800 Message-ID: <20200820021641.3188-6-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820021641.3188-1-thunder.leizhen@huawei.com> References: <20200820021641.3188-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: XRQEHXQFLTPPUS3ZCEWQ3USO5IRKQOTY X-Message-ID-Hash: XRQEHXQFLTPPUS3ZCEWQ3USO5IRKQOTY 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 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: According to the original code logic: if (!nvdimm->num_flush) { flush_data_size += sizeof(void *); //nvdimm->num_flush is zero now, add 1) have no side effects } else { flush_data_size += sizeof(void *); 1) flush_data_size += nvdimm->num_flush * sizeof(void *); } Obviously, the above code snippet can be reduced to one statement: flush_data_size += (nvdimm->num_flush + 1) * sizeof(void *); No functional change. Signed-off-by: Zhen Lei --- drivers/nvdimm/region_devs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index 7cf9c7d857909ce..49be115c9189eff 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -77,11 +77,8 @@ int nd_region_activate(struct nd_region *nd_region) } /* at least one null hint slot per-dimm for the "no-hint" case */ - flush_data_size += sizeof(void *); + flush_data_size += (nvdimm->num_flush + 1) * sizeof(void *); num_flush = min_not_zero(num_flush, nvdimm->num_flush); - if (!nvdimm->num_flush) - continue; - flush_data_size += nvdimm->num_flush * sizeof(void *); } nvdimm_bus_unlock(&nd_region->dev); From patchwork Thu Aug 20 02:16:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 11725363 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 29484618 for ; Thu, 20 Aug 2020 02:17:37 +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 12A8320825 for ; Thu, 20 Aug 2020 02:17:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12A8320825 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 26E5C13515B5E; Wed, 19 Aug 2020 19:17:35 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.191; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 17ECA13515B4E for ; Wed, 19 Aug 2020 19:17:28 -0700 (PDT) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 78F5EA4A5C7AB868251C; Thu, 20 Aug 2020 10:17:25 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 10:17:18 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel Subject: [PATCH v3 6/7] libnvdimm: make sure EXPORT_SYMBOL_GPL(nvdimm_flush) close to its function Date: Thu, 20 Aug 2020 10:16:40 +0800 Message-ID: <20200820021641.3188-7-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820021641.3188-1-thunder.leizhen@huawei.com> References: <20200820021641.3188-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: LWVPU6N5VFWWVTYZ2VWQ7TMBSSEXY4LB X-Message-ID-Hash: LWVPU6N5VFWWVTYZ2VWQ7TMBSSEXY4LB 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 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: Move EXPORT_SYMBOL_GPL(nvdimm_flush) close to nvdimm_flush(), currently it's near to generic_nvdimm_flush(). Signed-off-by: Zhen Lei Reviewed-by: Pankaj Gupta --- drivers/nvdimm/region_devs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index 49be115c9189eff..909bf03edb132cf 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -1183,6 +1183,8 @@ int nvdimm_flush(struct nd_region *nd_region, struct bio *bio) return rc; } +EXPORT_SYMBOL_GPL(nvdimm_flush); + /** * nvdimm_flush - flush any posted write queues between the cpu and pmem media * @nd_region: blk or interleaved pmem region @@ -1214,7 +1216,6 @@ int generic_nvdimm_flush(struct nd_region *nd_region) return 0; } -EXPORT_SYMBOL_GPL(nvdimm_flush); /** * nvdimm_has_flush - determine write flushing requirements From patchwork Thu Aug 20 02:16:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen (ThunderTown)" X-Patchwork-Id: 11725367 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 AB22E1392 for ; Thu, 20 Aug 2020 02:17:39 +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 93DB52078B for ; Thu, 20 Aug 2020 02:17:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93DB52078B 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 64A9A13515B55; Wed, 19 Aug 2020 19:17:37 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.190; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 84CD713515B4D for ; Wed, 19 Aug 2020 19:17:32 -0700 (PDT) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 970854FFC53A1C5449FA; Thu, 20 Aug 2020 10:17:30 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 10:17:19 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , Markus Elfring , linux-nvdimm , linux-kernel Subject: [PATCH v3 7/7] libnvdimm: slightly simplify available_slots_show() Date: Thu, 20 Aug 2020 10:16:41 +0800 Message-ID: <20200820021641.3188-8-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820021641.3188-1-thunder.leizhen@huawei.com> References: <20200820021641.3188-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: LT44XQR3KW457YXGOYD6D47GGXJEWF2M X-Message-ID-Hash: LT44XQR3KW457YXGOYD6D47GGXJEWF2M 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 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 type of "nfree" is u32, so "nfree - 1" can only be overflowed when "nfree" is zero. Replace "if (nfree - 1 > nfree)" with "if (nfree == 0)" seems more clear. And remove the assignment "nfree = 0", no need for it. Signed-off-by: Zhen Lei --- drivers/nvdimm/dimm_devs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c index 61374def515552f..bf7d0cdc147cb39 100644 --- a/drivers/nvdimm/dimm_devs.c +++ b/drivers/nvdimm/dimm_devs.c @@ -347,10 +347,9 @@ static ssize_t available_slots_show(struct device *dev, nvdimm_bus_lock(dev); nfree = nd_label_nfree(ndd); - if (nfree - 1 > nfree) { + if (nfree == 0) dev_WARN_ONCE(dev, 1, "we ate our last label?\n"); - nfree = 0; - } else + else nfree--; rc = sprintf(buf, "%d\n", nfree); nvdimm_bus_unlock(dev);