Skip to contentSkip to conversation

spi: fix erroneous logic inversion in spi_match_id() usage

PATCH In review Heiner Kallweit 3 participants 5 messages Nov 30, 2021 – Dec 1, 2021 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: fix erroneous logic inversion in spi_match_id() usage

We want to continue in case of a match. Fix the erroneously inverted logic.

Fixes 3f07657506df ("spi: deduplicate spi_match_id() in __spi_register_driver()")
---
 drivers/spi/spi.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/spi/spi.c +1 -4
index 5bf680fcb..4578c2fb5 100644
@@ -471,10 +471,7 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv)
 				of_name = of_id->compatible;
 
 			if (sdrv->id_table) {
-				const struct spi_device_id *spi_id;
-
-				spi_id = spi_match_id(sdrv->id_table, of_name);
-				if (!spi_id)
+				if (spi_match_id(sdrv->id_table, of_name))
 					continue;
 			} else {
 				if (strcmp(sdrv->driver.name, of_name) == 0)
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 2 lines · Heiner Kallweit

We want to continue in case of a match. Fix the erroneously inverted logic.

We do? Why? I can't tell from this changelog what the problem is or why the patch would fix it.

drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 477

Quoted 12 lines
drivers/spi/spi.c +1 -4
@@ -471,10 +471,7 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv)
 				of_name = of_id->compatible;
 
 			if (sdrv->id_table) {
-				const struct spi_device_id *spi_id;
-
-				spi_id = spi_match_id(sdrv->id_table, of_name);
-				if (!spi_id)
+				if (spi_match_id(sdrv->id_table, of_name))
 					continue;
 			} else {
 				if (strcmp(sdrv->driver.name, of_name) == 0)

This appears to correspond to the current code anyway?

#2 lore raw
Quoted 8 lines · Mark Brown
Quoted 2 lines · Heiner Kallweit

We want to continue in case of a match. Fix the erroneously inverted logic.

We do? Why? I can't tell from this changelog what the problem is or why the patch would fix it.

That's the relevant part of 3f07657506df. Before this change we hit the continue path if spi_id->name[0] != NULL, means if a match was found. spi_match_id() returns NULL if no match was found. The commit message of 3f07657506df doesn't mention an intention to change the logic.

@@ -474,12 +473,8 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv)
if (sdrv->id_table) {
const struct spi_device_id *spi_id;

- for (spi_id = sdrv->id_table; spi_id->name[0];
- spi_id++)
- if (strcmp(spi_id->name, of_name) == 0)
- break;
-
- if (spi_id->name[0])
+ spi_id = spi_match_id(sdrv->id_table, of_name);
+ if (!spi_id)
continue;
} else {

Quoted 15 lines

drivers/spi/spi.c int __spi_register_driver(struct module *owner, struct spi_driver *sdrv) · line 477

Quoted 12 lines
drivers/spi/spi.c +1 -4
@@ -471,10 +471,7 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv)
 				of_name = of_id->compatible;
 
 			if (sdrv->id_table) {
-				const struct spi_device_id *spi_id;
-
-				spi_id = spi_match_id(sdrv->id_table, of_name);
-				if (!spi_id)
+				if (spi_match_id(sdrv->id_table, of_name))
 					continue;
 			} else {
 				if (strcmp(sdrv->driver.name, of_name) == 0)

This appears to correspond to the current code anyway?

No. Now we (again) continue if spi_match_id() != NULL.

#3 lore raw
Quoted 8 lines · Heiner Kallweit
Quoted 7 lines · Mark Brown
Quoted 2 lines · Heiner Kallweit

We want to continue in case of a match. Fix the erroneously inverted logic.

We do? Why? I can't tell from this changelog what the problem is or why the patch would fix it.

Isn't it fixed by b79332ef9d61 ("spi: Fix condition in the __spi_register_driver()")?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Heiner Kallweit
Quoted 2 lines · Mark Brown

On Tue, Nov 30, 2021 at 09:13:35PM +0100, Heiner Kallweit wrote:

Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

We want to continue in case of a match. Fix the erroneously inverted logic.

We do? Why? I can't tell from this changelog what the problem is or why the patch would fix it.

Isn't it fixed by b79332ef9d61 ("spi: Fix condition in the __spi_register_driver()")?

Indeed, it has been fixed with this commit. I was using linux-next from Nov 24th that included the first change but not yet the fix. Sorry for the noise.