diff options
author | Jean Delvare <khali@linux-fr.org> | 2006-08-15 12:26:30 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-09-26 18:38:50 -0400 |
commit | b119c6c952a086f74202ccda4b7ed72161bb6522 (patch) | |
tree | d402c6b9ea26897077b2042a31045ecc0d689883 /drivers/i2c/i2c-core.c | |
parent | 22f76e744dc41096987c6df8270b5c249511cde5 (diff) |
i2c: __must_check fixes (core drivers)
i2c: __must_check fixes (core drivers)
Check for error on sysfs file creation.
Check for error on device registration.
Check for error on class device registration.
Greg, I am not familiar with completion, can you please tell me if I
need to take care of it in the error paths (as I did in this patch,
see /* Needed? */ comments), or if it isn't needed?
These patches were tested, including forced errors, so they should work
fine. But of course more testing can't hurt.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/i2c/i2c-core.c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 9cb277d6aa48..36e1214b0b1d 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -183,15 +183,21 @@ int i2c_add_adapter(struct i2c_adapter *adap) | |||
183 | sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); | 183 | sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); |
184 | adap->dev.driver = &i2c_adapter_driver; | 184 | adap->dev.driver = &i2c_adapter_driver; |
185 | adap->dev.release = &i2c_adapter_dev_release; | 185 | adap->dev.release = &i2c_adapter_dev_release; |
186 | device_register(&adap->dev); | 186 | res = device_register(&adap->dev); |
187 | device_create_file(&adap->dev, &dev_attr_name); | 187 | if (res) |
188 | goto out_list; | ||
189 | res = device_create_file(&adap->dev, &dev_attr_name); | ||
190 | if (res) | ||
191 | goto out_unregister; | ||
188 | 192 | ||
189 | /* Add this adapter to the i2c_adapter class */ | 193 | /* Add this adapter to the i2c_adapter class */ |
190 | memset(&adap->class_dev, 0x00, sizeof(struct class_device)); | 194 | memset(&adap->class_dev, 0x00, sizeof(struct class_device)); |
191 | adap->class_dev.dev = &adap->dev; | 195 | adap->class_dev.dev = &adap->dev; |
192 | adap->class_dev.class = &i2c_adapter_class; | 196 | adap->class_dev.class = &i2c_adapter_class; |
193 | strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); | 197 | strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); |
194 | class_device_register(&adap->class_dev); | 198 | res = class_device_register(&adap->class_dev); |
199 | if (res) | ||
200 | goto out_remove_name; | ||
195 | 201 | ||
196 | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); | 202 | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); |
197 | 203 | ||
@@ -206,6 +212,17 @@ int i2c_add_adapter(struct i2c_adapter *adap) | |||
206 | out_unlock: | 212 | out_unlock: |
207 | mutex_unlock(&core_lists); | 213 | mutex_unlock(&core_lists); |
208 | return res; | 214 | return res; |
215 | |||
216 | out_remove_name: | ||
217 | device_remove_file(&adap->dev, &dev_attr_name); | ||
218 | out_unregister: | ||
219 | init_completion(&adap->dev_released); /* Needed? */ | ||
220 | device_unregister(&adap->dev); | ||
221 | wait_for_completion(&adap->dev_released); | ||
222 | out_list: | ||
223 | list_del(&adap->list); | ||
224 | idr_remove(&i2c_adapter_idr, adap->nr); | ||
225 | goto out_unlock; | ||
209 | } | 226 | } |
210 | 227 | ||
211 | 228 | ||
@@ -394,14 +411,14 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr) | |||
394 | int i2c_attach_client(struct i2c_client *client) | 411 | int i2c_attach_client(struct i2c_client *client) |
395 | { | 412 | { |
396 | struct i2c_adapter *adapter = client->adapter; | 413 | struct i2c_adapter *adapter = client->adapter; |
414 | int res = 0; | ||
397 | 415 | ||
398 | mutex_lock(&adapter->clist_lock); | 416 | mutex_lock(&adapter->clist_lock); |
399 | if (__i2c_check_addr(client->adapter, client->addr)) { | 417 | if (__i2c_check_addr(client->adapter, client->addr)) { |
400 | mutex_unlock(&adapter->clist_lock); | 418 | res = -EBUSY; |
401 | return -EBUSY; | 419 | goto out_unlock; |
402 | } | 420 | } |
403 | list_add_tail(&client->list,&adapter->clients); | 421 | list_add_tail(&client->list,&adapter->clients); |
404 | mutex_unlock(&adapter->clist_lock); | ||
405 | 422 | ||
406 | if (adapter->client_register) { | 423 | if (adapter->client_register) { |
407 | if (adapter->client_register(client)) { | 424 | if (adapter->client_register(client)) { |
@@ -422,10 +439,26 @@ int i2c_attach_client(struct i2c_client *client) | |||
422 | "%d-%04x", i2c_adapter_id(adapter), client->addr); | 439 | "%d-%04x", i2c_adapter_id(adapter), client->addr); |
423 | dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", | 440 | dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", |
424 | client->name, client->dev.bus_id); | 441 | client->name, client->dev.bus_id); |
425 | device_register(&client->dev); | 442 | res = device_register(&client->dev); |
426 | device_create_file(&client->dev, &dev_attr_client_name); | 443 | if (res) |
427 | 444 | goto out_list; | |
428 | return 0; | 445 | res = device_create_file(&client->dev, &dev_attr_client_name); |
446 | if (res) | ||
447 | goto out_unregister; | ||
448 | |||
449 | out_unlock: | ||
450 | mutex_unlock(&adapter->clist_lock); | ||
451 | return res; | ||
452 | |||
453 | out_unregister: | ||
454 | init_completion(&client->released); /* Needed? */ | ||
455 | device_unregister(&client->dev); | ||
456 | wait_for_completion(&client->released); | ||
457 | out_list: | ||
458 | list_del(&client->list); | ||
459 | dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " | ||
460 | "(%d)\n", client->name, client->addr, res); | ||
461 | goto out_unlock; | ||
429 | } | 462 | } |
430 | 463 | ||
431 | 464 | ||