* [PATCH 0/3] bugfix and optimize for drivers/nvdimm
@ 2020-08-18 3:15 Zhen Lei
2020-08-18 3:15 ` [PATCH 1/3] libnvdimm: fix memleak in of_pmem.c Zhen Lei
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Zhen Lei @ 2020-08-18 3:15 UTC (permalink / raw)
To: Oliver O'Halloran, Dan Williams, Vishal Verma, Dave Jiang,
Ira Weiny, linux-nvdimm, linux-kernel
Cc: Zhen Lei
I found a memleak when I learned the drivers/nvdimm code today. And I also
added a sanity check for priv->bus_desc.provider_name, because strdup()
maybe failed. Patch 3 is a trivial source code optimization.
Zhen Lei (3):
libnvdimm: fix memleak in of_pmem.c
libnvdimm: add sanity check for provider_name in
of_pmem_region_probe()
libnvdimm/bus: simplify walk_to_nvdimm_bus()
drivers/nvdimm/bus.c | 7 +++----
drivers/nvdimm/of_pmem.c | 7 +++++++
2 files changed, 10 insertions(+), 4 deletions(-)
--
1.8.3
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] libnvdimm: fix memleak in of_pmem.c
2020-08-18 3:15 [PATCH 0/3] bugfix and optimize for drivers/nvdimm Zhen Lei
@ 2020-08-18 3:15 ` Zhen Lei
2020-08-18 3:15 ` [PATCH 2/3] libnvdimm: add sanity check for provider_name in of_pmem_region_probe() Zhen Lei
2020-08-18 3:15 ` [PATCH 3/3] libnvdimm/bus: simplify walk_to_nvdimm_bus() Zhen Lei
2 siblings, 0 replies; 4+ messages in thread
From: Zhen Lei @ 2020-08-18 3:15 UTC (permalink / raw)
To: Oliver O'Halloran, Dan Williams, Vishal Verma, Dave Jiang,
Ira Weiny, linux-nvdimm, linux-kernel
Cc: Zhen Lei
The memory priv->bus_desc.provider_name allocated by kstrdup() should be
freed.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
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;
--
1.8.3
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] libnvdimm: add sanity check for provider_name in of_pmem_region_probe()
2020-08-18 3:15 [PATCH 0/3] bugfix and optimize for drivers/nvdimm Zhen Lei
2020-08-18 3:15 ` [PATCH 1/3] libnvdimm: fix memleak in of_pmem.c Zhen Lei
@ 2020-08-18 3:15 ` Zhen Lei
2020-08-18 3:15 ` [PATCH 3/3] libnvdimm/bus: simplify walk_to_nvdimm_bus() Zhen Lei
2 siblings, 0 replies; 4+ messages in thread
From: Zhen Lei @ 2020-08-18 3:15 UTC (permalink / raw)
To: Oliver O'Halloran, Dan Williams, Vishal Verma, Dave Jiang,
Ira Weiny, linux-nvdimm, linux-kernel
Cc: Zhen Lei
kstrdup() may return NULL because of no memory, check it.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
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;
--
1.8.3
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] libnvdimm/bus: simplify walk_to_nvdimm_bus()
2020-08-18 3:15 [PATCH 0/3] bugfix and optimize for drivers/nvdimm Zhen Lei
2020-08-18 3:15 ` [PATCH 1/3] libnvdimm: fix memleak in of_pmem.c Zhen Lei
2020-08-18 3:15 ` [PATCH 2/3] libnvdimm: add sanity check for provider_name in of_pmem_region_probe() Zhen Lei
@ 2020-08-18 3:15 ` Zhen Lei
2 siblings, 0 replies; 4+ messages in thread
From: Zhen Lei @ 2020-08-18 3:15 UTC (permalink / raw)
To: Oliver O'Halloran, Dan Williams, Vishal Verma, Dave Jiang,
Ira Weiny, linux-nvdimm, linux-kernel
Cc: Zhen Lei
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@huawei.com>
---
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
_______________________________________________
Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-leave@lists.01.org
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-18 3:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-18 3:15 [PATCH 0/3] bugfix and optimize for drivers/nvdimm Zhen Lei
2020-08-18 3:15 ` [PATCH 1/3] libnvdimm: fix memleak in of_pmem.c Zhen Lei
2020-08-18 3:15 ` [PATCH 2/3] libnvdimm: add sanity check for provider_name in of_pmem_region_probe() Zhen Lei
2020-08-18 3:15 ` [PATCH 3/3] libnvdimm/bus: simplify walk_to_nvdimm_bus() Zhen Lei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).