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>
This commit is contained in:
committed by
Wolfram Sang
parent
666be28145
commit
3ec29d51b5
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user