Skip to contentSkip to conversation

i2c: smbus: Check for parent device before dereference

PATCH Applied Andy Shevchenko 2 participants 3 messages Feb 4, 2022 – Feb 19, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: smbus: Check for parent device before dereference

An I²C adapter might be instantiated without parent. In such case there is no property can be retrieved. Skip SMBus alert setup when this happens.

Fixes a263a84088f6 ("i2c: smbus: Use device_*() functions instead of of_*()")
Reported-by [email protected]
---
 drivers/i2c/i2c-core-smbus.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-smbus.c +6 -2
index 304c2c8fee68..029f1b7c83bc 100644
@@ -705,10 +705,14 @@ EXPORT_SYMBOL_GPL(i2c_new_smbus_alert_device);
 #if IS_ENABLED(CONFIG_I2C_SMBUS)
 int i2c_setup_smbus_alert(struct i2c_adapter *adapter)
 {
+	struct device *parent = adapter->dev.parent;
 	int irq;
 
-	irq = device_property_match_string(adapter->dev.parent, "interrupt-names",
-					   "smbus_alert");
+	/* Adapter instantiated without parent, skip the SMBus alert setup */
+	if (!parent)
+		return 0;
+
+	irq = device_property_match_string(parent, "interrupt-names", "smbus_alert");
 	if (irq == -EINVAL || irq == -ENODATA)
 		return 0;
 	else if (irq < 0)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · Andy Shevchenko

An I²C adapter might be instantiated without parent. In such case there is no property can be retrieved. Skip SMBus alert setup when this happens.

As of today the problem is still in v5.17-rcX.

Signature · 2 lines
With Best Regards,
Andy Shevchenko