diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-21 18:44:58 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-22 14:05:43 -0400 |
commit | 729fb9d33fe239e350a7e33e9f6aec2767086bd4 (patch) | |
tree | 279db34b83c7e79ffd9445f628349b3695a86b29 /drivers/w1 | |
parent | 32ea4175aea26181e2ed9a87853bb4bebd44e59e (diff) |
w1: slaves: w1_ds2413.c: convert to use w1_family_ops.groups
This moves the sysfs file creation/removal to the w1 core by using the
.groups field, saving code in the slave driver.
Acked-by: Evgeniy Polyakov <zbr@ioremap.net>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexander Stein <alexander.stein@informatik.tu-chemnitz.de>
Cc: Mariusz Bialonczyk <manio@skyboo.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/w1')
-rw-r--r-- | drivers/w1/slaves/w1_ds2413.c | 72 |
1 files changed, 22 insertions, 50 deletions
diff --git a/drivers/w1/slaves/w1_ds2413.c b/drivers/w1/slaves/w1_ds2413.c index 85937773a96a..ee28fc1ff390 100644 --- a/drivers/w1/slaves/w1_ds2413.c +++ b/drivers/w1/slaves/w1_ds2413.c | |||
@@ -30,10 +30,9 @@ MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS2413)); | |||
30 | #define W1_F3A_FUNC_PIO_ACCESS_WRITE 0x5A | 30 | #define W1_F3A_FUNC_PIO_ACCESS_WRITE 0x5A |
31 | #define W1_F3A_SUCCESS_CONFIRM_BYTE 0xAA | 31 | #define W1_F3A_SUCCESS_CONFIRM_BYTE 0xAA |
32 | 32 | ||
33 | static ssize_t w1_f3a_read_state( | 33 | static ssize_t state_read(struct file *filp, struct kobject *kobj, |
34 | struct file *filp, struct kobject *kobj, | 34 | struct bin_attribute *bin_attr, char *buf, loff_t off, |
35 | struct bin_attribute *bin_attr, | 35 | size_t count) |
36 | char *buf, loff_t off, size_t count) | ||
37 | { | 36 | { |
38 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | 37 | struct w1_slave *sl = kobj_to_w1_slave(kobj); |
39 | dev_dbg(&sl->dev, | 38 | dev_dbg(&sl->dev, |
@@ -66,10 +65,11 @@ static ssize_t w1_f3a_read_state( | |||
66 | return 1; | 65 | return 1; |
67 | } | 66 | } |
68 | 67 | ||
69 | static ssize_t w1_f3a_write_output( | 68 | static BIN_ATTR_RO(state, 1); |
70 | struct file *filp, struct kobject *kobj, | 69 | |
71 | struct bin_attribute *bin_attr, | 70 | static ssize_t output_write(struct file *filp, struct kobject *kobj, |
72 | char *buf, loff_t off, size_t count) | 71 | struct bin_attribute *bin_attr, char *buf, |
72 | loff_t off, size_t count) | ||
73 | { | 73 | { |
74 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | 74 | struct w1_slave *sl = kobj_to_w1_slave(kobj); |
75 | u8 w1_buf[3]; | 75 | u8 w1_buf[3]; |
@@ -110,53 +110,25 @@ error: | |||
110 | return -EIO; | 110 | return -EIO; |
111 | } | 111 | } |
112 | 112 | ||
113 | #define NB_SYSFS_BIN_FILES 2 | 113 | static BIN_ATTR(output, S_IRUGO | S_IWUSR | S_IWGRP, NULL, output_write, 1); |
114 | static struct bin_attribute w1_f3a_sysfs_bin_files[NB_SYSFS_BIN_FILES] = { | 114 | |
115 | { | 115 | static struct bin_attribute *w1_f3a_bin_attrs[] = { |
116 | .attr = { | 116 | &bin_attr_state, |
117 | .name = "state", | 117 | &bin_attr_output, |
118 | .mode = S_IRUGO, | 118 | NULL, |
119 | }, | ||
120 | .size = 1, | ||
121 | .read = w1_f3a_read_state, | ||
122 | }, | ||
123 | { | ||
124 | .attr = { | ||
125 | .name = "output", | ||
126 | .mode = S_IRUGO | S_IWUSR | S_IWGRP, | ||
127 | }, | ||
128 | .size = 1, | ||
129 | .write = w1_f3a_write_output, | ||
130 | } | ||
131 | }; | 119 | }; |
132 | 120 | ||
133 | static int w1_f3a_add_slave(struct w1_slave *sl) | 121 | static const struct attribute_group w1_f3a_group = { |
134 | { | 122 | .bin_attrs = w1_f3a_bin_attrs, |
135 | int err = 0; | 123 | }; |
136 | int i; | ||
137 | |||
138 | for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i) | ||
139 | err = sysfs_create_bin_file( | ||
140 | &sl->dev.kobj, | ||
141 | &(w1_f3a_sysfs_bin_files[i])); | ||
142 | if (err) | ||
143 | while (--i >= 0) | ||
144 | sysfs_remove_bin_file(&sl->dev.kobj, | ||
145 | &(w1_f3a_sysfs_bin_files[i])); | ||
146 | return err; | ||
147 | } | ||
148 | 124 | ||
149 | static void w1_f3a_remove_slave(struct w1_slave *sl) | 125 | static const struct attribute_group *w1_f3a_groups[] = { |
150 | { | 126 | &w1_f3a_group, |
151 | int i; | 127 | NULL, |
152 | for (i = NB_SYSFS_BIN_FILES - 1; i >= 0; --i) | 128 | }; |
153 | sysfs_remove_bin_file(&sl->dev.kobj, | ||
154 | &(w1_f3a_sysfs_bin_files[i])); | ||
155 | } | ||
156 | 129 | ||
157 | static struct w1_family_ops w1_f3a_fops = { | 130 | static struct w1_family_ops w1_f3a_fops = { |
158 | .add_slave = w1_f3a_add_slave, | 131 | .groups = w1_f3a_groups, |
159 | .remove_slave = w1_f3a_remove_slave, | ||
160 | }; | 132 | }; |
161 | 133 | ||
162 | static struct w1_family w1_family_3a = { | 134 | static struct w1_family w1_family_3a = { |