Skip to contentSkip to conversation

macintosh: therm_windtunnel: Fix i2c adapter reference leak in probe

PATCH In review Yige Jiang 2 participants 2 messages Nov 25

Subsystems (3)
lore
Share & tools
lore

Yige Jiang

author
#0 lore raw

PATCH 1/1 macintosh: therm_windtunnel: Fix i2c adapter reference leak in probe

therm_of_probe() walks the i2c adapters with i2c_get_adapter() and drops each reference with i2c_put_adapter() before taking the next one. Once do_attach() has started the control loop, however, it returns 0 while still holding the reference to the current adapter. The pointer is not stored anywhere, so that reference is never dropped. This happens on every successful probe, including after an unbind/rebind of the platform device, and the extra device reference would make i2c_del_adapter() for that bus wait forever for the adapter device to be released.

The driver does not use the adapter after do_attach() returns; the sensor clients it talks to afterwards are children of the adapter and are unregistered by i2c_del_adapter(). Drop the reference right after do_attach(), before checking x.running.

Fixes 3e7bed52719d ("macintosh: therm_windtunnel: drop using attach_adapter")

---
Based on linux-next next-20261109 (630059a5a632).
Compile-tested: powerpc (ppc32), GCC 14.2.0, W=1, pmac32_defconfig with CONFIG_THERM_WINDTUNNEL=m, CONFIG_I2C_POWERMAC=y (object only; no new warnings). No hardware or runtime test was performed.
AI assistance was used for analysis and patch preparation.
Runs on every successful probe of the Windtunnel G4 (PowerMac3,6) fan controller, and again on each unbind/rebind.

 drivers/macintosh/therm_windtunnel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/macintosh/therm_windtunnel.c +1 -1
index 0b2e08a1bee0..4f2581d9dec9 100644
@@ -472,9 +472,9 @@ static int therm_of_probe(struct platform_device *dev)
 	/* We assume Macs have consecutive I2C bus numbers starting at 0 */
 	while (adap) {
 		do_attach(adap);
+		i2c_put_adapter(adap);
 		if (x.running)
 			return 0;
-		i2c_put_adapter(adap);
 		adap = i2c_get_adapter(++i);
 	}
 

base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47

#1 lore raw
Quoted 10 lines · Yige Jiang

therm_of_probe() walks the i2c adapters with i2c_get_adapter() and drops each reference with i2c_put_adapter() before taking the next one. Once do_attach() has started the control loop, however, it returns 0 while still holding the reference to the current adapter. The pointer is not stored anywhere, so that reference is never dropped. This happens on every successful probe, including after an unbind/rebind of the platform device, and the extra device reference would make i2c_del_adapter() for that bus wait forever for the adapter device to be released.

Quoted 8 lines

The driver does not use the adapter after do_attach() returns; the sensor clients it talks to afterwards are children of the adapter and are unregistered by i2c_del_adapter(). Drop the reference right after do_attach(), before checking x.running.

Fixes 3e7bed52719d ("macintosh: therm_windtunnel: drop using attach_adapter")

I require tests on HW for this one. Windtunnel support has always been very fragile.