Skip to content

Commit 5e74b9b

Browse files
committed
Merge tag 'i2c-for-6.13-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c fixes from Wolfram Sang: - fix ref leak in the I2C core - fix remove notification in the address translator - missing error check in the pinctrl demuxer (plus a typo fix) - fix NAK handling when Linux is testunit target - fix NAK handling for the Renesas R-Car controller when it is a target * tag 'i2c-for-6.13-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: i2c: testunit: on errors, repeat NACK until STOP i2c: rcar: fix NACK handling when being a target i2c: mux: demux-pinctrl: correct comment i2c: mux: demux-pinctrl: check initial mux selection, too i2c: atr: Fix client detach i2c: core: fix reference leak in i2c_register_adapter()
2 parents 4b040f0 + 6ad30f7 commit 5e74b9b

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

drivers/i2c/busses/i2c-rcar.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
#define ID_P_PM_BLOCKED BIT(31)
131131
#define ID_P_MASK GENMASK(31, 27)
132132

133+
#define ID_SLAVE_NACK BIT(0)
134+
133135
enum rcar_i2c_type {
134136
I2C_RCAR_GEN1,
135137
I2C_RCAR_GEN2,
@@ -166,6 +168,7 @@ struct rcar_i2c_priv {
166168
int irq;
167169

168170
struct i2c_client *host_notify_client;
171+
u8 slave_flags;
169172
};
170173

171174
#define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent)
@@ -655,6 +658,7 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)
655658
{
656659
u32 ssr_raw, ssr_filtered;
657660
u8 value;
661+
int ret;
658662

659663
ssr_raw = rcar_i2c_read(priv, ICSSR) & 0xff;
660664
ssr_filtered = ssr_raw & rcar_i2c_read(priv, ICSIER);
@@ -670,7 +674,10 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)
670674
rcar_i2c_write(priv, ICRXTX, value);
671675
rcar_i2c_write(priv, ICSIER, SDE | SSR | SAR);
672676
} else {
673-
i2c_slave_event(priv->slave, I2C_SLAVE_WRITE_REQUESTED, &value);
677+
ret = i2c_slave_event(priv->slave, I2C_SLAVE_WRITE_REQUESTED, &value);
678+
if (ret)
679+
priv->slave_flags |= ID_SLAVE_NACK;
680+
674681
rcar_i2c_read(priv, ICRXTX); /* dummy read */
675682
rcar_i2c_write(priv, ICSIER, SDR | SSR | SAR);
676683
}
@@ -683,18 +690,21 @@ static bool rcar_i2c_slave_irq(struct rcar_i2c_priv *priv)
683690
if (ssr_filtered & SSR) {
684691
i2c_slave_event(priv->slave, I2C_SLAVE_STOP, &value);
685692
rcar_i2c_write(priv, ICSCR, SIE | SDBS); /* clear our NACK */
693+
priv->slave_flags &= ~ID_SLAVE_NACK;
686694
rcar_i2c_write(priv, ICSIER, SAR);
687695
rcar_i2c_write(priv, ICSSR, ~SSR & 0xff);
688696
}
689697

690698
/* master wants to write to us */
691699
if (ssr_filtered & SDR) {
692-
int ret;
693-
694700
value = rcar_i2c_read(priv, ICRXTX);
695701
ret = i2c_slave_event(priv->slave, I2C_SLAVE_WRITE_RECEIVED, &value);
696-
/* Send NACK in case of error */
697-
rcar_i2c_write(priv, ICSCR, SIE | SDBS | (ret < 0 ? FNA : 0));
702+
if (ret)
703+
priv->slave_flags |= ID_SLAVE_NACK;
704+
705+
/* Send NACK in case of error, but it will come 1 byte late :( */
706+
rcar_i2c_write(priv, ICSCR, SIE | SDBS |
707+
(priv->slave_flags & ID_SLAVE_NACK ? FNA : 0));
698708
rcar_i2c_write(priv, ICSSR, ~SDR & 0xff);
699709
}
700710

drivers/i2c/i2c-atr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int i2c_atr_bus_notifier_call(struct notifier_block *nb,
412412
dev_name(dev), ret);
413413
break;
414414

415-
case BUS_NOTIFY_DEL_DEVICE:
415+
case BUS_NOTIFY_REMOVED_DEVICE:
416416
i2c_atr_detach_client(client->adapter, client);
417417
break;
418418

drivers/i2c/i2c-core-base.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
15621562
res = device_add(&adap->dev);
15631563
if (res) {
15641564
pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
1565+
put_device(&adap->dev);
15651566
goto out_list;
15661567
}
15671568

drivers/i2c/i2c-slave-testunit.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum testunit_regs {
3838

3939
enum testunit_flags {
4040
TU_FLAG_IN_PROCESS,
41+
TU_FLAG_NACK,
4142
};
4243

4344
struct testunit_data {
@@ -90,17 +91,21 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client,
9091

9192
switch (event) {
9293
case I2C_SLAVE_WRITE_REQUESTED:
93-
if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags))
94-
return -EBUSY;
94+
if (test_bit(TU_FLAG_IN_PROCESS | TU_FLAG_NACK, &tu->flags)) {
95+
ret = -EBUSY;
96+
break;
97+
}
9598

9699
memset(tu->regs, 0, TU_NUM_REGS);
97100
tu->reg_idx = 0;
98101
tu->read_idx = 0;
99102
break;
100103

101104
case I2C_SLAVE_WRITE_RECEIVED:
102-
if (test_bit(TU_FLAG_IN_PROCESS, &tu->flags))
103-
return -EBUSY;
105+
if (test_bit(TU_FLAG_IN_PROCESS | TU_FLAG_NACK, &tu->flags)) {
106+
ret = -EBUSY;
107+
break;
108+
}
104109

105110
if (tu->reg_idx < TU_NUM_REGS)
106111
tu->regs[tu->reg_idx] = *val;
@@ -129,6 +134,8 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client,
129134
* here because we still need them in the workqueue!
130135
*/
131136
tu->reg_idx = 0;
137+
138+
clear_bit(TU_FLAG_NACK, &tu->flags);
132139
break;
133140

134141
case I2C_SLAVE_READ_PROCESSED:
@@ -151,6 +158,10 @@ static int i2c_slave_testunit_slave_cb(struct i2c_client *client,
151158
break;
152159
}
153160

161+
/* If an error occurred somewhen, we NACK everything until next STOP */
162+
if (ret)
163+
set_bit(TU_FLAG_NACK, &tu->flags);
164+
154165
return ret;
155166
}
156167

drivers/i2c/muxes/i2c-demux-pinctrl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int i2c_demux_activate_master(struct i2c_demux_pinctrl_priv *priv, u32 ne
6868
}
6969

7070
/*
71-
* Check if there are pinctrl states at all. Note: we cant' use
71+
* Check if there are pinctrl states at all. Note: we can't use
7272
* devm_pinctrl_get_select() because we need to distinguish between
7373
* the -ENODEV from devm_pinctrl_get() and pinctrl_lookup_state().
7474
*/
@@ -261,7 +261,9 @@ static int i2c_demux_pinctrl_probe(struct platform_device *pdev)
261261
pm_runtime_no_callbacks(&pdev->dev);
262262

263263
/* switch to first parent as active master */
264-
i2c_demux_activate_master(priv, 0);
264+
err = i2c_demux_activate_master(priv, 0);
265+
if (err)
266+
goto err_rollback;
265267

266268
err = device_create_file(&pdev->dev, &dev_attr_available_masters);
267269
if (err)

0 commit comments

Comments
 (0)