Skip to content

Commit 3ec29d5

Browse files
rgantoisWolfram Sang
authored andcommitted
media: i2c: ds90ub960: Protect alias_use_mask with a mutex
The aliased_addrs list represents the occupation of an RX port's hardware alias table. This list and the underlying hardware table are only accessed in the attach/detach_client() callbacks. These functions are only called from a bus notifier handler in i2c-atr.c, which is always called with the notifier chain's semaphore held. This indirectly prevents concurrent access to the aliased_addrs list. However, more explicit and direct locking is preferable. Moreover, with the introduction of dynamic address translation in a future patch, the attach/detach_client() callbacks will be called from outside of the notifier chain's read section. Introduce a mutex to protect access to the aliased_addrs list and its underlying hardware table. Tested-by: Tomi Valkeinen <[email protected]> Signed-off-by: Romain Gantois <[email protected]> Acked-by: Andi Shyti <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 666be28 commit 3ec29d5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/media/i2c/ds90ub960.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828

2929
#include <linux/bitops.h>
30+
#include <linux/cleanup.h>
3031
#include <linux/clk.h>
3132
#include <linux/delay.h>
3233
#include <linux/fwnode.h>
@@ -478,6 +479,8 @@ struct ub960_rxport {
478479
};
479480
} eq;
480481

482+
/* lock for aliased_addrs and associated registers */
483+
struct mutex aliased_addrs_lock;
481484
u16 aliased_addrs[UB960_MAX_PORT_ALIASES];
482485
};
483486

@@ -1054,6 +1057,8 @@ static int ub960_atr_attach_client(struct i2c_atr *atr, u32 chan_id,
10541057
struct device *dev = &priv->client->dev;
10551058
unsigned int reg_idx;
10561059

1060+
guard(mutex)(&rxport->aliased_addrs_lock);
1061+
10571062
for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx++) {
10581063
if (!rxport->aliased_addrs[reg_idx])
10591064
break;
@@ -1085,6 +1090,8 @@ static void ub960_atr_detach_client(struct i2c_atr *atr, u32 chan_id,
10851090
struct device *dev = &priv->client->dev;
10861091
unsigned int reg_idx;
10871092

1093+
guard(mutex)(&rxport->aliased_addrs_lock);
1094+
10881095
for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx++) {
10891096
if (rxport->aliased_addrs[reg_idx] == client->addr)
10901097
break;
@@ -3235,6 +3242,8 @@ static void ub960_rxport_free_ports(struct ub960_data *priv)
32353242
fwnode_handle_put(rxport->source.ep_fwnode);
32363243
fwnode_handle_put(rxport->ser.fwnode);
32373244

3245+
mutex_destroy(&rxport->aliased_addrs_lock);
3246+
32383247
kfree(rxport);
32393248
priv->rxports[nport] = NULL;
32403249
}
@@ -3455,6 +3464,8 @@ static int ub960_parse_dt_rxport(struct ub960_data *priv, unsigned int nport,
34553464
if (ret)
34563465
goto err_put_remote_fwnode;
34573466

3467+
mutex_init(&rxport->aliased_addrs_lock);
3468+
34583469
return 0;
34593470

34603471
err_put_remote_fwnode:

0 commit comments

Comments
 (0)