Skip to contentSkip to conversation

libnvdimm/namsepace: Don't set claim_class on error

PATCH In review [email protected] 2 participants 3 messages Sep 25, 2019 – Sep 26, 2019 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 libnvdimm/namsepace: Don't set claim_class on error

From: Ira Weiny <[email protected]>

Don't leave claim_class set to an invalid value if an error occurs in btt_claim_class().

While we are here change the return type of __holder_class_store() to be clear about the values it is returning.

This was found via code inspection.

---
V1->V2
Add space after variable declaration...

V2->V3
Fix oneliner
Rebase without Dan Carpenter's patch and give him Reported-by
credit

 drivers/nvdimm/namespace_devs.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/nvdimm/namespace_devs.c +10 -10
index a16e52251a30..eef885c59f47 100644
@@ -1510,16 +1510,20 @@ static ssize_t holder_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(holder);
 
-static ssize_t __holder_class_store(struct device *dev, const char *buf)
+static int __holder_class_store(struct device *dev, const char *buf)
 {
 	struct nd_namespace_common *ndns = to_ndns(dev);
 
 	if (dev->driver || ndns->claim)
 		return -EBUSY;
 
-	if (sysfs_streq(buf, "btt"))
-		ndns->claim_class = btt_claim_class(dev);
-	else if (sysfs_streq(buf, "pfn"))
+	if (sysfs_streq(buf, "btt")) {
+		int rc = btt_claim_class(dev);
+
+		if (rc < NVDIMM_CCLASS_NONE)
+			return rc;
+		ndns->claim_class = rc;
+	} else if (sysfs_streq(buf, "pfn"))
 		ndns->claim_class = NVDIMM_CCLASS_PFN;
 	else if (sysfs_streq(buf, "dax"))
 		ndns->claim_class = NVDIMM_CCLASS_DAX;
@@ -1528,10 +1532,6 @@ static ssize_t __holder_class_store(struct device *dev, const char *buf)
 	else
 		return -EINVAL;
 
-	/* btt_claim_class() could've returned an error */
-	if (ndns->claim_class < 0)
-		return ndns->claim_class;
-
 	return 0;
 }
 
@@ -1539,7 +1539,7 @@ static ssize_t holder_class_store(struct device *dev,
 		struct device_attribute *attr, const char *buf, size_t len)
 {
 	struct nd_region *nd_region = to_nd_region(dev->parent);
-	ssize_t rc;
+	int rc;
 
 	nd_device_lock(dev);
 	nvdimm_bus_lock(dev);
@@ -1547,7 +1547,7 @@ static ssize_t holder_class_store(struct device *dev,
 	rc = __holder_class_store(dev, buf);
 	if (rc >= 0)
 		rc = nd_namespace_label_update(nd_region, dev);
-	dev_dbg(dev, "%s(%zd)\n", rc < 0 ? "fail " : "", rc);
+	dev_dbg(dev, "%s(%d)\n", rc < 0 ? "fail " : "", rc);
 	nvdimm_bus_unlock(dev);
 	nd_device_unlock(dev);
 
Signature · 6 lines
2.20.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#1 lore raw
Quoted 14 lines · On Wed, Sep 25, 2019 at 02:13:48PM -0700, [email protected] wrote:

From: Ira Weiny <[email protected]>

Don't leave claim_class set to an invalid value if an error occurs in btt_claim_class().

While we are here change the return type of __holder_class_store() to be clear about the values it is returning.

This was found via code inspection.

Quoted 8 lines

---
V1->V2
Add space after variable declaration...

V2->V3
Fix oneliner
Rebase without Dan Carpenter's patch and give him Reported-by
credit

Thanks! Btw, if it's ever a question of "do you want to redo a patch or just transfer to reported by credit?" then always I always want the #2 option. It would have taken me several iterations to generate the patch you wanted.

regards,
dan carpenter

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#2 lore raw
Quoted 24 lines · Dan Carpenter
Quoted 14 lines · On Wed, Sep 25, 2019 at 02:13:48PM -0700, [email protected] wrote:

From: Ira Weiny <[email protected]>

Don't leave claim_class set to an invalid value if an error occurs in btt_claim_class().

While we are here change the return type of __holder_class_store() to be clear about the values it is returning.

This was found via code inspection.

Quoted 8 lines

---
V1->V2
Add space after variable declaration...

V2->V3
Fix oneliner
Rebase without Dan Carpenter's patch and give him Reported-by
credit

Quoted 4 lines

Thanks! Btw, if it's ever a question of "do you want to redo a patch or just transfer to reported by credit?" then always I always want the #2 option. It would have taken me several iterations to generate the patch you wanted.

Thanks for letting me know!

And thanks for finding this as well. :-D

Ira

Quoted 4 lines

regards,
dan carpenter

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm