diff mbox series

[v3,7/7] libnvdimm: slightly simplify available_slots_show()

Message ID 20200820021641.3188-8-thunder.leizhen@huawei.com (mailing list archive)
State New, archived
Headers show
Series bugfix and optimize for drivers/nvdimm | expand

Commit Message

Zhen Lei Aug. 20, 2020, 2:16 a.m. UTC
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 <thunder.leizhen@huawei.com>
---
 drivers/nvdimm/dimm_devs.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Salih Agenter Aug. 21, 2020, 12:56 p.m. UTC | #1
https://www.agenter.com/how-to-earn
diff mbox series

Patch

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);