Skip to contentSkip to conversation

spi: core: invert success test in devm_spi_register_master

PATCH In review Stephen Warren 2 participants 2 messages Nov 21, 2013 – Nov 22, 2013 1 message not in the archive SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: core: invert success test in devm_spi_register_master

From: Stephen Warren <[email protected]>

devres_add() should be called when the action to be undone succeeded, not when it failed. Fix the inverted test in devm_spi_register_master() which was doing the opposite.

The user-visible issue without this fix is:
insmod spi-tegra114.ko
Assume there's an MTD device on that SPI bus, which creates /dev/mtd0.
rmmod spi-tegra114
Doesn't remove devices on the SPI bus.
insmod spi-tegra114.ko
Creates a duplicate SPI device which creates /dev/mtd1.
hexdump -C /dev/mtd0
That's the old device, which uses an SPI bus hosted by a non-existent module, which causes the oops below.

Unable to handle kernel paging request at virtual address bf0017c0
pgd = c0004000
[bf0017c0] *pgd=ad51b811, *pte=00000000, *ppte=00000000
Internal error: Oops: 80000007 [#1] PREEMPT SMP ARM
...
PC is at 0xbf0017c0
LR is at spi_pump_messages+0x15c/0x204
pc : [<bf0017c0>] lr : [<c02f0af8>] psr: 60000113

...

Fixes 666d5b4c742b ("spi: core: Add devm_spi_register_master()")
---
 drivers/spi/spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi.c +1 -1
index e29d73d759ce..678af42a1a41 100644
@@ -1404,7 +1404,7 @@ int devm_spi_register_master(struct device *dev, struct spi_master *master)
 		return -ENOMEM;
 
 	ret = spi_register_master(master);
-	if (ret != 0) {
+	if (!ret) {
 		*ptr = master;
 		devres_add(dev, ptr);
 	} else {
Signature · 6 lines
1.8.1.5

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

A message that is not in the archive (sent off-list or not yet received): 1385075475-25441-1-git-send-email-swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org

#2 lore raw
Quoted 5 lines · Stephen Warren

From: Stephen Warren <[email protected]>

devres_add() should be called when the action to be undone succeeded, not when it failed. Fix the inverted test in devm_spi_register_master() which was doing the opposite.

Oh, my. That's embarrassing. Applied, thanks.