Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dafc50d1 authored by Jean Delvare's avatar Jean Delvare
Browse files

i2c: Use a separate mutex for userspace client lists



Moving userspace-instantiated clients to separate lists wasn't nearly
enough to avoid deadlocks in multiplexed bus cases. We also want to
have a dedicated mutex to protect each list.

Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Cc: Michael Lawnick <ml.lawnick@gmx.de>
parent 8031d79b
Loading
Loading
Loading
Loading
+7 −6
Original line number Original line Diff line number Diff line
@@ -662,9 +662,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
		return -EINVAL;
		return -EINVAL;


	/* Keep track of the added device */
	/* Keep track of the added device */
	i2c_lock_adapter(adap);
	mutex_lock(&adap->userspace_clients_lock);
	list_add_tail(&client->detected, &adap->userspace_clients);
	list_add_tail(&client->detected, &adap->userspace_clients);
	i2c_unlock_adapter(adap);
	mutex_unlock(&adap->userspace_clients_lock);
	dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",
	dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",
		 info.type, info.addr);
		 info.type, info.addr);


@@ -703,7 +703,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,


	/* Make sure the device was added through sysfs */
	/* Make sure the device was added through sysfs */
	res = -ENOENT;
	res = -ENOENT;
	i2c_lock_adapter(adap);
	mutex_lock(&adap->userspace_clients_lock);
	list_for_each_entry_safe(client, next, &adap->userspace_clients,
	list_for_each_entry_safe(client, next, &adap->userspace_clients,
				 detected) {
				 detected) {
		if (client->addr == addr) {
		if (client->addr == addr) {
@@ -716,7 +716,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
			break;
			break;
		}
		}
	}
	}
	i2c_unlock_adapter(adap);
	mutex_unlock(&adap->userspace_clients_lock);


	if (res < 0)
	if (res < 0)
		dev_err(dev, "%s: Can't find device in list\n",
		dev_err(dev, "%s: Can't find device in list\n",
@@ -798,6 +798,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
	}
	}


	rt_mutex_init(&adap->bus_lock);
	rt_mutex_init(&adap->bus_lock);
	mutex_init(&adap->userspace_clients_lock);
	INIT_LIST_HEAD(&adap->userspace_clients);
	INIT_LIST_HEAD(&adap->userspace_clients);


	/* Set default timeout to 1 second if not already set */
	/* Set default timeout to 1 second if not already set */
@@ -1003,7 +1004,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
		return res;
		return res;


	/* Remove devices instantiated from sysfs */
	/* Remove devices instantiated from sysfs */
	i2c_lock_adapter(adap);
	mutex_lock(&adap->userspace_clients_lock);
	list_for_each_entry_safe(client, next, &adap->userspace_clients,
	list_for_each_entry_safe(client, next, &adap->userspace_clients,
				 detected) {
				 detected) {
		dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
		dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
@@ -1011,7 +1012,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
		list_del(&client->detected);
		list_del(&client->detected);
		i2c_unregister_device(client);
		i2c_unregister_device(client);
	}
	}
	i2c_unlock_adapter(adap);
	mutex_unlock(&adap->userspace_clients_lock);


	/* Detach any active clients. This can't fail, thus we do not
	/* Detach any active clients. This can't fail, thus we do not
	   checking the returned value. */
	   checking the returned value. */
+1 −0
Original line number Original line Diff line number Diff line
@@ -368,6 +368,7 @@ struct i2c_adapter {
	char name[48];
	char name[48];
	struct completion dev_released;
	struct completion dev_released;


	struct mutex userspace_clients_lock;
	struct list_head userspace_clients;
	struct list_head userspace_clients;
};
};
#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)