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

w1: slaves: w1_ds28e04: 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: Alexander Stein <alexander.stein@informatik.tu-chemnitz.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+42 -70
+42 -70
drivers/w1/slaves/w1_ds28e04.c
··· 118 118 return w1_read_block(sl->master, data, len); 119 119 } 120 120 121 - static ssize_t w1_f1C_read_bin(struct file *filp, struct kobject *kobj, 122 - struct bin_attribute *bin_attr, 123 - char *buf, loff_t off, size_t count) 121 + static ssize_t eeprom_read(struct file *filp, struct kobject *kobj, 122 + struct bin_attribute *bin_attr, char *buf, 123 + loff_t off, size_t count) 124 124 { 125 125 struct w1_slave *sl = kobj_to_w1_slave(kobj); 126 126 struct w1_f1C_data *data = sl->family_data; ··· 226 226 return 0; 227 227 } 228 228 229 - static ssize_t w1_f1C_write_bin(struct file *filp, struct kobject *kobj, 230 - struct bin_attribute *bin_attr, 231 - char *buf, loff_t off, size_t count) 229 + static ssize_t eeprom_write(struct file *filp, struct kobject *kobj, 230 + struct bin_attribute *bin_attr, char *buf, 231 + loff_t off, size_t count) 232 232 233 233 { 234 234 struct w1_slave *sl = kobj_to_w1_slave(kobj); ··· 280 280 return count; 281 281 } 282 282 283 - static ssize_t w1_f1C_read_pio(struct file *filp, struct kobject *kobj, 284 - struct bin_attribute *bin_attr, 285 - char *buf, loff_t off, size_t count) 283 + static BIN_ATTR_RW(eeprom, W1_EEPROM_SIZE); 284 + 285 + static ssize_t pio_read(struct file *filp, struct kobject *kobj, 286 + struct bin_attribute *bin_attr, char *buf, loff_t off, 287 + size_t count) 286 288 287 289 { 288 290 struct w1_slave *sl = kobj_to_w1_slave(kobj); ··· 301 299 return ret; 302 300 } 303 301 304 - static ssize_t w1_f1C_write_pio(struct file *filp, struct kobject *kobj, 305 - struct bin_attribute *bin_attr, 306 - char *buf, loff_t off, size_t count) 302 + static ssize_t pio_write(struct file *filp, struct kobject *kobj, 303 + struct bin_attribute *bin_attr, char *buf, loff_t off, 304 + size_t count) 307 305 308 306 { 309 307 struct w1_slave *sl = kobj_to_w1_slave(kobj); ··· 341 339 return count; 342 340 } 343 341 344 - static ssize_t w1_f1C_show_crccheck(struct device *dev, 345 - struct device_attribute *attr, char *buf) 342 + static BIN_ATTR_RW(pio, 1); 343 + 344 + static ssize_t crccheck_show(struct device *dev, struct device_attribute *attr, 345 + char *buf) 346 346 { 347 347 if (put_user(w1_enable_crccheck + 0x30, buf)) 348 348 return -EFAULT; ··· 352 348 return sizeof(w1_enable_crccheck); 353 349 } 354 350 355 - static ssize_t w1_f1C_store_crccheck(struct device *dev, 356 - struct device_attribute *attr, 357 - const char *buf, size_t count) 351 + static ssize_t crccheck_store(struct device *dev, struct device_attribute *attr, 352 + const char *buf, size_t count) 358 353 { 359 354 char val; 360 355 ··· 374 371 return sizeof(w1_enable_crccheck); 375 372 } 376 373 377 - #define NB_SYSFS_BIN_FILES 2 378 - static struct bin_attribute w1_f1C_bin_attr[NB_SYSFS_BIN_FILES] = { 379 - { 380 - .attr = { 381 - .name = "eeprom", 382 - .mode = S_IRUGO | S_IWUSR, 383 - }, 384 - .size = W1_EEPROM_SIZE, 385 - .read = w1_f1C_read_bin, 386 - .write = w1_f1C_write_bin, 387 - }, 388 - { 389 - .attr = { 390 - .name = "pio", 391 - .mode = S_IRUGO | S_IWUSR, 392 - }, 393 - .size = 1, 394 - .read = w1_f1C_read_pio, 395 - .write = w1_f1C_write_pio, 396 - } 374 + static DEVICE_ATTR_RW(crccheck); 375 + 376 + static struct attribute *w1_f1C_attrs[] = { 377 + &dev_attr_crccheck.attr, 378 + NULL, 397 379 }; 398 380 399 - static DEVICE_ATTR(crccheck, S_IWUSR | S_IRUGO, 400 - w1_f1C_show_crccheck, w1_f1C_store_crccheck); 381 + static struct bin_attribute *w1_f1C_bin_attrs[] = { 382 + &bin_attr_eeprom, 383 + &bin_attr_pio, 384 + NULL, 385 + }; 386 + 387 + static const struct attribute_group w1_f1C_group = { 388 + .attrs = w1_f1C_attrs, 389 + .bin_attrs = w1_f1C_bin_attrs, 390 + }; 391 + 392 + static const struct attribute_group *w1_f1C_groups[] = { 393 + &w1_f1C_group, 394 + NULL, 395 + }; 401 396 402 397 static int w1_f1C_add_slave(struct w1_slave *sl) 403 398 { 404 - int err = 0; 405 - int i; 406 399 struct w1_f1C_data *data = NULL; 407 400 408 401 if (w1_enable_crccheck) { ··· 408 409 sl->family_data = data; 409 410 } 410 411 411 - /* create binary sysfs attributes */ 412 - for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i) 413 - err = sysfs_create_bin_file( 414 - &sl->dev.kobj, &(w1_f1C_bin_attr[i])); 415 - 416 - if (!err) { 417 - /* create device attributes */ 418 - err = device_create_file(&sl->dev, &dev_attr_crccheck); 419 - } 420 - 421 - if (err) { 422 - /* remove binary sysfs attributes */ 423 - for (i = 0; i < NB_SYSFS_BIN_FILES; ++i) 424 - sysfs_remove_bin_file( 425 - &sl->dev.kobj, &(w1_f1C_bin_attr[i])); 426 - 427 - kfree(data); 428 - } 429 - 430 - return err; 412 + return 0; 431 413 } 432 414 433 415 static void w1_f1C_remove_slave(struct w1_slave *sl) 434 416 { 435 - int i; 436 - 437 417 kfree(sl->family_data); 438 418 sl->family_data = NULL; 439 - 440 - /* remove device attributes */ 441 - device_remove_file(&sl->dev, &dev_attr_crccheck); 442 - 443 - /* remove binary sysfs attributes */ 444 - for (i = 0; i < NB_SYSFS_BIN_FILES; ++i) 445 - sysfs_remove_bin_file(&sl->dev.kobj, &(w1_f1C_bin_attr[i])); 446 419 } 447 420 448 421 static struct w1_family_ops w1_f1C_fops = { 449 422 .add_slave = w1_f1C_add_slave, 450 423 .remove_slave = w1_f1C_remove_slave, 424 + .groups = w1_f1C_groups, 451 425 }; 452 426 453 427 static struct w1_family w1_family_1C = {