diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/i2c-dev.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 2ce083391292..567fb05aeccc 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c | |||
@@ -406,6 +406,7 @@ static struct class *i2c_dev_class; | |||
406 | static int i2cdev_attach_adapter(struct i2c_adapter *adap) | 406 | static int i2cdev_attach_adapter(struct i2c_adapter *adap) |
407 | { | 407 | { |
408 | struct i2c_dev *i2c_dev; | 408 | struct i2c_dev *i2c_dev; |
409 | int res; | ||
409 | 410 | ||
410 | i2c_dev = get_free_i2c_dev(adap); | 411 | i2c_dev = get_free_i2c_dev(adap); |
411 | if (IS_ERR(i2c_dev)) | 412 | if (IS_ERR(i2c_dev)) |
@@ -419,14 +420,20 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap) | |||
419 | MKDEV(I2C_MAJOR, adap->nr), | 420 | MKDEV(I2C_MAJOR, adap->nr), |
420 | &adap->dev, "i2c-%d", | 421 | &adap->dev, "i2c-%d", |
421 | adap->nr); | 422 | adap->nr); |
422 | if (!i2c_dev->class_dev) | 423 | if (!i2c_dev->class_dev) { |
424 | res = -ENODEV; | ||
423 | goto error; | 425 | goto error; |
424 | class_device_create_file(i2c_dev->class_dev, &class_device_attr_name); | 426 | } |
427 | res = class_device_create_file(i2c_dev->class_dev, &class_device_attr_name); | ||
428 | if (res) | ||
429 | goto error_destroy; | ||
425 | return 0; | 430 | return 0; |
431 | error_destroy: | ||
432 | class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); | ||
426 | error: | 433 | error: |
427 | return_i2c_dev(i2c_dev); | 434 | return_i2c_dev(i2c_dev); |
428 | kfree(i2c_dev); | 435 | kfree(i2c_dev); |
429 | return -ENODEV; | 436 | return res; |
430 | } | 437 | } |
431 | 438 | ||
432 | static int i2cdev_detach_adapter(struct i2c_adapter *adap) | 439 | static int i2cdev_detach_adapter(struct i2c_adapter *adap) |
@@ -437,6 +444,7 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap) | |||
437 | if (!i2c_dev) | 444 | if (!i2c_dev) |
438 | return -ENODEV; | 445 | return -ENODEV; |
439 | 446 | ||
447 | class_device_remove_file(i2c_dev->class_dev, &class_device_attr_name); | ||
440 | return_i2c_dev(i2c_dev); | 448 | return_i2c_dev(i2c_dev); |
441 | class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); | 449 | class_device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); |
442 | kfree(i2c_dev); | 450 | kfree(i2c_dev); |