[PATCH 3/3] libnvdimm/bus: simplify walk_to_nvdimm_bus()

From: Zhen Lei
Date: Mon Aug 17 2020 - 23:16:57 EST


I first want to move dev_WARN_ONCE() after "if (dev)" branch, but further
I find the "if (dev)" can only be true when is_nvdimm_bus(dev) successed.

No functional change. In fact, the compiler can optimize it correctly. I
run "size drivers/nvdimm/bus.o" and find nothing has changed. So it's
just source code level optimization, make us can read it faster.

Signed-off-by: Zhen Lei <thunder.leizhen@xxxxxxxxxx>
---
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;
}

--
1.8.3