i2c: designware: Fix oops from i2c_dw_irq_handler_slave
Subsystems (3)
PATCH 1/1 i2c: designware: Fix oops from i2c_dw_irq_handler_slave
When i2c-designware is initialized in slave mode the i2c-designware-slave.c: i2c_dw_irq_handler_slave() can hit a NULL pointer dereference when I2C slave backend is not registered but code is accessing the struct dw_i2c_dev.slave without testing is it NULL.
We might get spurious interrupts from other devices or from IRQ core during unloading the driver when CONFIG_DEBUG_SHIRQ is set. Existing check for enable and IRQ status is not enough since device can be power gated and those bits may read 1.
Fix this by handling the interrupt only when also struct dw_i2c_dev.slave is set.
--- drivers/i2c/busses/i2c-designware-slave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-slave.c +1 -1
@@ -272,7 +272,7 @@ static int i2c_dw_irq_handler_slave(struct dw_i2c_dev *dev) slave_activity = ((dw_readl (dev,DW_IC_STATUS ) &DW_IC_STATUS_SLAVE_ACTIVITY ) >>6 ); -if (!enabled || !(raw_stat & ~DW_IC_INTR_ACTIVITY )) +if (!enabled || !(raw_stat & ~DW_IC_INTR_ACTIVITY ) || !dev->slave)return 0 ; dev_dbg(dev->dev,
Signature · 1 line
2.13.2
Wolfram Sang
AppliedQuoted 10 lines · Jarkko Nikula
When i2c-designware is initialized in slave mode the
i2c-designware-slave.c:i2c_dw_irq_handler_slave()can hit a NULL pointer dereference when I2C slave backend is not registered but code is accessing the struct dw_i2c_dev.slave without testing is it NULL.We might get spurious interrupts from other devices or from IRQ core during unloading the driver when
CONFIG_DEBUG_SHIRQis set. Existing check for enable and IRQ status is not enough since device can be power gated and those bits may read 1.
Quoted 4 lines
Fix this by handling the interrupt only when also struct dw_i2c_dev.slave is set.
Signed-off-by Jarkko Nikula <[email protected]>
Applied to for-current, thanks!