Skip to content

Commit 00b43f8

Browse files
committed
Merge tag 'libnvdimm-for-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm
Pull libnvdimm updates from Ira Weiny: - use Open Firmware helper routines - fix memory leak when nvdimm labels are incorrect - remove some dead code * tag 'libnvdimm-for-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm: nvdimm: Remove dead code for ENODEV checking in scan_labels() nvdimm: Fix devs leaks in scan_labels() nvdimm: Use of_property_present() and of_property_read_bool()
2 parents 20d9ba7 + 447b167 commit 00b43f8

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

drivers/nvdimm/namespace_devs.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,9 +1612,6 @@ static int select_pmem_id(struct nd_region *nd_region, const uuid_t *pmem_id)
16121612
{
16131613
int i;
16141614

1615-
if (!pmem_id)
1616-
return -ENODEV;
1617-
16181615
for (i = 0; i < nd_region->ndr_mappings; i++) {
16191616
struct nd_mapping *nd_mapping = &nd_region->mapping[i];
16201617
struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
@@ -1790,9 +1787,6 @@ static struct device *create_namespace_pmem(struct nd_region *nd_region,
17901787
case -EINVAL:
17911788
dev_dbg(&nd_region->dev, "invalid label(s)\n");
17921789
break;
1793-
case -ENODEV:
1794-
dev_dbg(&nd_region->dev, "label not found\n");
1795-
break;
17961790
default:
17971791
dev_dbg(&nd_region->dev, "unexpected err: %d\n", rc);
17981792
break;
@@ -1937,12 +1931,16 @@ static int cmp_dpa(const void *a, const void *b)
19371931
static struct device **scan_labels(struct nd_region *nd_region)
19381932
{
19391933
int i, count = 0;
1940-
struct device *dev, **devs = NULL;
1934+
struct device *dev, **devs;
19411935
struct nd_label_ent *label_ent, *e;
19421936
struct nd_mapping *nd_mapping = &nd_region->mapping[0];
19431937
struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
19441938
resource_size_t map_end = nd_mapping->start + nd_mapping->size - 1;
19451939

1940+
devs = kcalloc(2, sizeof(dev), GFP_KERNEL);
1941+
if (!devs)
1942+
return NULL;
1943+
19461944
/* "safe" because create_namespace_pmem() might list_move() label_ent */
19471945
list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list) {
19481946
struct nd_namespace_label *nd_label = label_ent->label;
@@ -1961,22 +1959,21 @@ static struct device **scan_labels(struct nd_region *nd_region)
19611959
goto err;
19621960
if (i < count)
19631961
continue;
1964-
__devs = kcalloc(count + 2, sizeof(dev), GFP_KERNEL);
1965-
if (!__devs)
1966-
goto err;
1967-
memcpy(__devs, devs, sizeof(dev) * count);
1968-
kfree(devs);
1969-
devs = __devs;
1962+
if (count) {
1963+
__devs = kcalloc(count + 2, sizeof(dev), GFP_KERNEL);
1964+
if (!__devs)
1965+
goto err;
1966+
memcpy(__devs, devs, sizeof(dev) * count);
1967+
kfree(devs);
1968+
devs = __devs;
1969+
}
19701970

19711971
dev = create_namespace_pmem(nd_region, nd_mapping, nd_label);
19721972
if (IS_ERR(dev)) {
19731973
switch (PTR_ERR(dev)) {
19741974
case -EAGAIN:
19751975
/* skip invalid labels */
19761976
continue;
1977-
case -ENODEV:
1978-
/* fallthrough to seed creation */
1979-
break;
19801977
default:
19811978
goto err;
19821979
}
@@ -1993,11 +1990,6 @@ static struct device **scan_labels(struct nd_region *nd_region)
19931990

19941991
/* Publish a zero-sized namespace for userspace to configure. */
19951992
nd_mapping_free_labels(nd_mapping);
1996-
1997-
devs = kcalloc(2, sizeof(dev), GFP_KERNEL);
1998-
if (!devs)
1999-
goto err;
2000-
20011993
nspm = kzalloc(sizeof(*nspm), GFP_KERNEL);
20021994
if (!nspm)
20031995
goto err;
@@ -2036,11 +2028,10 @@ static struct device **scan_labels(struct nd_region *nd_region)
20362028
return devs;
20372029

20382030
err:
2039-
if (devs) {
2040-
for (i = 0; devs[i]; i++)
2041-
namespace_pmem_release(devs[i]);
2042-
kfree(devs);
2043-
}
2031+
for (i = 0; devs[i]; i++)
2032+
namespace_pmem_release(devs[i]);
2033+
kfree(devs);
2034+
20442035
return NULL;
20452036
}
20462037

drivers/nvdimm/of_pmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int of_pmem_region_probe(struct platform_device *pdev)
4747
}
4848
platform_set_drvdata(pdev, priv);
4949

50-
is_volatile = !!of_find_property(np, "volatile", NULL);
50+
is_volatile = of_property_read_bool(np, "volatile");
5151
dev_dbg(&pdev->dev, "Registering %s regions from %pOF\n",
5252
is_volatile ? "volatile" : "non-volatile", np);
5353

drivers/nvmem/layouts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static int nvmem_layout_bus_populate(struct nvmem_device *nvmem,
123123
int ret;
124124

125125
/* Make sure it has a compatible property */
126-
if (!of_get_property(layout_dn, "compatible", NULL)) {
126+
if (!of_property_present(layout_dn, "compatible")) {
127127
pr_debug("%s() - skipping %pOF, no compatible prop\n",
128128
__func__, layout_dn);
129129
return 0;

0 commit comments

Comments
 (0)