Skip to contentSkip to conversation

libnvdimm: normalize dev_debug failed and succeeded wording

PATCH In review Robert Elliott 2 participants 4 messages Jan 22, 2019 libnvdimm: non-volatile memory device

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libnvdimm: normalize dev_debug failed and succeeded wording

Make dev_dbg prints use consistent wording for failed and succeeded, and include the return code when reporting something failed.

---
 drivers/nvdimm/dimm.c     |  2 +-
 drivers/nvdimm/label.c    |  7 ++++---
 drivers/nvdimm/security.c | 53 ++++++++++++++++++++++++++++++++++-------------
 3 files changed, 44 insertions(+), 18 deletions(-)
drivers/nvdimm/dimm.c +1 -1
index 0cf58cabc9ed..3ff104f7ccaa 100644
@@ -62,7 +62,7 @@ static int nvdimm_probe(struct device *dev)
 	 */
 	rc = nvdimm_security_unlock(dev);
 	if (rc < 0)
-		dev_dbg(dev, "failed to unlock dimm: %d\n", rc);
+		dev_dbg(dev, "unlock failed: %d\n", rc);
 
 
 	/*
drivers/nvdimm/label.c +4 -3
index a11bf4e6b451..235833a4881b 100644
@@ -149,7 +149,7 @@ static int __nd_label_validate(struct nvdimm_drvdata *ndd)
 			labelsize = 128;
 
 		if (labelsize != sizeof_namespace_label(ndd)) {
-			dev_dbg(dev, "nsindex%d labelsize %d invalid\n",
+			dev_dbg(dev, "nsindex%d labelsize: %d invalid\n",
 					i, nsindex[i]->labelsize);
 			continue;
 		}
@@ -373,7 +373,8 @@ static bool slot_valid(struct nvdimm_drvdata *ndd,
 		sum = nd_fletcher64(nd_label, sizeof_namespace_label(ndd), 1);
 		nd_label->checksum = __cpu_to_le64(sum_save);
 		if (sum != sum_save) {
-			dev_dbg(ndd->dev, "fail checksum. slot: %d expect: %#llx\n",
+			dev_dbg(ndd->dev,
+				"checksum failed. slot: %d expected: %#llx\n",
 				slot, sum);
 			return false;
 		}
@@ -535,7 +536,7 @@ int nd_label_data_init(struct nvdimm_drvdata *ndd)
 		read_size += label_read_size;
 	}
 
-	dev_dbg(ndd->dev, "len: %zu rc: %d\n", offset, rc);
+	dev_dbg(ndd->dev, "init config data area len: %zu succeeded\n", offset);
 out_err:
 	return rc;
 }
drivers/nvdimm/security.c +39 -14

111 lines not on this page · raw message

Signature · 6 lines
2.16.3

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

Looks ok, just some formatting nits...

Quoted 10 lines · Robert Elliott

Make dev_dbg prints use consistent wording for failed and succeeded, and include the return code when reporting something failed.

---
 drivers/nvdimm/dimm.c     |  2 +-
 drivers/nvdimm/label.c    |  7 ++++---
 drivers/nvdimm/security.c | 53 ++++++++++++++++++++++++++++++++++-------------
 3 files changed, 44 insertions(+), 18 deletions(-)

This insertions > 2x deletions is concerning, some suggestions below.

Quoted 28 lines
drivers/nvdimm/dimm.c +1 -1
index 0cf58cabc9ed..3ff104f7ccaa 100644
@@ -62,7 +62,7 @@ static int nvdimm_probe(struct device *dev)
         */
        rc = nvdimm_security_unlock(dev);
        if (rc < 0)
