Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

w1: slaves: w1_ds2408: 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: Jean-Francois Dagenais <jeff.dagenais@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexander Stein <alexander.stein@informatik.tu-chemnitz.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+52 -122
+52 -122
drivers/w1/slaves/w1_ds2408.c
··· 72 72 return 1; 73 73 } 74 74 75 - static ssize_t w1_f29_read_state( 76 - struct file *filp, struct kobject *kobj, 77 - struct bin_attribute *bin_attr, 78 - char *buf, loff_t off, size_t count) 75 + static ssize_t state_read(struct file *filp, struct kobject *kobj, 76 + struct bin_attribute *bin_attr, char *buf, loff_t off, 77 + size_t count) 79 78 { 80 79 dev_dbg(&kobj_to_w1_slave(kobj)->dev, 81 80 "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", ··· 84 85 return _read_reg(kobj_to_w1_slave(kobj), W1_F29_REG_LOGIG_STATE, buf); 85 86 } 86 87 87 - static ssize_t w1_f29_read_output( 88 - struct file *filp, struct kobject *kobj, 89 - struct bin_attribute *bin_attr, 90 - char *buf, loff_t off, size_t count) 88 + static ssize_t output_read(struct file *filp, struct kobject *kobj, 89 + struct bin_attribute *bin_attr, char *buf, 90 + loff_t off, size_t count) 91 91 { 92 92 dev_dbg(&kobj_to_w1_slave(kobj)->dev, 93 93 "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", ··· 97 99 W1_F29_REG_OUTPUT_LATCH_STATE, buf); 98 100 } 99 101 100 - static ssize_t w1_f29_read_activity( 101 - struct file *filp, struct kobject *kobj, 102 - struct bin_attribute *bin_attr, 103 - char *buf, loff_t off, size_t count) 102 + static ssize_t activity_read(struct file *filp, struct kobject *kobj, 103 + struct bin_attribute *bin_attr, char *buf, 104 + loff_t off, size_t count) 104 105 { 105 106 dev_dbg(&kobj_to_w1_slave(kobj)->dev, 106 107 "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", ··· 110 113 W1_F29_REG_ACTIVITY_LATCH_STATE, buf); 111 114 } 112 115 113 - static ssize_t w1_f29_read_cond_search_mask( 114 - struct file *filp, struct kobject *kobj, 115 - struct bin_attribute *bin_attr, 116 - char *buf, loff_t off, size_t count) 116 + static ssize_t cond_search_mask_read(struct file *filp, struct kobject *kobj, 117 + struct bin_attribute *bin_attr, char *buf, 118 + loff_t off, size_t count) 117 119 { 118 120 dev_dbg(&kobj_to_w1_slave(kobj)->dev, 119 121 "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", ··· 123 127 W1_F29_REG_COND_SEARCH_SELECT_MASK, buf); 124 128 } 125 129 126 - static ssize_t w1_f29_read_cond_search_polarity( 127 - struct file *filp, struct kobject *kobj, 128 - struct bin_attribute *bin_attr, 129 - char *buf, loff_t off, size_t count) 130 + static ssize_t cond_search_polarity_read(struct file *filp, 131 + struct kobject *kobj, 132 + struct bin_attribute *bin_attr, 133 + char *buf, loff_t off, size_t count) 130 134 { 131 135 if (count != 1 || off != 0) 132 136 return -EFAULT; ··· 134 138 W1_F29_REG_COND_SEARCH_POL_SELECT, buf); 135 139 } 136 140 137 - static ssize_t w1_f29_read_status_control( 138 - struct file *filp, struct kobject *kobj, 139 - struct bin_attribute *bin_attr, 140 - char *buf, loff_t off, size_t count) 141 + static ssize_t status_control_read(struct file *filp, struct kobject *kobj, 142 + struct bin_attribute *bin_attr, char *buf, 143 + loff_t off, size_t count) 141 144 { 142 145 if (count != 1 || off != 0) 143 146 return -EFAULT; ··· 144 149 W1_F29_REG_CONTROL_AND_STATUS, buf); 145 150 } 146 151 147 - 148 - 149 - 150 - static ssize_t w1_f29_write_output( 151 - struct file *filp, struct kobject *kobj, 152 - struct bin_attribute *bin_attr, 153 - char *buf, loff_t off, size_t count) 152 + static ssize_t output_write(struct file *filp, struct kobject *kobj, 153 + struct bin_attribute *bin_attr, char *buf, 154 + loff_t off, size_t count) 154 155 { 155 156 struct w1_slave *sl = kobj_to_w1_slave(kobj); 156 157 u8 w1_buf[3]; ··· 215 224 /** 216 225 * Writing to the activity file resets the activity latches. 217 226 */ 218 - static ssize_t w1_f29_write_activity( 219 - struct file *filp, struct kobject *kobj, 220 - struct bin_attribute *bin_attr, 221 - char *buf, loff_t off, size_t count) 227 + static ssize_t activity_write(struct file *filp, struct kobject *kobj, 228 + struct bin_attribute *bin_attr, char *buf, 229 + loff_t off, size_t count) 222 230 { 223 231 struct w1_slave *sl = kobj_to_w1_slave(kobj); 224 232 unsigned int retries = W1_F29_RETRIES; ··· 245 255 return -EIO; 246 256 } 247 257 248 - static ssize_t w1_f29_write_status_control( 249 - struct file *filp, 250 - struct kobject *kobj, 251 - struct bin_attribute *bin_attr, 252 - char *buf, 253 - loff_t off, 254 - size_t count) 258 + static ssize_t status_control_write(struct file *filp, struct kobject *kobj, 259 + struct bin_attribute *bin_attr, char *buf, 260 + loff_t off, size_t count) 255 261 { 256 262 struct w1_slave *sl = kobj_to_w1_slave(kobj); 257 263 u8 w1_buf[4]; ··· 316 330 return res; 317 331 } 318 332 319 - static struct bin_attribute w1_f29_sysfs_bin_files[] = { 320 - { 321 - .attr = { 322 - .name = "state", 323 - .mode = S_IRUGO, 324 - }, 325 - .size = 1, 326 - .read = w1_f29_read_state, 327 - }, 328 - { 329 - .attr = { 330 - .name = "output", 331 - .mode = S_IRUGO | S_IWUSR | S_IWGRP, 332 - }, 333 - .size = 1, 334 - .read = w1_f29_read_output, 335 - .write = w1_f29_write_output, 336 - }, 337 - { 338 - .attr = { 339 - .name = "activity", 340 - .mode = S_IRUGO, 341 - }, 342 - .size = 1, 343 - .read = w1_f29_read_activity, 344 - .write = w1_f29_write_activity, 345 - }, 346 - { 347 - .attr = { 348 - .name = "cond_search_mask", 349 - .mode = S_IRUGO, 350 - }, 351 - .size = 1, 352 - .read = w1_f29_read_cond_search_mask, 353 - }, 354 - { 355 - .attr = { 356 - .name = "cond_search_polarity", 357 - .mode = S_IRUGO, 358 - }, 359 - .size = 1, 360 - .read = w1_f29_read_cond_search_polarity, 361 - }, 362 - { 363 - .attr = { 364 - .name = "status_control", 365 - .mode = S_IRUGO | S_IWUSR | S_IWGRP, 366 - }, 367 - .size = 1, 368 - .read = w1_f29_read_status_control, 369 - .write = w1_f29_write_status_control, 370 - } 333 + static BIN_ATTR_RO(state, 1); 334 + static BIN_ATTR_RW(output, 1); 335 + static BIN_ATTR_RW(activity, 1); 336 + static BIN_ATTR_RO(cond_search_mask, 1); 337 + static BIN_ATTR_RO(cond_search_polarity, 1); 338 + static BIN_ATTR_RW(status_control, 1); 339 + 340 + static struct bin_attribute *w1_f29_bin_attrs[] = { 341 + &bin_attr_state, 342 + &bin_attr_output, 343 + &bin_attr_activity, 344 + &bin_attr_cond_search_mask, 345 + &bin_attr_cond_search_polarity, 346 + &bin_attr_status_control, 347 + NULL, 371 348 }; 372 349 373 - static int w1_f29_add_slave(struct w1_slave *sl) 374 - { 375 - int err = 0; 376 - int i; 350 + static const struct attribute_group w1_f29_group = { 351 + .bin_attrs = w1_f29_bin_attrs, 352 + }; 377 353 378 - err = w1_f29_disable_test_mode(sl); 379 - if (err) 380 - return err; 381 - 382 - for (i = 0; i < ARRAY_SIZE(w1_f29_sysfs_bin_files) && !err; ++i) 383 - err = sysfs_create_bin_file( 384 - &sl->dev.kobj, 385 - &(w1_f29_sysfs_bin_files[i])); 386 - if (err) 387 - while (--i >= 0) 388 - sysfs_remove_bin_file(&sl->dev.kobj, 389 - &(w1_f29_sysfs_bin_files[i])); 390 - return err; 391 - } 392 - 393 - static void w1_f29_remove_slave(struct w1_slave *sl) 394 - { 395 - int i; 396 - for (i = ARRAY_SIZE(w1_f29_sysfs_bin_files) - 1; i >= 0; --i) 397 - sysfs_remove_bin_file(&sl->dev.kobj, 398 - &(w1_f29_sysfs_bin_files[i])); 399 - } 354 + static const struct attribute_group *w1_f29_groups[] = { 355 + &w1_f29_group, 356 + NULL, 357 + }; 400 358 401 359 static struct w1_family_ops w1_f29_fops = { 402 - .add_slave = w1_f29_add_slave, 403 - .remove_slave = w1_f29_remove_slave, 360 + .add_slave = w1_f29_disable_test_mode, 361 + .groups = w1_f29_groups, 404 362 }; 405 363 406 364 static struct w1_family w1_family_29 = {