Commit 2f43b600 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

[PATCH] fix up the i2c locking changes

There was one place where we missed an unlock, in addition some more
code cleanups.
parent 4878dffc
...@@ -313,42 +313,45 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr) ...@@ -313,42 +313,45 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr)
int i2c_attach_client(struct i2c_client *client) int i2c_attach_client(struct i2c_client *client)
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
int res = -EBUSY, i; int i;
down(&adapter->list); down(&adapter->list);
if (__i2c_check_addr(client->adapter,client->addr)) if (__i2c_check_addr(client->adapter, client->addr))
goto out_unlock_list; goto out_unlock_list;
for (i = 0; i < I2C_CLIENT_MAX; i++) for (i = 0; i < I2C_CLIENT_MAX; i++) {
if (NULL == adapter->clients[i]) if (!adapter->clients[i])
break; goto free_slot;
if (I2C_CLIENT_MAX == i) {
printk(KERN_WARNING
" i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
client->name);
res = -ENOMEM;
goto out_unlock_list;
} }
printk(KERN_WARNING
" i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n",
client->name);
out_unlock_list:
up(&adapter->list);
return -EBUSY;
free_slot:
adapter->clients[i] = client; adapter->clients[i] = client;
up(&adapter->list); up(&adapter->list);
if (adapter->client_register) if (adapter->client_register) {
if (adapter->client_register(client)) if (adapter->client_register(client)) {
printk(KERN_DEBUG "i2c-core.o: warning: client_register seems " printk(KERN_DEBUG
"i2c-core.o: warning: client_register seems "
"to have failed for client %02x at adapter %s\n", "to have failed for client %02x at adapter %s\n",
client->addr,adapter->name); client->addr, adapter->name);
DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] registered to adapter [%s](pos. %d).\n", }
client->name, adapter->name,i)); }
DEB(printk(KERN_DEBUG
"i2c-core.o: client [%s] registered to adapter [%s] "
"(pos. %d).\n", client->name, adapter->name, i));
if(client->flags & I2C_CLIENT_ALLOW_USE) if (client->flags & I2C_CLIENT_ALLOW_USE)
client->usage_count = 0; client->usage_count = 0;
return 0; return 0;
out_unlock_list:
up(&adapter->list);
return res;
} }
...@@ -363,28 +366,30 @@ int i2c_detach_client(struct i2c_client *client) ...@@ -363,28 +366,30 @@ int i2c_detach_client(struct i2c_client *client)
if (adapter->client_unregister) { if (adapter->client_unregister) {
res = adapter->client_unregister(client); res = adapter->client_unregister(client);
if (res) { if (res) {
printk(KERN_ERR "i2c-core.o: client_unregister [%s] failed, " printk(KERN_ERR
"client not detached",client->name); "i2c-core.o: client_unregister [%s] failed, "
return res; "client not detached", client->name);
goto out;
} }
} }
down(&adapter->list); down(&adapter->list);
for (i = 0; i < I2C_CLIENT_MAX; i++) { for (i = 0; i < I2C_CLIENT_MAX; i++) {
if (client == adapter->clients[i]) if (client == adapter->clients[i]) {
break; adapter->clients[i] = NULL;
goto out_unlock;
}
} }
if (I2C_CLIENT_MAX == i) { printk(KERN_WARNING
printk(KERN_WARNING " i2c-core.o: unregister_client " " i2c-core.o: unregister_client [%s] not found\n",
"[%s] not found\n", client->name);
client->name); res = -ENODEV;
return -ENODEV;
} else
adapter->clients[i] = NULL;
up(&adapter->list);
return 0; out_unlock:
up(&adapter->list);
out:
return res;
} }
static int i2c_inc_use_client(struct i2c_client *client) static int i2c_inc_use_client(struct i2c_client *client)
...@@ -563,7 +568,7 @@ static int i2cproc_register(struct i2c_adapter *adap, int bus) ...@@ -563,7 +568,7 @@ static int i2cproc_register(struct i2c_adapter *adap, int bus)
goto fail; goto fail;
proc_entry->proc_fops = &i2cproc_operations; proc_entry->proc_fops = &i2cproc_operations;
proc_entry->owner = THIS_MODULE; proc_entry->owner = adap->owner;
adap->inode = proc_entry->low_ino; adap->inode = proc_entry->low_ino;
return 0; return 0;
fail: fail:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment