diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2012-07-05 04:57:06 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2012-07-08 05:39:58 -0400 |
commit | 6d459aa011cb087ed1f5c17836b032fcc670e306 (patch) | |
tree | 5b09c984a18dc30aa6d20670b3c50753ecd103c9 /drivers/iio/industrialio-trigger.c | |
parent | cf09fe9c873ca0f4e2ca83e7bea03e2599a62d58 (diff) |
iio:trigger: Register sysfs file statically
The name sysfs attribute is the same for all triggers, so there is no need to
register them dynamically at runtime. Create a attribute group for it and set it
up for the bus attribute group. This also avoids a possible race condition
where the uevent for the device is sent before the name sysfs attribute has been
added.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/industrialio-trigger.c')
-rw-r--r-- | drivers/iio/industrialio-trigger.c | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 2ef36d15ccc5..4fe0ead84213 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c | |||
@@ -51,25 +51,19 @@ static ssize_t iio_trigger_read_name(struct device *dev, | |||
51 | 51 | ||
52 | static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL); | 52 | static DEVICE_ATTR(name, S_IRUGO, iio_trigger_read_name, NULL); |
53 | 53 | ||
54 | /** | 54 | static struct attribute *iio_trig_dev_attrs[] = { |
55 | * iio_trigger_register_sysfs() - create a device for this trigger | 55 | &dev_attr_name.attr, |
56 | * @trig_info: the trigger | 56 | NULL, |
57 | * | 57 | }; |
58 | * Also adds any control attribute registered by the trigger driver | ||
59 | **/ | ||
60 | static int iio_trigger_register_sysfs(struct iio_trigger *trig_info) | ||
61 | { | ||
62 | return sysfs_add_file_to_group(&trig_info->dev.kobj, | ||
63 | &dev_attr_name.attr, | ||
64 | NULL); | ||
65 | } | ||
66 | 58 | ||
67 | static void iio_trigger_unregister_sysfs(struct iio_trigger *trig_info) | 59 | static struct attribute_group iio_trig_attr_group = { |
68 | { | 60 | .attrs = iio_trig_dev_attrs, |
69 | sysfs_remove_file_from_group(&trig_info->dev.kobj, | 61 | }; |
70 | &dev_attr_name.attr, | 62 | |
71 | NULL); | 63 | static const struct attribute_group *iio_trig_attr_groups[] = { |
72 | } | 64 | &iio_trig_attr_group, |
65 | NULL | ||
66 | }; | ||
73 | 67 | ||
74 | int iio_trigger_register(struct iio_trigger *trig_info) | 68 | int iio_trigger_register(struct iio_trigger *trig_info) |
75 | { | 69 | { |
@@ -88,10 +82,6 @@ int iio_trigger_register(struct iio_trigger *trig_info) | |||
88 | if (ret) | 82 | if (ret) |
89 | goto error_unregister_id; | 83 | goto error_unregister_id; |
90 | 84 | ||
91 | ret = iio_trigger_register_sysfs(trig_info); | ||
92 | if (ret) | ||
93 | goto error_device_del; | ||
94 | |||
95 | /* Add to list of available triggers held by the IIO core */ | 85 | /* Add to list of available triggers held by the IIO core */ |
96 | mutex_lock(&iio_trigger_list_lock); | 86 | mutex_lock(&iio_trigger_list_lock); |
97 | list_add_tail(&trig_info->list, &iio_trigger_list); | 87 | list_add_tail(&trig_info->list, &iio_trigger_list); |
@@ -99,8 +89,6 @@ int iio_trigger_register(struct iio_trigger *trig_info) | |||
99 | 89 | ||
100 | return 0; | 90 | return 0; |
101 | 91 | ||
102 | error_device_del: | ||
103 | device_del(&trig_info->dev); | ||
104 | error_unregister_id: | 92 | error_unregister_id: |
105 | ida_simple_remove(&iio_trigger_ida, trig_info->id); | 93 | ida_simple_remove(&iio_trigger_ida, trig_info->id); |
106 | error_ret: | 94 | error_ret: |
@@ -114,7 +102,6 @@ void iio_trigger_unregister(struct iio_trigger *trig_info) | |||
114 | list_del(&trig_info->list); | 102 | list_del(&trig_info->list); |
115 | mutex_unlock(&iio_trigger_list_lock); | 103 | mutex_unlock(&iio_trigger_list_lock); |
116 | 104 | ||
117 | iio_trigger_unregister_sysfs(trig_info); | ||
118 | ida_simple_remove(&iio_trigger_ida, trig_info->id); | 105 | ida_simple_remove(&iio_trigger_ida, trig_info->id); |
119 | /* Possible issue in here */ | 106 | /* Possible issue in here */ |
120 | device_unregister(&trig_info->dev); | 107 | device_unregister(&trig_info->dev); |
@@ -406,6 +393,7 @@ static void iio_trig_release(struct device *device) | |||
406 | 393 | ||
407 | static struct device_type iio_trig_type = { | 394 | static struct device_type iio_trig_type = { |
408 | .release = iio_trig_release, | 395 | .release = iio_trig_release, |
396 | .groups = iio_trig_attr_groups, | ||
409 | }; | 397 | }; |
410 | 398 | ||
411 | static void iio_trig_subirqmask(struct irq_data *d) | 399 | static void iio_trig_subirqmask(struct irq_data *d) |