diff options
author | Romain Gantois <romain.gantois@bootlin.com> | 2025-03-06 19:23:24 +0300 |
---|---|---|
committer | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2025-04-19 00:33:25 +0300 |
commit | 3ec29d51b546f69de0b0d10642c9aaaf5e3704eb (patch) | |
tree | 5bf476729a526beba52508662b4b2851263bb265 | |
parent | 666be28145afbcde4a1223e6bc398664abdf8bec (diff) | |
download | linux-3ec29d51b546f69de0b0d10642c9aaaf5e3704eb.tar.xz |
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 <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
Acked-by: Andi Shyti <andi.shyti@kernel.org>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
-rw-r--r-- | drivers/media/i2c/ds90ub960.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/media/i2c/ds90ub960.c b/drivers/media/i2c/ds90ub960.c index fa06ce38e35f..fc5c43718ca4 100644 --- a/drivers/media/i2c/ds90ub960.c +++ b/drivers/media/i2c/ds90ub960.c @@ -27,6 +27,7 @@ */ #include <linux/bitops.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/fwnode.h> @@ -478,6 +479,8 @@ struct ub960_rxport { }; } eq; + /* lock for aliased_addrs and associated registers */ + struct mutex aliased_addrs_lock; u16 aliased_addrs[UB960_MAX_PORT_ALIASES]; }; @@ -1054,6 +1057,8 @@ static int ub960_atr_attach_client(struct i2c_atr *atr, u32 chan_id, struct device *dev = &priv->client->dev; unsigned int reg_idx; + guard(mutex)(&rxport->aliased_addrs_lock); + for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx++) { if (!rxport->aliased_addrs[reg_idx]) break; @@ -1085,6 +1090,8 @@ static void ub960_atr_detach_client(struct i2c_atr *atr, u32 chan_id, struct device *dev = &priv->client->dev; unsigned int reg_idx; + guard(mutex)(&rxport->aliased_addrs_lock); + for (reg_idx = 0; reg_idx < ARRAY_SIZE(rxport->aliased_addrs); reg_idx++) { if (rxport->aliased_addrs[reg_idx] == client->addr) break; @@ -3235,6 +3242,8 @@ static void ub960_rxport_free_ports(struct ub960_data *priv) fwnode_handle_put(rxport->source.ep_fwnode); fwnode_handle_put(rxport->ser.fwnode); + mutex_destroy(&rxport->aliased_addrs_lock); + kfree(rxport); priv->rxports[nport] = NULL; } @@ -3455,6 +3464,8 @@ static int ub960_parse_dt_rxport(struct ub960_data *priv, unsigned int nport, if (ret) goto err_put_remote_fwnode; + mutex_init(&rxport->aliased_addrs_lock); + return 0; err_put_remote_fwnode: |