Skip to contentSkip to conversation

libnvdimm: remove redundant assignment to pointer 'dev'

PATCH In review Colin King 3 participants 5 messages Feb 5, 2018

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 libnvdimm: remove redundant assignment to pointer 'dev'

From: Colin Ian King <[email protected]>

Pointer dev is being assigned a value that is never read, it is being re-assigned the same value later on, hence the initialization is redundant and can be removed.

Cleans up clang warning:
drivers/nvdimm/pfn_devs.c:307:17: warning: Value stored to 'dev' during its initialization is never read

---
 drivers/nvdimm/pfn_devs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvdimm/pfn_devs.c +1 -1
index f5c4e8c6e29d..2f4d18752c97 100644
@@ -304,7 +304,7 @@ static const struct attribute_group *nd_pfn_attribute_groups[] = {
 struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
 		struct nd_namespace_common *ndns)
 {
-	struct device *dev = &nd_pfn->dev;
+	struct device *dev;
 
 	if (!nd_pfn)
 		return NULL;
Signature · 6 lines
2.15.1

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Colin King

From: Colin Ian King <[email protected]>

Pointer dev is being assigned a value that is never read, it is being re-assigned the same value later on, hence the initialization is redundant and can be removed.

Cleans up clang warning:
drivers/nvdimm/pfn_devs.c:307:17: warning: Value stored to 'dev' during its initialization is never read

More importantly this fixes a potential NULL pointer dereference. nd_pfn is checked for NULL a few lines down, but we would have crashed here trying to get nd_pfn->dev.

We can append the above info to the changelog when we apply.

Quoted 24 lines
---
 drivers/nvdimm/pfn_devs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvdimm/pfn_devs.c +1 -1
index f5c4e8c6e29d..2f4d18752c97 100644
@@ -304,7 +304,7 @@ static const struct attribute_group *nd_pfn_attribute_groups[] = {
 struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn,
 		struct nd_namespace_common *ndns)
 {
-	struct device *dev = &nd_pfn->dev;
+	struct device *dev;
 
 	if (!nd_pfn)
 		return NULL;
Signature · 6 lines
2.15.1

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

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

#2 lore raw
Quoted 11 lines · Ross Zwisler
Quoted 10 lines · Colin King

From: Colin Ian King <[email protected]>

Pointer dev is being assigned a value that is never read, it is being re-assigned the same value later on, hence the initialization is redundant and can be removed.

Cleans up clang warning:
drivers/nvdimm/pfn_devs.c:307:17: warning: Value stored to 'dev' during its initialization is never read

Quoted 8 lines
Quoted 1 line

More importantly this fixes a potential NULL pointer dereference. nd_pfn is checked for NULL a few lines down, but we would have crashed here trying to get nd_pfn->dev.

No we wouldn't crash. We're just calculating the address, not de-referencing a NULL pointer.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

#3 lore raw
Quoted 17 lines · Dan Williams
Quoted 15 lines · Ross Zwisler
Quoted 11 lines · Colin King

From: Colin Ian King <[email protected]>

Pointer dev is being assigned a value that is never read, it is being re-assigned the same value later on, hence the initialization is redundant and can be removed.

Cleans up clang warning:
drivers/nvdimm/pfn_devs.c:307:17: warning: Value stored to 'dev' during its initialization is never read

Quoted 7 lines
Quoted 4 lines

More importantly this fixes a potential NULL pointer dereference. nd_pfn is checked for NULL a few lines down, but we would have crashed here trying to get nd_pfn->dev.

No we wouldn't crash. We're just calculating the address, not de-referencing a NULL pointer.

Indeed, it's just a warning clean up. Nothing more.

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

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

#4 lore raw
In reply to Dan Williams
Quoted 17 lines · Dan Williams
Quoted 15 lines · Ross Zwisler
Quoted 11 lines · Colin King

From: Colin Ian King <[email protected]>

Pointer dev is being assigned a value that is never read, it is being re-assigned the same value later on, hence the initialization is redundant and can be removed.

Cleans up clang warning:
drivers/nvdimm/pfn_devs.c:307:17: warning: Value stored to 'dev' during its initialization is never read

Quoted 7 lines
Quoted 4 lines

More importantly this fixes a potential NULL pointer dereference. nd_pfn is checked for NULL a few lines down, but we would have crashed here trying to get nd_pfn->dev.

No we wouldn't crash. We're just calculating the address, not de-referencing a NULL pointer.

Ah, yep, you're right of course. This is exactly how offsetof() is implemented in some architectures. Thanks.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm