Skip to content

Commit

Permalink
i2c: smbus: Check for parent device before dereference
Browse files Browse the repository at this point in the history
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: a263a84 ("i2c: smbus: Use device_*() functions instead of of_*()")
Reported-by: syzbot+0591ccf54ee05344e4eb@syzkaller.appspotmail.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
  • Loading branch information
Andy Shevchenko authored and Wolfram Sang committed Feb 19, 2022
1 parent 017b32e commit 8302532
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/i2c/i2c-core-smbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8302532

Please sign in to comment.