diff options
author | Jean Delvare <khali@linux-fr.org> | 2006-08-15 18:26:30 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-09-26 15:38:50 -0700 |
commit | b119c6c952a086f74202ccda4b7ed72161bb6522 (patch) | |
tree | d402c6b9ea26897077b2042a31045ecc0d689883 /drivers/i2c | |
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')
-rw-r--r-- | drivers/i2c/busses/i2c-isa.c | 29 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 53 |
2 files changed, 69 insertions, 13 deletions
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c index c3e1d3e888d7..d7486e586068 100644 --- a/drivers/i2c/busses/i2c-isa.c +++ b/drivers/i2c/busses/i2c-isa.c @@ -125,6 +125,8 @@ int i2c_isa_del_driver(struct i2c_driver *driver) static int __init i2c_isa_init(void) { + int err; + mutex_init(&isa_adapter.clist_lock); INIT_LIST_HEAD(&isa_adapter.clients); @@ -133,8 +135,16 @@ static int __init i2c_isa_init(void) sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); isa_adapter.dev.driver = &i2c_adapter_driver; isa_adapter.dev.release = &i2c_adapter_dev_release; - device_register(&isa_adapter.dev); - device_create_file(&isa_adapter.dev, &dev_attr_name); + err = device_register(&isa_adapter.dev); + if (err) { + printk(KERN_ERR "i2c-isa: Failed to register device\n"); + goto exit; + } + err = device_create_file(&isa_adapter.dev, &dev_attr_name); + if (err) { + printk(KERN_ERR "i2c-isa: Failed to create name file\n"); + goto exit_unregister; + } /* Add this adapter to the i2c_adapter class */ memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device)); @@ -142,11 +152,24 @@ static int __init i2c_isa_init(void) isa_adapter.class_dev.class = &i2c_adapter_class; strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id, BUS_ID_SIZE); - class_device_register(&isa_adapter.class_dev); + err = class_device_register(&isa_adapter.class_dev); + if (err) { + printk(KERN_ERR "i2c-isa: Failed to register class device\n"); + goto exit_remove_name; + } dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); return 0; + +exit_remove_name: + device_remove_file(&isa_adapter.dev, &dev_attr_name); +exit_unregister: + init_completion(&isa_adapter.dev_released); /* Needed? */ + device_unregister(&isa_adapter.dev); + wait_for_completion(&isa_adapter.dev_released); +exit: + return err; } static void __exit i2c_isa_exit(void) 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) sprintf(adap->dev.bus_id, "i2c-%d", adap->nr); adap->dev.driver = &i2c_adapter_driver; adap->dev.release = &i2c_adapter_dev_release; - device_register(&adap->dev); - device_create_file(&adap->dev, &dev_attr_name); + res = device_register(&adap->dev); + if (res) + goto out_list; + res = device_create_file(&adap->dev, &dev_attr_name); + if (res) + goto out_unregister; /* Add this adapter to the i2c_adapter class */ memset(&adap->class_dev, 0x00, sizeof(struct class_device)); adap->class_dev.dev = &adap->dev; adap->class_dev.class = &i2c_adapter_class; strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); - class_device_register(&adap->class_dev); + res = class_device_register(&adap->class_dev); + if (res) + goto out_remove_name; dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); @@ -206,6 +212,17 @@ int i2c_add_adapter(struct i2c_adapter *adap) out_unlock: mutex_unlock(&core_lists); return res; + +out_remove_name: + device_remove_file(&adap->dev, &dev_attr_name); +out_unregister: + init_completion(&adap->dev_released); /* Needed? */ + device_unregister(&adap->dev); + wait_for_completion(&adap->dev_released); +out_list: + list_del(&adap->list); + idr_remove(&i2c_adapter_idr, adap->nr); + goto out_unlock; } @@ -394,14 +411,14 @@ int i2c_check_addr(struct i2c_adapter *adapter, int addr) int i2c_attach_client(struct i2c_client *client) { struct i2c_adapter *adapter = client->adapter; + int res = 0; mutex_lock(&adapter->clist_lock); if (__i2c_check_addr(client->adapter, client->addr)) { - mutex_unlock(&adapter->clist_lock); - return -EBUSY; + res = -EBUSY; + goto out_unlock; } list_add_tail(&client->list,&adapter->clients); - mutex_unlock(&adapter->clist_lock); if (adapter->client_register) { if (adapter->client_register(client)) { @@ -422,10 +439,26 @@ int i2c_attach_client(struct i2c_client *client) "%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); - device_register(&client->dev); - device_create_file(&client->dev, &dev_attr_client_name); - - return 0; + res = device_register(&client->dev); + if (res) + goto out_list; + res = device_create_file(&client->dev, &dev_attr_client_name); + if (res) + goto out_unregister; + +out_unlock: + mutex_unlock(&adapter->clist_lock); + return res; + +out_unregister: + init_completion(&client->released); /* Needed? */ + device_unregister(&client->dev); + wait_for_completion(&client->released); +out_list: + list_del(&client->list); + dev_err(&adapter->dev, "Failed to attach i2c client %s at 0x%02x " + "(%d)\n", client->name, client->addr, res); + goto out_unlock; } |