Skip to contentSkip to conversation

PCI: endpoint: fix incorrect end of table check in while loop

PATCH In review Colin King 3 participants 4 messages Aug 23, 2017 – Aug 29, 2017

Subsystems (3)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 PCI: endpoint: fix incorrect end of table check in while loop

From: Colin Ian King <[email protected]>

Currently, the while loop will iterate until a matching name is found or until the id pointer wraps around to NULL (the latter is incorrect).

The end of a pci_epf_device_id table is terminated with zero'd entries for name and driver_data, so can change the while loop to iterate while the first character in the name is a non-zero character.

Detected by CoverityScan, CID#1454557 ("Logically dead code")

Fixes 9e9d6eb48623 ("PCI: endpoint: Add an API to get matching "pci_epf_device_id")
---
 drivers/pci/endpoint/pci-epf-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/pci-epf-core.c +1 -1
index ae6fac5995e3..70eccc04ee7f 100644
@@ -273,7 +273,7 @@ pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf)
 	if (!id || !epf)
 		return NULL;
 
-	while (id) {
+	while (*id->name) {
 		if (strcmp(epf->name, id->name) = 0)
 			return id;
 		id++;
Signature · 1 line
2.14.1
#1 lore raw
Quoted 5 lines · Colin King

From: Colin Ian King <[email protected]>

Currently, the while loop will iterate until a matching name is found or until the id pointer wraps around to NULL (the latter is incorrect).

Quoted 8 lines

The end of a pci_epf_device_id table is terminated with zero'd entries for name and driver_data, so can change the while loop to iterate while the first character in the name is a non-zero character.

Detected by CoverityScan, CID#1454557 ("Logically dead code")

Fixes 9e9d6eb48623 ("PCI: endpoint: Add an API to get matching "pci_epf_device_id")

Kishon, do you want to ack this, please?

Quoted 20 lines
---
 drivers/pci/endpoint/pci-epf-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/pci-epf-core.c +1 -1
index ae6fac5995e3..70eccc04ee7f 100644
@@ -273,7 +273,7 @@ pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf)
 	if (!id || !epf)
 		return NULL;
 
-	while (id) {
+	while (*id->name) {
 		if (strcmp(epf->name, id->name) = 0)
 			return id;
 		id++;
Signature · 1 line
2.14.1
#2 lore raw
Quoted 10 lines · Bjorn Helgaas
Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

Currently, the while loop will iterate until a matching name is found or until the id pointer wraps around to NULL (the latter is incorrect).

The end of a pci_epf_device_id table is terminated with zero'd entries for name and driver_data, so can change the while loop to iterate while the first character in the name is a non-zero character.

Quoted 6 lines
Quoted 4 lines

Detected by CoverityScan, CID#1454557 ("Logically dead code")

Fixes 9e9d6eb48623 ("PCI: endpoint: Add an API to get matching "pci_epf_device_id")

Kishon, do you want to ack this, please?

Quoted 21 lines
Quoted 21 lines
---
 drivers/pci/endpoint/pci-epf-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/pci-epf-core.c +1 -1
index ae6fac5995e3..70eccc04ee7f 100644
@@ -273,7 +273,7 @@ pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf)
 	if (!id || !epf)
 		return NULL;
 
-	while (id) {
+	while (*id->name) {
 		if (strcmp(epf->name, id->name) == 0)
 			return id;
 		id++;
Signature · 1 line
2.14.1
#3 lore raw
In reply to Colin King
Quoted 5 lines · Colin King

From: Colin Ian King <[email protected]>

Currently, the while loop will iterate until a matching name is found or until the id pointer wraps around to NULL (the latter is incorrect).

Quoted 8 lines

The end of a pci_epf_device_id table is terminated with zero'd entries for name and driver_data, so can change the while loop to iterate while the first character in the name is a non-zero character.

Detected by CoverityScan, CID#1454557 ("Logically dead code")

Fixes 9e9d6eb48623 ("PCI: endpoint: Add an API to get matching "pci_epf_device_id")

Folded into the original patch, thanks!

Quoted 20 lines
---
 drivers/pci/endpoint/pci-epf-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/endpoint/pci-epf-core.c +1 -1
index ae6fac5995e3..70eccc04ee7f 100644
@@ -273,7 +273,7 @@ pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf)
 	if (!id || !epf)
 		return NULL;
 
-	while (id) {
+	while (*id->name) {
 		if (strcmp(epf->name, id->name) = 0)
 			return id;
 		id++;
Signature · 1 line
2.14.1