-               dev_dbg(dev, "failed to unlock dimm: %d\n", rc);
+               dev_dbg(dev, "unlock failed: %d\n", rc);
 
 
        /*
drivers/nvdimm/label.c +1 -1
index a11bf4e6b451..235833a4881b 100644
@@ -149,7 +149,7 @@ static int __nd_label_validate(struct nvdimm_drvdata *ndd)
                        labelsize = 128;
 
                if (labelsize != sizeof_namespace_label(ndd)) {
-                       dev_dbg(dev, "nsindex%d labelsize %d invalid\n",
+                       dev_dbg(dev, "nsindex%d labelsize: %d invalid\n",
                                        i, nsindex[i]->labelsize);
                        continue;
                }

drivers/nvdimm/label.c static bool slot_valid(struct nvdimm_drvdata *ndd, · line 377

Quoted 6 lines
drivers/nvdimm/label.c +2 -1
@@ -373,7 +373,8 @@ static bool slot_valid(struct nvdimm_drvdata *ndd,
                sum = nd_fletcher64(nd_label, sizeof_namespace_label(ndd), 1);
                nd_label->checksum = __cpu_to_le64(sum_save);
                if (sum != sum_save) {
-                       dev_dbg(ndd->dev, "fail checksum. slot: %d expect: %#llx\n",
+                       dev_dbg(ndd->dev,
+                               "checksum failed. slot: %d expected: %#llx\n",

It's ok to keep the format string on the same line as dev_dbg(), even if it violates 80 columns. In general it helps grep'ability if the format string is on the same line as print call.

Quoted 35 lines
drivers/nvdimm/label.c +1 -1
                                slot, sum);
                        return false;
                }
@@ -535,7 +536,7 @@ int nd_label_data_init(struct nvdimm_drvdata *ndd)
                read_size += label_read_size;
        }
 
-       dev_dbg(ndd->dev, "len: %zu rc: %d\n", offset, rc);
+       dev_dbg(ndd->dev, "init config data area len: %zu succeeded\n", offset);
 out_err:
        return rc;
 }
drivers/nvdimm/security.c +3 -1
index f8bb746a549f..b7f86846015a 100644
@@ -58,7 +58,8 @@ static struct key *nvdimm_request_key(struct nvdimm *nvdimm)
                if (PTR_ERR(key) == -ENOKEY)
                        dev_dbg(dev, "request_key() found no key\n");
                else
-                       dev_dbg(dev, "request_key() upcall failed\n");
+                       dev_dbg(dev, "request_key() upcall failed: %ld\n",
+                               PTR_ERR(key));
                key = NULL;
        } else {
                struct encrypted_key_payload *epayload;
@@ -107,6 +108,7 @@ static struct key *nvdimm_lookup_user_key(struct nvdimm *nvdimm,
 
 static struct key *nvdimm_key_revalidate(struct nvdimm *nvdimm)
 {
+       struct device *dev = &nvdimm->dev;
        struct key *key;
        int rc;
 

drivers/nvdimm/security.c static struct key *nvdimm_key_revalidate(struct nvdimm *nvdimm) · line 135

Quoted 9 lines
drivers/nvdimm/security.c +5 -1
@@ -126,7 +128,11 @@ static struct key *nvdimm_key_revalidate(struct nvdimm *nvdimm)
        if (rc < 0) {
                nvdimm_put_key(key);
                key = NULL;
-       }
+               dev_dbg(dev, "key: %d revalidation failed: %d\n",
+                       key_serial(key), rc);
+       } else
+               dev_dbg(dev, "key: %d revalidation succeeded\n",
+                       key_serial(key));

For all of these success vs fail cases I would prefer to continue to use a ternary:

    dev_dbg(dev, "key: %d revalidation %s: %d\n",
        key_serial(key), rc == 0 ? "succeeded" : "failed", rc);

...as to not clutter the code with extra debug statements.
_______________________________________________
Linux-nvdimm mailing list [email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#2 lore raw
Quoted 23 lines

-----Original Message-----
From: Dan Williams [mailto:[email protected]]
Sent: Tuesday, January 22, 2019 4:24 PM
To: Elliott, Robert (Persistent Memory) <[email protected]>
Cc: linux-nvdimm <[email protected]>
Subject: Re: [PATCH] libnvdimm: normalize dev_debug failed and succeeded wording

Looks ok, just some formatting nits...

drivers/nvdimm/security.c static struct key *nvdimm_key_revalidate(struct nvdimm *nvdimm) · line 135

Quoted 10 lines · Robert Elliott
        if (rc < 0) {
                nvdimm_put_key(key);
                key = NULL;
drivers/nvdimm/security.c +5 -1
-       }
+               dev_dbg(dev, "key: %d revalidation failed: %d\n",
+                       key_serial(key), rc);
+       } else
+               dev_dbg(dev, "key: %d revalidation succeeded\n",
+                       key_serial(key));
Quoted 7 lines

For all of these success vs fail cases I would prefer to continue to use a ternary:

    dev_dbg(dev, "key: %d revalidation %s: %d\n",
        key_serial(key), rc == 0 ? "succeeded" : "failed", rc);

...as to not clutter the code with extra debug statements.

That'll result in printing the return code for successful cases:

    ...succeeded: 0

I guess that's fine for the dev_dbg level.

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

#3 lore raw
Quoted 30 lines · Robert (Persistent Memory)
Quoted 30 lines

-----Original Message-----
From: Dan Williams [mailto:[email protected]]
Sent: Tuesday, January 22, 2019 4:24 PM
To: Elliott, Robert (Persistent Memory) <[email protected]>
Cc: linux-nvdimm <[email protected]>
Subject: Re: [PATCH] libnvdimm: normalize dev_debug failed and succeeded wording

Looks ok, just some formatting nits...

drivers/nvdimm/security.c static struct key *nvdimm_key_revalidate(struct nvdimm *nvdimm) · line 135

Quoted 10 lines · Robert Elliott
        if (rc < 0) {
                nvdimm_put_key(key);
                key = NULL;
drivers/nvdimm/security.c +5 -1
-       }
+               dev_dbg(dev, "key: %d revalidation failed: %d\n",
+                       key_serial(key), rc);
+       } else
+               dev_dbg(dev, "key: %d revalidation succeeded\n",
+                       key_serial(key));

For all of these success vs fail cases I would prefer to continue to use a ternary:

    dev_dbg(dev, "key: %d revalidation %s: %d\n",
        key_serial(key), rc == 0 ? "succeeded" : "failed", rc);
Quoted 6 lines
Quoted 1 line

...as to not clutter the code with extra debug statements.

That'll result in printing the return code for successful cases:

    ...succeeded: 0

I guess that's fine for the dev_dbg level.

Yeah, I'm ok with that price for slightly more compact code.
_______________________________________________
Linux-nvdimm mailing list [email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm