Skip to content

Commit 19cde9c

Browse files
911gt3wsakernel
authored andcommitted
i2c: rk3x: fix potential spinlock recursion on poll
Possible deadlock scenario (on reboot): rk3x_i2c_xfer_common(polling) -> rk3x_i2c_wait_xfer_poll() -> rk3x_i2c_irq(0, i2c); --> spin_lock(&i2c->lock); ... <rk3x i2c interrupt> -> rk3x_i2c_irq(0, i2c); --> spin_lock(&i2c->lock); (deadlock here) Store the IRQ number and disable/enable it around the polling transfer. This patch has been tested on NanoPC-T4. Signed-off-by: Jensen Huang <jensenhuang@friendlyarm.com> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent 043465b commit 19cde9c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/i2c/busses/i2c-rk3x.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ struct rk3x_i2c_soc_data {
178178
* @clk: function clk for rk3399 or function & Bus clks for others
179179
* @pclk: Bus clk for rk3399
180180
* @clk_rate_nb: i2c clk rate change notify
181+
* @irq: irq number
181182
* @t: I2C known timing information
182183
* @lock: spinlock for the i2c bus
183184
* @wait: the waitqueue to wait for i2c transfer
@@ -200,6 +201,7 @@ struct rk3x_i2c {
200201
struct clk *clk;
201202
struct clk *pclk;
202203
struct notifier_block clk_rate_nb;
204+
int irq;
203205

204206
/* Settings */
205207
struct i2c_timings t;
@@ -1087,13 +1089,18 @@ static int rk3x_i2c_xfer_common(struct i2c_adapter *adap,
10871089

10881090
spin_unlock_irqrestore(&i2c->lock, flags);
10891091

1090-
rk3x_i2c_start(i2c);
1091-
10921092
if (!polling) {
1093+
rk3x_i2c_start(i2c);
1094+
10931095
timeout = wait_event_timeout(i2c->wait, !i2c->busy,
10941096
msecs_to_jiffies(WAIT_TIMEOUT));
10951097
} else {
1098+
disable_irq(i2c->irq);
1099+
rk3x_i2c_start(i2c);
1100+
10961101
timeout = rk3x_i2c_wait_xfer_poll(i2c);
1102+
1103+
enable_irq(i2c->irq);
10971104
}
10981105

10991106
spin_lock_irqsave(&i2c->lock, flags);
@@ -1310,6 +1317,8 @@ static int rk3x_i2c_probe(struct platform_device *pdev)
13101317
return ret;
13111318
}
13121319

1320+
i2c->irq = irq;
1321+
13131322
platform_set_drvdata(pdev, i2c);
13141323

13151324
if (i2c->soc_data->calc_timings == rk3x_i2c_v0_calc_timings) {

0 commit comments

Comments
 (0)