Skip to contentSkip to conversation

tools/testing/nvdimm: fix return value check

PATCH New Yang Yingliang 1 participant 3 messages Nov 25, 2022 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

cover tools/testing/nvdimm: fix return value check

This patchset fixes two return value check problems when device_create_with_groups fails.

Yang Yingliang (2):
nfit_test: fix return value check in nfit_test_dimm_init()
ndtest: fix return value check in ndtest_dimm_register()

 tools/testing/nvdimm/test/ndtest.c | 4 ++--
 tools/testing/nvdimm/test/nfit.c   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 nfit_test: fix return value check in nfit_test_dimm_init()

If device_create_with_groups() fails, it returns ERR_PTR() and never return NULL, so replace NULL pointer check with IS_ERR() to fix this problem.

Fixes 231bf117aada ("tools/testing/nvdimm: unit test for acpi_nvdimm_notify()")
---
 tools/testing/nvdimm/test/nfit.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/nvdimm/test/nfit.c +2 -2
index c75abb497a1a..220315091143 100644
@@ -1833,10 +1833,10 @@ static int nfit_test_dimm_init(struct nfit_test *t)
 		t->dimm_dev[i] = device_create_with_groups(nfit_test_dimm,
 				&t->pdev.dev, 0, NULL,
 				nfit_test_dimm_attribute_groups,
 				"test_dimm%d", i + t->dcr_idx);
-		if (!t->dimm_dev[i])
-			return -ENOMEM;
+		if (IS_ERR(t->dimm_dev[i]))
+			return PTR_ERR(t->dimm_dev[i]);
 	}
 	return 0;
 }
 
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 ndtest: fix return value check in ndtest_dimm_register()

In reply to Yang Yingliang

If device_create_with_groups() fails, it returns ERR_PTR() and never return NULL, so replace NULL pointer check with IS_ERR() to fix this problem.

Fixes 9399ab61ad82 ("ndtest: Add dimms to the two buses")
---
 tools/testing/nvdimm/test/ndtest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/nvdimm/test/ndtest.c +2 -2
index 01ceb98c15a0..42954a6d0929 100644
@@ -740,11 +740,11 @@ static int ndtest_dimm_register(struct ndtest_priv *priv,
 	dimm->dev = device_create_with_groups(ndtest_dimm_class,
 					     &priv->pdev.dev,
 					     0, dimm, dimm_attribute_groups,
 					     "test_dimm%d", id);
-	if (!dimm->dev) {
+	if (IS_ERR(dimm->dev)) {
 		pr_err("Could not create dimm device attributes\n");
-		return -ENOMEM;
+		return PTR_ERR(dimm->dev);
 	}
 
 	return 0;
 }
Signature · 1 line
2.25.1