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

Commit 86ec5ec8 authored by David Brownell's avatar David Brownell Committed by Jean Delvare
Browse files

i2c-remove-redundant-i2c_client-list.patch



This goes on top of the patch removing most i2c_adapter.clients usage,
updating i2c_attach_client:

 - Don't call device_register() while holding clist_lock.  This
   removes a self-deadlock when on the i2c_driver.probe() path,
   for drivers that need to attach new devices (e.g. dummies).

 - Remove a redundant address check.  The driver model core does
   this as a consequence of guaranteeing unique names.

 - Move the "device registered" diagnostic so that it never lies;
   previously, on error paths it would falsely report success.

Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 961f80f9
Loading
Loading
Loading
Loading
+8 −14
Original line number Original line Diff line number Diff line
@@ -709,13 +709,6 @@ int i2c_attach_client(struct i2c_client *client)
	struct i2c_adapter *adapter = client->adapter;
	struct i2c_adapter *adapter = client->adapter;
	int res = 0;
	int res = 0;


	mutex_lock(&adapter->clist_lock);
	if (i2c_check_addr(client->adapter, client->addr)) {
		res = -EBUSY;
		goto out_unlock;
	}
	list_add_tail(&client->list,&adapter->clients);

	client->dev.parent = &client->adapter->dev;
	client->dev.parent = &client->adapter->dev;
	client->dev.bus = &i2c_bus_type;
	client->dev.bus = &i2c_bus_type;


@@ -730,13 +723,17 @@ int i2c_attach_client(struct i2c_client *client)


	snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
	snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
		"%d-%04x", i2c_adapter_id(adapter), client->addr);
		"%d-%04x", i2c_adapter_id(adapter), client->addr);
	dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
		client->name, client->dev.bus_id);
	res = device_register(&client->dev);
	res = device_register(&client->dev);
	if (res)
	if (res)
		goto out_list;
		goto out_err;

	mutex_lock(&adapter->clist_lock);
	list_add_tail(&client->list, &adapter->clients);
	mutex_unlock(&adapter->clist_lock);
	mutex_unlock(&adapter->clist_lock);


	dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
		client->name, client->dev.bus_id);

	if (adapter->client_register)  {
	if (adapter->client_register)  {
		if (adapter->client_register(client)) {
		if (adapter->client_register(client)) {
			dev_dbg(&adapter->dev, "client_register "
			dev_dbg(&adapter->dev, "client_register "
@@ -747,12 +744,9 @@ int i2c_attach_client(struct i2c_client *client)


	return 0;
	return 0;


out_list:
out_err:
	list_del(&client->list);
	dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x "
	dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x "
		"(%d)\n", client->name, client->addr, res);
		"(%d)\n", client->name, client->addr, res);
out_unlock:
	mutex_unlock(&adapter->clist_lock);
	return res;
	return res;
}
}
EXPORT_SYMBOL(i2c_attach_client);
EXPORT_SYMBOL(i2c_attach_client);