aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2013-09-26 22:36:11 -0400
committerWolfram Sang <wsa@the-dreams.de>2013-09-30 00:02:31 -0400
commit45f176aea60e9fe8c5fdf8e5c90e5c50c264d86f (patch)
tree6d1d003aae7d32cb563921c046a66c4889bf08db
parent15c03dd4859ab16f9212238f29dd315654aa94f6 (diff)
i2c: i2c-dev: Create 'name' attribute automatically
The 'name' attribute is needed for all i2c-dev class devices, meaning it can be created automatically by pointing to it in the class data structure. This simplifies the code and reduces the probability for race conditions (the name attribute should exist by the time the device is announced to user space). Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/i2c-dev.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index c3ccdea3d180..80b47e8ce030 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -102,8 +102,8 @@ static void return_i2c_dev(struct i2c_dev *i2c_dev)
102 kfree(i2c_dev); 102 kfree(i2c_dev);
103} 103}
104 104
105static ssize_t show_adapter_name(struct device *dev, 105static ssize_t name_show(struct device *dev,
106 struct device_attribute *attr, char *buf) 106 struct device_attribute *attr, char *buf)
107{ 107{
108 struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(dev->devt)); 108 struct i2c_dev *i2c_dev = i2c_dev_get_by_minor(MINOR(dev->devt));
109 109
@@ -111,7 +111,13 @@ static ssize_t show_adapter_name(struct device *dev,
111 return -ENODEV; 111 return -ENODEV;
112 return sprintf(buf, "%s\n", i2c_dev->adap->name); 112 return sprintf(buf, "%s\n", i2c_dev->adap->name);
113} 113}
114static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL); 114static DEVICE_ATTR_RO(name);
115
116static struct attribute *i2c_attrs[] = {
117 &dev_attr_name.attr,
118 NULL,
119};
120ATTRIBUTE_GROUPS(i2c);
115 121
116/* ------------------------------------------------------------------------- */ 122/* ------------------------------------------------------------------------- */
117 123
@@ -562,15 +568,10 @@ static int i2cdev_attach_adapter(struct device *dev, void *dummy)
562 res = PTR_ERR(i2c_dev->dev); 568 res = PTR_ERR(i2c_dev->dev);
563 goto error; 569 goto error;
564 } 570 }
565 res = device_create_file(i2c_dev->dev, &dev_attr_name);
566 if (res)
567 goto error_destroy;
568 571
569 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n", 572 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
570 adap->name, adap->nr); 573 adap->name, adap->nr);
571 return 0; 574 return 0;
572error_destroy:
573 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
574error: 575error:
575 return_i2c_dev(i2c_dev); 576 return_i2c_dev(i2c_dev);
576 return res; 577 return res;
@@ -589,7 +590,6 @@ static int i2cdev_detach_adapter(struct device *dev, void *dummy)
589 if (!i2c_dev) /* attach_adapter must have failed */ 590 if (!i2c_dev) /* attach_adapter must have failed */
590 return 0; 591 return 0;
591 592
592 device_remove_file(i2c_dev->dev, &dev_attr_name);
593 return_i2c_dev(i2c_dev); 593 return_i2c_dev(i2c_dev);
594 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); 594 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
595 595
@@ -637,6 +637,7 @@ static int __init i2c_dev_init(void)
637 res = PTR_ERR(i2c_dev_class); 637 res = PTR_ERR(i2c_dev_class);
638 goto out_unreg_chrdev; 638 goto out_unreg_chrdev;
639 } 639 }
640 i2c_dev_class->dev_groups = i2c_groups;
640 641
641 /* Keep track of adapters which will be added or removed later */ 642 /* Keep track of adapters which will be added or removed later */
642 res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier); 643 res = bus_register_notifier(&i2c_bus_type, &i2cdev_notifier);