Commit 4caf4cb1 authored by Chengfeng Ye's avatar Chengfeng Ye Committed by Wolfram Sang

i2c: bcm-iproc: Fix bcm_iproc_i2c_isr deadlock issue

iproc_i2c_rd_reg() and iproc_i2c_wr_reg() are called from both
interrupt context (e.g. bcm_iproc_i2c_isr) and process context
(e.g. bcm_iproc_i2c_suspend). Therefore, interrupts should be
disabled to avoid potential deadlock. To prevent this scenario,
use spin_lock_irqsave().

Fixes: 9a103872 ("i2c: iproc: add NIC I2C support")
Signed-off-by: default avatarChengfeng Ye <dg573847474@gmail.com>
Acked-by: default avatarRay Jui <ray.jui@broadcom.com>
Reviewed-by: default avatarAndi Shyti <andi.shyti@kernel.org>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent 7d711966
...@@ -233,13 +233,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c, ...@@ -233,13 +233,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
u32 offset) u32 offset)
{ {
u32 val; u32 val;
unsigned long flags;
if (iproc_i2c->idm_base) { if (iproc_i2c->idm_base) {
spin_lock(&iproc_i2c->idm_lock); spin_lock_irqsave(&iproc_i2c->idm_lock, flags);
writel(iproc_i2c->ape_addr_mask, writel(iproc_i2c->ape_addr_mask,
iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET);
val = readl(iproc_i2c->base + offset); val = readl(iproc_i2c->base + offset);
spin_unlock(&iproc_i2c->idm_lock); spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags);
} else { } else {
val = readl(iproc_i2c->base + offset); val = readl(iproc_i2c->base + offset);
} }
...@@ -250,12 +251,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c, ...@@ -250,12 +251,14 @@ static inline u32 iproc_i2c_rd_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
static inline void iproc_i2c_wr_reg(struct bcm_iproc_i2c_dev *iproc_i2c, static inline void iproc_i2c_wr_reg(struct bcm_iproc_i2c_dev *iproc_i2c,
u32 offset, u32 val) u32 offset, u32 val)
{ {
unsigned long flags;
if (iproc_i2c->idm_base) { if (iproc_i2c->idm_base) {
spin_lock(&iproc_i2c->idm_lock); spin_lock_irqsave(&iproc_i2c->idm_lock, flags);
writel(iproc_i2c->ape_addr_mask, writel(iproc_i2c->ape_addr_mask,
iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET); iproc_i2c->idm_base + IDM_CTRL_DIRECT_OFFSET);
writel(val, iproc_i2c->base + offset); writel(val, iproc_i2c->base + offset);
spin_unlock(&iproc_i2c->idm_lock); spin_unlock_irqrestore(&iproc_i2c->idm_lock, flags);
} else { } else {
writel(val, iproc_i2c->base + offset); writel(val, iproc_i2c->base + offset);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment