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 05919C43464 for ; Sat, 19 Sep 2020 11:12:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9DC821481 for ; Sat, 19 Sep 2020 11:12:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726247AbgISLMy (ORCPT ); Sat, 19 Sep 2020 07:12:54 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:47032 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726041AbgISLMy (ORCPT ); Sat, 19 Sep 2020 07:12:54 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 47FCEF26C25183634819; Sat, 19 Sep 2020 19:12:52 +0800 (CST) Received: from thunder-town.china.huawei.com (10.174.177.253) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Sat, 19 Sep 2020 19:12:43 +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: slightly simplify available_slots_show() Date: Sat, 19 Sep 2020 19:11:12 +0800 Message-ID: <20200919111112.4074-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 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 --- v1 --> v2: No change, just sent separately v1: https://lkml.org/lkml/2020/8/19/1465 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 b59032e0859b7f3..d6835f127d83055 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); -- 1.8.3