From a332eeac4d196f927893b21f0d923b89cf545acc Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:04 -0700 Subject: misc: c2port: use dev_bin_attrs instead of hand-coding it Classes support a list of default binary attributes, so use that in the c2port driver, instead of hand creating and destroying the file, which is racing with userspace. Bonus is this removes lines of code. Cc: Rodolfo Giometti Signed-off-by: Greg Kroah-Hartman --- drivers/misc/c2port/core.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index f32550a74bd..a3b8370c7de 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -867,14 +867,17 @@ static struct device_attribute c2port_attrs[] = { __ATTR_NULL, }; -static struct bin_attribute c2port_bin_attrs = { - .attr = { - .name = "flash_data", - .mode = 0644 +static struct bin_attribute c2port_bin_attrs[] = { + { + .attr = { + .name = "flash_data", + .mode = 0644 + }, + .read = c2port_read_flash_data, + .write = c2port_write_flash_data, + /* .size is computed at run-time */ }, - .read = c2port_read_flash_data, - .write = c2port_write_flash_data, - /* .size is computed at run-time */ + __ATTR_NULL }; /* @@ -907,6 +910,8 @@ struct c2port_device *c2port_device_register(char *name, goto error_idr_alloc; c2dev->id = ret; + c2port_bin_attrs[0].size = ops->blocks_num * ops->block_size; + c2dev->dev = device_create(c2port_class, NULL, 0, c2dev, "c2port%d", c2dev->id); if (unlikely(IS_ERR(c2dev->dev))) { @@ -919,12 +924,6 @@ struct c2port_device *c2port_device_register(char *name, c2dev->ops = ops; mutex_init(&c2dev->mutex); - /* Create binary file */ - c2port_bin_attrs.size = ops->blocks_num * ops->block_size; - ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs); - if (unlikely(ret)) - goto error_device_create_bin_file; - /* By default C2 port access is off */ c2dev->access = c2dev->flash_access = 0; ops->access(c2dev, 0); @@ -937,9 +936,6 @@ struct c2port_device *c2port_device_register(char *name, return c2dev; -error_device_create_bin_file: - device_destroy(c2port_class, 0); - error_device_create: spin_lock_irq(&c2port_idr_lock); idr_remove(&c2port_idr, c2dev->id); @@ -959,7 +955,6 @@ void c2port_device_unregister(struct c2port_device *c2dev) dev_info(c2dev->dev, "C2 port %s removed\n", c2dev->name); - device_remove_bin_file(c2dev->dev, &c2port_bin_attrs); spin_lock_irq(&c2port_idr_lock); idr_remove(&c2port_idr, c2dev->id); spin_unlock_irq(&c2port_idr_lock); @@ -985,6 +980,7 @@ static int __init c2port_init(void) return PTR_ERR(c2port_class); } c2port_class->dev_attrs = c2port_attrs; + c2port_class->dev_bin_attrs = c2port_bin_attrs; return 0; } -- cgit v1.2.3-70-g09d2 From 62e13505b4eff7a0e94bdcb1f4fd76cbe4a96ff1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:06 -0700 Subject: bsr: convert bsr_class to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the bsr bsr_class code to use the correct field. Cc: Arnd Bergmann Signed-off-by: Greg Kroah-Hartman --- drivers/char/bsr.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/char/bsr.c b/drivers/char/bsr.c index 97467053a01..0671e45daa5 100644 --- a/drivers/char/bsr.c +++ b/drivers/char/bsr.c @@ -95,6 +95,7 @@ bsr_size_show(struct device *dev, struct device_attribute *attr, char *buf) struct bsr_dev *bsr_dev = dev_get_drvdata(dev); return sprintf(buf, "%u\n", bsr_dev->bsr_bytes); } +static DEVICE_ATTR_RO(bsr_size); static ssize_t bsr_stride_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -102,20 +103,23 @@ bsr_stride_show(struct device *dev, struct device_attribute *attr, char *buf) struct bsr_dev *bsr_dev = dev_get_drvdata(dev); return sprintf(buf, "%u\n", bsr_dev->bsr_stride); } +static DEVICE_ATTR_RO(bsr_stride); static ssize_t -bsr_len_show(struct device *dev, struct device_attribute *attr, char *buf) +bsr_length_show(struct device *dev, struct device_attribute *attr, char *buf) { struct bsr_dev *bsr_dev = dev_get_drvdata(dev); return sprintf(buf, "%llu\n", bsr_dev->bsr_len); } +static DEVICE_ATTR_RO(bsr_length); -static struct device_attribute bsr_dev_attrs[] = { - __ATTR(bsr_size, S_IRUGO, bsr_size_show, NULL), - __ATTR(bsr_stride, S_IRUGO, bsr_stride_show, NULL), - __ATTR(bsr_length, S_IRUGO, bsr_len_show, NULL), - __ATTR_NULL +static struct attribute *bsr_dev_attrs[] = { + &dev_attr_bsr_size.attr, + &dev_attr_bsr_stride.attr, + &dev_attr_bsr_length.attr, + NULL, }; +ATTRIBUTE_GROUPS(bsr_dev); static int bsr_mmap(struct file *filp, struct vm_area_struct *vma) { @@ -308,7 +312,7 @@ static int __init bsr_init(void) ret = PTR_ERR(bsr_class); goto out_err_1; } - bsr_class->dev_attrs = bsr_dev_attrs; + bsr_class->dev_groups = bsr_dev_groups; ret = alloc_chrdev_region(&bsr_dev, 0, BSR_MAX_DEVS, "bsr"); bsr_major = MAJOR(bsr_dev); -- cgit v1.2.3-70-g09d2 From e017a84b9397f50e22ba219d0b2875bf48a6573f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:07 -0700 Subject: tile: srom: convert srom_class to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the tile srom_class code to use the correct field. Cc: Arnd Bergmann Signed-off-by: Greg Kroah-Hartman --- drivers/char/tile-srom.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/char/tile-srom.c b/drivers/char/tile-srom.c index 7faeb1cde97..344e97b9101 100644 --- a/drivers/char/tile-srom.c +++ b/drivers/char/tile-srom.c @@ -279,33 +279,37 @@ loff_t srom_llseek(struct file *file, loff_t offset, int origin) return fixed_size_llseek(file, offset, origin, srom->total_size); } -static ssize_t total_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t total_size_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct srom_dev *srom = dev_get_drvdata(dev); return sprintf(buf, "%u\n", srom->total_size); } +static DEVICE_ATTR_RO(total_size); -static ssize_t sector_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t sector_size_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct srom_dev *srom = dev_get_drvdata(dev); return sprintf(buf, "%u\n", srom->sector_size); } +static DEVICE_ATTR_RO(sector_size); -static ssize_t page_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t page_size_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct srom_dev *srom = dev_get_drvdata(dev); return sprintf(buf, "%u\n", srom->page_size); } +static DEVICE_ATTR_RO(page_size); -static struct device_attribute srom_dev_attrs[] = { - __ATTR(total_size, S_IRUGO, total_show, NULL), - __ATTR(sector_size, S_IRUGO, sector_show, NULL), - __ATTR(page_size, S_IRUGO, page_show, NULL), - __ATTR_NULL +static struct attribute srom_dev_attrs[] = { + &dev_attr_total_size.attr, + &dev_attr_sector_size.attr, + &dev_attr_page_size.attr, + NULL, }; +ATTRIBUTE_GROUPS(srom_dev); static char *srom_devnode(struct device *dev, umode_t *mode) { @@ -418,7 +422,7 @@ static int srom_init(void) result = PTR_ERR(srom_class); goto fail_cdev; } - srom_class->dev_attrs = srom_dev_attrs; + srom_class->dev_groups = srom_dev_groups; srom_class->devnode = srom_devnode; /* Do per-partition initialization */ -- cgit v1.2.3-70-g09d2 From eb375597e2d456499bfa427fb398ab36bdc837e5 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:15 -0700 Subject: c2port: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the c2port class code to use the correct field. Cc: Rodolfo Giometti Signed-off-by: Greg Kroah-Hartman --- drivers/misc/c2port/core.c | 50 +++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index a3b8370c7de..abe6e251e36 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -311,6 +311,7 @@ static ssize_t c2port_show_name(struct device *dev, return sprintf(buf, "%s\n", c2dev->name); } +static DEVICE_ATTR(name, 0444, c2port_show_name, NULL); static ssize_t c2port_show_flash_blocks_num(struct device *dev, struct device_attribute *attr, char *buf) @@ -320,6 +321,7 @@ static ssize_t c2port_show_flash_blocks_num(struct device *dev, return sprintf(buf, "%d\n", ops->blocks_num); } +static DEVICE_ATTR(flash_blocks_num, 0444, c2port_show_flash_blocks_num, NULL); static ssize_t c2port_show_flash_block_size(struct device *dev, struct device_attribute *attr, char *buf) @@ -329,6 +331,7 @@ static ssize_t c2port_show_flash_block_size(struct device *dev, return sprintf(buf, "%d\n", ops->block_size); } +static DEVICE_ATTR(flash_block_size, 0444, c2port_show_flash_block_size, NULL); static ssize_t c2port_show_flash_size(struct device *dev, struct device_attribute *attr, char *buf) @@ -338,18 +341,18 @@ static ssize_t c2port_show_flash_size(struct device *dev, return sprintf(buf, "%d\n", ops->blocks_num * ops->block_size); } +static DEVICE_ATTR(flash_size, 0444, c2port_show_flash_size, NULL); -static ssize_t c2port_show_access(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t access_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct c2port_device *c2dev = dev_get_drvdata(dev); return sprintf(buf, "%d\n", c2dev->access); } -static ssize_t c2port_store_access(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t access_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { struct c2port_device *c2dev = dev_get_drvdata(dev); struct c2port_ops *ops = c2dev->ops; @@ -375,6 +378,7 @@ static ssize_t c2port_store_access(struct device *dev, return count; } +static DEVICE_ATTR_RW(access); static ssize_t c2port_store_reset(struct device *dev, struct device_attribute *attr, @@ -395,6 +399,7 @@ static ssize_t c2port_store_reset(struct device *dev, return count; } +static DEVICE_ATTR(reset, 0200, NULL, c2port_store_reset); static ssize_t __c2port_show_dev_id(struct c2port_device *dev, char *buf) { @@ -431,6 +436,7 @@ static ssize_t c2port_show_dev_id(struct device *dev, return ret; } +static DEVICE_ATTR(dev_id, 0444, c2port_show_dev_id, NULL); static ssize_t __c2port_show_rev_id(struct c2port_device *dev, char *buf) { @@ -467,6 +473,7 @@ static ssize_t c2port_show_rev_id(struct device *dev, return ret; } +static DEVICE_ATTR(rev_id, 0444, c2port_show_rev_id, NULL); static ssize_t c2port_show_flash_access(struct device *dev, struct device_attribute *attr, char *buf) @@ -536,6 +543,8 @@ static ssize_t c2port_store_flash_access(struct device *dev, return count; } +static DEVICE_ATTR(flash_access, 0644, c2port_show_flash_access, + c2port_store_flash_access); static ssize_t __c2port_write_flash_erase(struct c2port_device *dev) { @@ -616,6 +625,7 @@ static ssize_t c2port_store_flash_erase(struct device *dev, return count; } +static DEVICE_ATTR(flash_erase, 0200, NULL, c2port_store_flash_erase); static ssize_t __c2port_read_flash_data(struct c2port_device *dev, char *buffer, loff_t offset, size_t count) @@ -850,22 +860,20 @@ static ssize_t c2port_write_flash_data(struct file *filp, struct kobject *kobj, /* * Class attributes */ - -static struct device_attribute c2port_attrs[] = { - __ATTR(name, 0444, c2port_show_name, NULL), - __ATTR(flash_blocks_num, 0444, c2port_show_flash_blocks_num, NULL), - __ATTR(flash_block_size, 0444, c2port_show_flash_block_size, NULL), - __ATTR(flash_size, 0444, c2port_show_flash_size, NULL), - __ATTR(access, 0644, c2port_show_access, c2port_store_access), - __ATTR(reset, 0200, NULL, c2port_store_reset), - __ATTR(dev_id, 0444, c2port_show_dev_id, NULL), - __ATTR(rev_id, 0444, c2port_show_rev_id, NULL), - - __ATTR(flash_access, 0644, c2port_show_flash_access, - c2port_store_flash_access), - __ATTR(flash_erase, 0200, NULL, c2port_store_flash_erase), - __ATTR_NULL, +static struct attribute *c2port_attrs[] = { + &dev_attr_name.attr, + &dev_attr_flash_blocks_num.attr, + &dev_attr_flash_block_size.attr, + &dev_attr_flash_size.attr, + &dev_attr_access.attr, + &dev_attr_reset.attr, + &dev_attr_dev_id.attr, + &dev_attr_rev_id.attr, + &dev_attr_flash_access.attr, + &dev_attr_flash_erase.attr, + NULL, }; +ATTRIBUTE_GROUPS(c2port); static struct bin_attribute c2port_bin_attrs[] = { { @@ -979,7 +987,7 @@ static int __init c2port_init(void) printk(KERN_ERR "c2port: failed to allocate class\n"); return PTR_ERR(c2port_class); } - c2port_class->dev_attrs = c2port_attrs; + c2port_class->dev_groups = c2port_groups; c2port_class->dev_bin_attrs = c2port_bin_attrs; return 0; -- cgit v1.2.3-70-g09d2 From 899826f16a034f1ab6d23cd5b60cd113eaefad19 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:16 -0700 Subject: enclosure: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the enclosure class code to use the correct field. Cc: Arnd Bergmann Signed-off-by: Greg Kroah-Hartman --- drivers/misc/enclosure.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c index 00e5fcac8fd..0e8df41aaf1 100644 --- a/drivers/misc/enclosure.c +++ b/drivers/misc/enclosure.c @@ -239,7 +239,7 @@ static void enclosure_component_release(struct device *dev) put_device(dev->parent); } -static const struct attribute_group *enclosure_groups[]; +static const struct attribute_group *enclosure_component_groups[]; /** * enclosure_component_register - add a particular component to an enclosure @@ -282,7 +282,7 @@ enclosure_component_register(struct enclosure_device *edev, dev_set_name(cdev, "%u", number); cdev->release = enclosure_component_release; - cdev->groups = enclosure_groups; + cdev->groups = enclosure_component_groups; err = device_register(cdev); if (err) { @@ -365,25 +365,26 @@ EXPORT_SYMBOL_GPL(enclosure_remove_device); * sysfs pieces below */ -static ssize_t enclosure_show_components(struct device *cdev, - struct device_attribute *attr, - char *buf) +static ssize_t components_show(struct device *cdev, + struct device_attribute *attr, char *buf) { struct enclosure_device *edev = to_enclosure_device(cdev); return snprintf(buf, 40, "%d\n", edev->components); } +static DEVICE_ATTR_RO(components); -static struct device_attribute enclosure_attrs[] = { - __ATTR(components, S_IRUGO, enclosure_show_components, NULL), - __ATTR_NULL +static struct attribute *enclosure_class_attrs[] = { + &dev_attr_components.attr, + NULL, }; +ATTRIBUTE_GROUPS(enclosure_class); static struct class enclosure_class = { .name = "enclosure", .owner = THIS_MODULE, .dev_release = enclosure_release, - .dev_attrs = enclosure_attrs, + .dev_groups = enclosure_class_groups, }; static const char *const enclosure_status [] = { @@ -536,15 +537,7 @@ static struct attribute *enclosure_component_attrs[] = { &dev_attr_type.attr, NULL }; - -static struct attribute_group enclosure_group = { - .attrs = enclosure_component_attrs, -}; - -static const struct attribute_group *enclosure_groups[] = { - &enclosure_group, - NULL -}; +ATTRIBUTE_GROUPS(enclosure_component); static int __init enclosure_init(void) { -- cgit v1.2.3-70-g09d2 From c9dce927e96c002856ac93b3a43115c33b6c1a74 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:23 -0700 Subject: UIO: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the uio class code to use the correct field. Cc: Hans J. Koch Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 3b96f18593b..170a178d661 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -224,38 +224,42 @@ static struct kobj_type portio_attr_type = { .default_attrs = portio_attrs, }; -static ssize_t show_name(struct device *dev, +static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) { struct uio_device *idev = dev_get_drvdata(dev); return sprintf(buf, "%s\n", idev->info->name); } +static DEVICE_ATTR_RO(name); -static ssize_t show_version(struct device *dev, +static ssize_t version_show(struct device *dev, struct device_attribute *attr, char *buf) { struct uio_device *idev = dev_get_drvdata(dev); return sprintf(buf, "%s\n", idev->info->version); } +static DEVICE_ATTR_RO(version); -static ssize_t show_event(struct device *dev, +static ssize_t event_show(struct device *dev, struct device_attribute *attr, char *buf) { struct uio_device *idev = dev_get_drvdata(dev); return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event)); } +static DEVICE_ATTR_RO(event); -static struct device_attribute uio_class_attributes[] = { - __ATTR(name, S_IRUGO, show_name, NULL), - __ATTR(version, S_IRUGO, show_version, NULL), - __ATTR(event, S_IRUGO, show_event, NULL), - {} +static struct attribute *uio_attrs[] = { + &dev_attr_name.attr, + &dev_attr_version.attr, + &dev_attr_event.attr, + NULL, }; +ATTRIBUTE_GROUPS(uio); /* UIO class infrastructure */ static struct class uio_class = { .name = "uio", - .dev_attrs = uio_class_attributes, + .dev_groups = uio_groups, }; /* -- cgit v1.2.3-70-g09d2 From e56341ad380114454119ac043e6d710ddbbb7710 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:25 -0700 Subject: staging: comedi: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the comedi class code to use the correct field. Cc: Ian Abbott Reviewed-by: H Hartley Sweeten Acked-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/comedi_fops.c | 39 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'drivers') diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 8647518259f..2f2ff8f0878 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -262,7 +262,7 @@ static int resize_async_buffer(struct comedi_device *dev, /* sysfs attribute files */ -static ssize_t show_max_read_buffer_kb(struct device *csdev, +static ssize_t max_read_buffer_kb_show(struct device *csdev, struct device_attribute *attr, char *buf) { unsigned int minor = MINOR(csdev->devt); @@ -283,7 +283,7 @@ static ssize_t show_max_read_buffer_kb(struct device *csdev, return snprintf(buf, PAGE_SIZE, "%i\n", size); } -static ssize_t store_max_read_buffer_kb(struct device *csdev, +static ssize_t max_read_buffer_kb_store(struct device *csdev, struct device_attribute *attr, const char *buf, size_t count) { @@ -314,8 +314,9 @@ static ssize_t store_max_read_buffer_kb(struct device *csdev, return err ? err : count; } +static DEVICE_ATTR_RW(max_read_buffer_kb); -static ssize_t show_read_buffer_kb(struct device *csdev, +static ssize_t read_buffer_kb_show(struct device *csdev, struct device_attribute *attr, char *buf) { unsigned int minor = MINOR(csdev->devt); @@ -336,7 +337,7 @@ static ssize_t show_read_buffer_kb(struct device *csdev, return snprintf(buf, PAGE_SIZE, "%i\n", size); } -static ssize_t store_read_buffer_kb(struct device *csdev, +static ssize_t read_buffer_kb_store(struct device *csdev, struct device_attribute *attr, const char *buf, size_t count) { @@ -367,8 +368,9 @@ static ssize_t store_read_buffer_kb(struct device *csdev, return err ? err : count; } +static DEVICE_ATTR_RW(read_buffer_kb); -static ssize_t show_max_write_buffer_kb(struct device *csdev, +static ssize_t max_write_buffer_kb_show(struct device *csdev, struct device_attribute *attr, char *buf) { @@ -390,7 +392,7 @@ static ssize_t show_max_write_buffer_kb(struct device *csdev, return snprintf(buf, PAGE_SIZE, "%i\n", size); } -static ssize_t store_max_write_buffer_kb(struct device *csdev, +static ssize_t max_write_buffer_kb_store(struct device *csdev, struct device_attribute *attr, const char *buf, size_t count) { @@ -421,8 +423,9 @@ static ssize_t store_max_write_buffer_kb(struct device *csdev, return err ? err : count; } +static DEVICE_ATTR_RW(max_write_buffer_kb); -static ssize_t show_write_buffer_kb(struct device *csdev, +static ssize_t write_buffer_kb_show(struct device *csdev, struct device_attribute *attr, char *buf) { unsigned int minor = MINOR(csdev->devt); @@ -443,7 +446,7 @@ static ssize_t show_write_buffer_kb(struct device *csdev, return snprintf(buf, PAGE_SIZE, "%i\n", size); } -static ssize_t store_write_buffer_kb(struct device *csdev, +static ssize_t write_buffer_kb_store(struct device *csdev, struct device_attribute *attr, const char *buf, size_t count) { @@ -474,18 +477,16 @@ static ssize_t store_write_buffer_kb(struct device *csdev, return err ? err : count; } +static DEVICE_ATTR_RW(write_buffer_kb); -static struct device_attribute comedi_dev_attrs[] = { - __ATTR(max_read_buffer_kb, S_IRUGO | S_IWUSR, - show_max_read_buffer_kb, store_max_read_buffer_kb), - __ATTR(read_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP, - show_read_buffer_kb, store_read_buffer_kb), - __ATTR(max_write_buffer_kb, S_IRUGO | S_IWUSR, - show_max_write_buffer_kb, store_max_write_buffer_kb), - __ATTR(write_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP, - show_write_buffer_kb, store_write_buffer_kb), - __ATTR_NULL +static struct attribute *comedi_dev_attrs[] = { + &dev_attr_max_read_buffer_kb.attr, + &dev_attr_read_buffer_kb.attr, + &dev_attr_max_write_buffer_kb.attr, + &dev_attr_write_buffer_kb.attr, + NULL, }; +ATTRIBUTE_GROUPS(comedi_dev); static void comedi_set_subdevice_runflags(struct comedi_subdevice *s, unsigned mask, unsigned bits) @@ -2554,7 +2555,7 @@ static int __init comedi_init(void) return PTR_ERR(comedi_class); } - comedi_class->dev_attrs = comedi_dev_attrs; + comedi_class->dev_groups = comedi_dev_groups; /* XXX requires /proc interface */ comedi_proc_init(); -- cgit v1.2.3-70-g09d2 From ac3785d5c15922c8a4c6b9e050a5bc59895a6b9b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:37 -0700 Subject: c2port: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Rodolfo Giometti Signed-off-by: Greg Kroah-Hartman --- drivers/misc/c2port/core.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c index abe6e251e36..464419b3644 100644 --- a/drivers/misc/c2port/core.c +++ b/drivers/misc/c2port/core.c @@ -856,6 +856,9 @@ static ssize_t c2port_write_flash_data(struct file *filp, struct kobject *kobj, return ret; } +/* size is computed at run-time */ +static BIN_ATTR(flash_data, 0644, c2port_read_flash_data, + c2port_write_flash_data, 0); /* * Class attributes @@ -873,19 +876,20 @@ static struct attribute *c2port_attrs[] = { &dev_attr_flash_erase.attr, NULL, }; -ATTRIBUTE_GROUPS(c2port); - -static struct bin_attribute c2port_bin_attrs[] = { - { - .attr = { - .name = "flash_data", - .mode = 0644 - }, - .read = c2port_read_flash_data, - .write = c2port_write_flash_data, - /* .size is computed at run-time */ - }, - __ATTR_NULL + +static struct bin_attribute *c2port_bin_attrs[] = { + &bin_attr_flash_data, + NULL, +}; + +static const struct attribute_group c2port_group = { + .attrs = c2port_attrs, + .bin_attrs = c2port_bin_attrs, +}; + +static const struct attribute_group *c2port_groups[] = { + &c2port_group, + NULL, }; /* @@ -918,7 +922,7 @@ struct c2port_device *c2port_device_register(char *name, goto error_idr_alloc; c2dev->id = ret; - c2port_bin_attrs[0].size = ops->blocks_num * ops->block_size; + bin_attr_flash_data.size = ops->blocks_num * ops->block_size; c2dev->dev = device_create(c2port_class, NULL, 0, c2dev, "c2port%d", c2dev->id); @@ -988,7 +992,6 @@ static int __init c2port_init(void) return PTR_ERR(c2port_class); } c2port_class->dev_groups = c2port_groups; - c2port_class->dev_bin_attrs = c2port_bin_attrs; return 0; } -- cgit v1.2.3-70-g09d2 From 7c42721fe0c58a848849b43ff558cf2fb86aa35a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 25 Jul 2013 13:50:30 -0700 Subject: char: tile-srom: fix build error This fixes the build error: drivers/char/tile-srom.c:307:2: warning: missing braces around initializer [-Wmissing-braces] and the resulting fallout for the missing '*' character, sorry, my fault... Reported-by: kbuild test robot Signed-off-by: Greg Kroah-Hartman --- drivers/char/tile-srom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/char/tile-srom.c b/drivers/char/tile-srom.c index 344e97b9101..ae82933883b 100644 --- a/drivers/char/tile-srom.c +++ b/drivers/char/tile-srom.c @@ -303,7 +303,7 @@ static ssize_t page_size_show(struct device *dev, } static DEVICE_ATTR_RO(page_size); -static struct attribute srom_dev_attrs[] = { +static struct attribute *srom_dev_attrs[] = { &dev_attr_total_size.attr, &dev_attr_sector_size.attr, &dev_attr_page_size.attr, -- cgit v1.2.3-70-g09d2 From 58b267d3e3f3ce87c3e559e4c330c8c03e905f5e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:08 -0700 Subject: dma: convert dma_devclass to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the dma dma_devclass code to use the correct field. Cc: Dan Williams Acked-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/dmaengine.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c index 9e56745f87b..99af4db5948 100644 --- a/drivers/dma/dmaengine.c +++ b/drivers/dma/dmaengine.c @@ -87,7 +87,8 @@ static struct dma_chan *dev_to_dma_chan(struct device *dev) return chan_dev->chan; } -static ssize_t show_memcpy_count(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t memcpy_count_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct dma_chan *chan; unsigned long count = 0; @@ -106,9 +107,10 @@ static ssize_t show_memcpy_count(struct device *dev, struct device_attribute *at return err; } +static DEVICE_ATTR_RO(memcpy_count); -static ssize_t show_bytes_transferred(struct device *dev, struct device_attribute *attr, - char *buf) +static ssize_t bytes_transferred_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct dma_chan *chan; unsigned long count = 0; @@ -127,8 +129,10 @@ static ssize_t show_bytes_transferred(struct device *dev, struct device_attribut return err; } +static DEVICE_ATTR_RO(bytes_transferred); -static ssize_t show_in_use(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t in_use_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct dma_chan *chan; int err; @@ -143,13 +147,15 @@ static ssize_t show_in_use(struct device *dev, struct device_attribute *attr, ch return err; } +static DEVICE_ATTR_RO(in_use); -static struct device_attribute dma_attrs[] = { - __ATTR(memcpy_count, S_IRUGO, show_memcpy_count, NULL), - __ATTR(bytes_transferred, S_IRUGO, show_bytes_transferred, NULL), - __ATTR(in_use, S_IRUGO, show_in_use, NULL), - __ATTR_NULL +static struct attribute *dma_dev_attrs[] = { + &dev_attr_memcpy_count.attr, + &dev_attr_bytes_transferred.attr, + &dev_attr_in_use.attr, + NULL, }; +ATTRIBUTE_GROUPS(dma_dev); static void chan_dev_release(struct device *dev) { @@ -167,7 +173,7 @@ static void chan_dev_release(struct device *dev) static struct class dma_devclass = { .name = "dma", - .dev_attrs = dma_attrs, + .dev_groups = dma_dev_groups, .dev_release = chan_dev_release, }; -- cgit v1.2.3-70-g09d2 From af01da0e02def46c7f32f86811d6befb6ca16170 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:10 -0700 Subject: extcon: convert extcon_class to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the extcon_class code to use the correct field. Cc: MyungJoo Ham Acked-by: Chanwoo Choi Signed-off-by: Greg Kroah-Hartman --- drivers/extcon/extcon-class.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index 18ccadef43f..022ca369834 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c @@ -148,6 +148,7 @@ static ssize_t state_store(struct device *dev, struct device_attribute *attr, return count; } +static DEVICE_ATTR_RW(state); static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -163,6 +164,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, return sprintf(buf, "%s\n", dev_name(edev->dev)); } +static DEVICE_ATTR_RO(name); static ssize_t cable_name_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -527,11 +529,12 @@ int extcon_unregister_notifier(struct extcon_dev *edev, } EXPORT_SYMBOL_GPL(extcon_unregister_notifier); -static struct device_attribute extcon_attrs[] = { - __ATTR(state, S_IRUGO | S_IWUSR, state_show, state_store), - __ATTR_RO(name), - __ATTR_NULL, +static struct attribute *extcon_attrs[] = { + &dev_attr_state.attr, + &dev_attr_name.attr, + NULL, }; +ATTRIBUTE_GROUPS(extcon); static int create_extcon_class(void) { @@ -539,7 +542,7 @@ static int create_extcon_class(void) extcon_class = class_create(THIS_MODULE, "extcon"); if (IS_ERR(extcon_class)) return PTR_ERR(extcon_class); - extcon_class->dev_attrs = extcon_attrs; + extcon_class->dev_groups = extcon_groups; #if defined(CONFIG_ANDROID) switch_class = class_compat_register("switch"); -- cgit v1.2.3-70-g09d2 From 92a3e661bf55457091817c5c346c4313be2508af Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:27 -0700 Subject: SCSI: OSD: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the scsi osd class code to use the correct field. Acked-by: Boaz Harrosh Cc: Benny Halevy Cc: James E.J. Bottomley Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/osd/osd_uld.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c index 9d86947d67f..e1d9a4c4c4b 100644 --- a/drivers/scsi/osd/osd_uld.c +++ b/drivers/scsi/osd/osd_uld.c @@ -107,6 +107,7 @@ static ssize_t osdname_show(struct device *dev, struct device_attribute *attr, class_dev); return sprintf(buf, "%s\n", ould->odi.osdname); } +static DEVICE_ATTR_RO(osdname); static ssize_t systemid_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -117,17 +118,19 @@ static ssize_t systemid_show(struct device *dev, struct device_attribute *attr, memcpy(buf, ould->odi.systemid, ould->odi.systemid_len); return ould->odi.systemid_len; } +static DEVICE_ATTR_RO(systemid); -static struct device_attribute osd_uld_attrs[] = { - __ATTR(osdname, S_IRUGO, osdname_show, NULL), - __ATTR(systemid, S_IRUGO, systemid_show, NULL), - __ATTR_NULL, +static struct attribute *osd_uld_attrs[] = { + &dev_attr_osdname.attr, + &dev_attr_systemid.attr, + NULL, }; +ATTRIBUTE_GROUPS(osd_uld); static struct class osd_uld_class = { .owner = THIS_MODULE, .name = "scsi_osd", - .dev_attrs = osd_uld_attrs, + .dev_groups = osd_uld_groups, }; /* -- cgit v1.2.3-70-g09d2 From ea1bb7064fd6972ef00a93ba882a2f38450b273e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:30 -0700 Subject: video: backlight: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the video backlight class code to use the correct field. Cc: Richard Purdie Acked-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/video/backlight/backlight.c | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'drivers') diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index 3fccb6d3c8c..94a403a9717 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -103,16 +103,16 @@ static void backlight_generate_event(struct backlight_device *bd, sysfs_notify(&bd->dev.kobj, NULL, "actual_brightness"); } -static ssize_t backlight_show_power(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t bl_power_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct backlight_device *bd = to_backlight_device(dev); return sprintf(buf, "%d\n", bd->props.power); } -static ssize_t backlight_store_power(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) +static ssize_t bl_power_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { int rc; struct backlight_device *bd = to_backlight_device(dev); @@ -136,8 +136,9 @@ static ssize_t backlight_store_power(struct device *dev, return rc; } +static DEVICE_ATTR_RW(bl_power); -static ssize_t backlight_show_brightness(struct device *dev, +static ssize_t brightness_show(struct device *dev, struct device_attribute *attr, char *buf) { struct backlight_device *bd = to_backlight_device(dev); @@ -145,7 +146,7 @@ static ssize_t backlight_show_brightness(struct device *dev, return sprintf(buf, "%d\n", bd->props.brightness); } -static ssize_t backlight_store_brightness(struct device *dev, +static ssize_t brightness_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int rc; @@ -175,24 +176,27 @@ static ssize_t backlight_store_brightness(struct device *dev, return rc; } +static DEVICE_ATTR_RW(brightness); -static ssize_t backlight_show_type(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t type_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct backlight_device *bd = to_backlight_device(dev); return sprintf(buf, "%s\n", backlight_types[bd->props.type]); } +static DEVICE_ATTR_RO(type); -static ssize_t backlight_show_max_brightness(struct device *dev, +static ssize_t max_brightness_show(struct device *dev, struct device_attribute *attr, char *buf) { struct backlight_device *bd = to_backlight_device(dev); return sprintf(buf, "%d\n", bd->props.max_brightness); } +static DEVICE_ATTR_RO(max_brightness); -static ssize_t backlight_show_actual_brightness(struct device *dev, +static ssize_t actual_brightness_show(struct device *dev, struct device_attribute *attr, char *buf) { int rc = -ENXIO; @@ -205,6 +209,7 @@ static ssize_t backlight_show_actual_brightness(struct device *dev, return rc; } +static DEVICE_ATTR_RO(actual_brightness); static struct class *backlight_class; @@ -247,16 +252,15 @@ static void bl_device_release(struct device *dev) kfree(bd); } -static struct device_attribute bl_device_attributes[] = { - __ATTR(bl_power, 0644, backlight_show_power, backlight_store_power), - __ATTR(brightness, 0644, backlight_show_brightness, - backlight_store_brightness), - __ATTR(actual_brightness, 0444, backlight_show_actual_brightness, - NULL), - __ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), - __ATTR(type, 0444, backlight_show_type, NULL), - __ATTR_NULL, +static struct attribute *bl_device_attrs[] = { + &dev_attr_bl_power.attr, + &dev_attr_brightness.attr, + &dev_attr_actual_brightness.attr, + &dev_attr_max_brightness.attr, + &dev_attr_type.attr, + NULL, }; +ATTRIBUTE_GROUPS(bl_device); /** * backlight_force_update - tell the backlight subsystem that hardware state @@ -493,7 +497,7 @@ static int __init backlight_class_init(void) return PTR_ERR(backlight_class); } - backlight_class->dev_attrs = bl_device_attributes; + backlight_class->dev_groups = bl_device_groups; backlight_class->pm = &backlight_class_dev_pm_ops; return 0; } -- cgit v1.2.3-70-g09d2 From d79fd03fd651bd91a081fc97f5f0d221557f8cbb Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:31 -0700 Subject: video: backlight: lcd: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the video backlight lcd class code to use the correct field. Cc: Richard Purdie Acked-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/video/backlight/lcd.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c index 41964a71a03..93cf15efc71 100644 --- a/drivers/video/backlight/lcd.c +++ b/drivers/video/backlight/lcd.c @@ -89,7 +89,7 @@ static inline void lcd_unregister_fb(struct lcd_device *ld) } #endif /* CONFIG_FB */ -static ssize_t lcd_show_power(struct device *dev, struct device_attribute *attr, +static ssize_t lcd_power_show(struct device *dev, struct device_attribute *attr, char *buf) { int rc; @@ -105,7 +105,7 @@ static ssize_t lcd_show_power(struct device *dev, struct device_attribute *attr, return rc; } -static ssize_t lcd_store_power(struct device *dev, +static ssize_t lcd_power_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int rc; @@ -128,8 +128,9 @@ static ssize_t lcd_store_power(struct device *dev, return rc; } +static DEVICE_ATTR_RW(lcd_power); -static ssize_t lcd_show_contrast(struct device *dev, +static ssize_t contrast_show(struct device *dev, struct device_attribute *attr, char *buf) { int rc = -ENXIO; @@ -143,7 +144,7 @@ static ssize_t lcd_show_contrast(struct device *dev, return rc; } -static ssize_t lcd_store_contrast(struct device *dev, +static ssize_t contrast_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int rc; @@ -166,14 +167,16 @@ static ssize_t lcd_store_contrast(struct device *dev, return rc; } +static DEVICE_ATTR_RW(contrast); -static ssize_t lcd_show_max_contrast(struct device *dev, +static ssize_t max_contrast_show(struct device *dev, struct device_attribute *attr, char *buf) { struct lcd_device *ld = to_lcd_device(dev); return sprintf(buf, "%d\n", ld->props.max_contrast); } +static DEVICE_ATTR_RO(max_contrast); static struct class *lcd_class; @@ -183,12 +186,13 @@ static void lcd_device_release(struct device *dev) kfree(ld); } -static struct device_attribute lcd_device_attributes[] = { - __ATTR(lcd_power, 0644, lcd_show_power, lcd_store_power), - __ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast), - __ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL), - __ATTR_NULL, +static struct attribute *lcd_device_attrs[] = { + &dev_attr_lcd_power.attr, + &dev_attr_contrast.attr, + &dev_attr_max_contrast.attr, + NULL, }; +ATTRIBUTE_GROUPS(lcd_device); /** * lcd_device_register - register a new object of lcd_device class. @@ -344,7 +348,7 @@ static int __init lcd_class_init(void) return PTR_ERR(lcd_class); } - lcd_class->dev_attrs = lcd_device_attributes; + lcd_class->dev_groups = lcd_device_groups; return 0; } -- cgit v1.2.3-70-g09d2 From 86df268705696ce2286410f1493e294e889bdce6 Mon Sep 17 00:00:00 2001 From: David Graham White Date: Sun, 21 Jul 2013 20:41:14 -0400 Subject: drivers:base:core: Moved sym export macros to respective functions Moved 11 calls to the EXPORT_SYMBOL_GPL beneath their respective functions per checkpatch.pl warnings. Signed-off-by: David Graham White Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/base/core.c b/drivers/base/core.c index 8856d74545d..4b9b0d7f602 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -626,6 +626,7 @@ int device_create_file(struct device *dev, return error; } +EXPORT_SYMBOL_GPL(device_create_file); /** * device_remove_file - remove sysfs attribute file. @@ -638,6 +639,7 @@ void device_remove_file(struct device *dev, if (dev) sysfs_remove_file(&dev->kobj, &attr->attr); } +EXPORT_SYMBOL_GPL(device_remove_file); /** * device_create_bin_file - create sysfs binary attribute file for device. @@ -748,6 +750,7 @@ void device_initialize(struct device *dev) device_pm_init(dev); set_dev_node(dev, -1); } +EXPORT_SYMBOL_GPL(device_initialize); struct kobject *virtual_device_parent(struct device *dev) { @@ -1187,6 +1190,7 @@ name_error: dev->p = NULL; goto done; } +EXPORT_SYMBOL_GPL(device_add); /** * device_register - register a device with the system. @@ -1211,6 +1215,7 @@ int device_register(struct device *dev) device_initialize(dev); return device_add(dev); } +EXPORT_SYMBOL_GPL(device_register); /** * get_device - increment reference count for device. @@ -1224,6 +1229,7 @@ struct device *get_device(struct device *dev) { return dev ? kobj_to_dev(kobject_get(&dev->kobj)) : NULL; } +EXPORT_SYMBOL_GPL(get_device); /** * put_device - decrement reference count. @@ -1235,6 +1241,7 @@ void put_device(struct device *dev) if (dev) kobject_put(&dev->kobj); } +EXPORT_SYMBOL_GPL(put_device); /** * device_del - delete device from system. @@ -1297,6 +1304,7 @@ void device_del(struct device *dev) kobject_del(&dev->kobj); put_device(parent); } +EXPORT_SYMBOL_GPL(device_del); /** * device_unregister - unregister device from system. @@ -1315,6 +1323,7 @@ void device_unregister(struct device *dev) device_del(dev); put_device(dev); } +EXPORT_SYMBOL_GPL(device_unregister); static struct device *next_device(struct klist_iter *i) { @@ -1403,6 +1412,7 @@ int device_for_each_child(struct device *parent, void *data, klist_iter_exit(&i); return error; } +EXPORT_SYMBOL_GPL(device_for_each_child); /** * device_find_child - device iterator for locating a particular device. @@ -1437,6 +1447,7 @@ struct device *device_find_child(struct device *parent, void *data, klist_iter_exit(&i); return child; } +EXPORT_SYMBOL_GPL(device_find_child); int __init devices_init(void) { @@ -1464,21 +1475,6 @@ int __init devices_init(void) return -ENOMEM; } -EXPORT_SYMBOL_GPL(device_for_each_child); -EXPORT_SYMBOL_GPL(device_find_child); - -EXPORT_SYMBOL_GPL(device_initialize); -EXPORT_SYMBOL_GPL(device_add); -EXPORT_SYMBOL_GPL(device_register); - -EXPORT_SYMBOL_GPL(device_del); -EXPORT_SYMBOL_GPL(device_unregister); -EXPORT_SYMBOL_GPL(get_device); -EXPORT_SYMBOL_GPL(put_device); - -EXPORT_SYMBOL_GPL(device_create_file); -EXPORT_SYMBOL_GPL(device_remove_file); - static DEFINE_MUTEX(device_hotplug_lock); void lock_device_hotplug(void) -- cgit v1.2.3-70-g09d2 From 34da5e6770ac06df770a0355b417155e6e84e263 Mon Sep 17 00:00:00 2001 From: Jingoo Han Date: Fri, 26 Jul 2013 13:10:22 +0900 Subject: driver core: replace strict_strto*() with kstrto*() The usage of strict_strto*() is not preferred, because strict_strto*() is obsolete. Thus, kstrto*() should be used. Signed-off-by: Jingoo Han Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 2 +- drivers/base/memory.c | 4 ++-- drivers/base/power/sysfs.c | 2 +- drivers/base/regmap/regmap-debugfs.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/base/core.c b/drivers/base/core.c index 4b9b0d7f602..e51c7878293 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -38,7 +38,7 @@ long sysfs_deprecated = 0; #endif static __init int sysfs_deprecated_setup(char *arg) { - return strict_strtol(arg, 10, &sysfs_deprecated); + return kstrtol(arg, 10, &sysfs_deprecated); } early_param("sysfs.deprecated", sysfs_deprecated_setup); #endif diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 2b7813ec6d0..ddd14ce6654 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -469,7 +469,7 @@ store_soft_offline_page(struct device *dev, u64 pfn; if (!capable(CAP_SYS_ADMIN)) return -EPERM; - if (strict_strtoull(buf, 0, &pfn) < 0) + if (kstrtoull(buf, 0, &pfn) < 0) return -EINVAL; pfn >>= PAGE_SHIFT; if (!pfn_valid(pfn)) @@ -488,7 +488,7 @@ store_hard_offline_page(struct device *dev, u64 pfn; if (!capable(CAP_SYS_ADMIN)) return -EPERM; - if (strict_strtoull(buf, 0, &pfn) < 0) + if (kstrtoull(buf, 0, &pfn) < 0) return -EINVAL; pfn >>= PAGE_SHIFT; ret = memory_failure(pfn, 0, 0); diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index a53ebd26570..03e089ade5c 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c @@ -206,7 +206,7 @@ static ssize_t autosuspend_delay_ms_store(struct device *dev, if (!dev->power.use_autosuspend) return -EIO; - if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay) + if (kstrtol(buf, 10, &delay) != 0 || delay != (int) delay) return -EINVAL; device_lock(dev); diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 53495753fbd..634164da9c1 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -281,7 +281,7 @@ static ssize_t regmap_map_write_file(struct file *file, reg = simple_strtoul(start, &start, 16); while (*start == ' ') start++; - if (strict_strtoul(start, 16, &value)) + if (kstrtoul(start, 16, &value)) return -EINVAL; /* Userspace has been fiddling around behind the kernel's back */ -- cgit v1.2.3-70-g09d2 From d98259cbf9f1c86e921caa1241aa8d229249e0b8 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:12 -0700 Subject: ISDN: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the mISDN class code to use the correct field. Acked-by: Karsten Keil Signed-off-by: Greg Kroah-Hartman --- drivers/isdn/mISDN/core.c | 64 ++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'drivers') diff --git a/drivers/isdn/mISDN/core.c b/drivers/isdn/mISDN/core.c index da30c5cb960..faf505462a4 100644 --- a/drivers/isdn/mISDN/core.c +++ b/drivers/isdn/mISDN/core.c @@ -37,8 +37,8 @@ static void mISDN_dev_release(struct device *dev) /* nothing to do: the device is part of its parent's data structure */ } -static ssize_t _show_id(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t id_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct mISDNdevice *mdev = dev_to_mISDN(dev); @@ -46,9 +46,10 @@ static ssize_t _show_id(struct device *dev, return -ENODEV; return sprintf(buf, "%d\n", mdev->id); } +static DEVICE_ATTR_RO(id); -static ssize_t _show_nrbchan(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t nrbchan_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct mISDNdevice *mdev = dev_to_mISDN(dev); @@ -56,9 +57,10 @@ static ssize_t _show_nrbchan(struct device *dev, return -ENODEV; return sprintf(buf, "%d\n", mdev->nrbchan); } +static DEVICE_ATTR_RO(nrbchan); -static ssize_t _show_d_protocols(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t d_protocols_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct mISDNdevice *mdev = dev_to_mISDN(dev); @@ -66,9 +68,10 @@ static ssize_t _show_d_protocols(struct device *dev, return -ENODEV; return sprintf(buf, "%d\n", mdev->Dprotocols); } +static DEVICE_ATTR_RO(d_protocols); -static ssize_t _show_b_protocols(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t b_protocols_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct mISDNdevice *mdev = dev_to_mISDN(dev); @@ -76,9 +79,10 @@ static ssize_t _show_b_protocols(struct device *dev, return -ENODEV; return sprintf(buf, "%d\n", mdev->Bprotocols | get_all_Bprotocols()); } +static DEVICE_ATTR_RO(b_protocols); -static ssize_t _show_protocol(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t protocol_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct mISDNdevice *mdev = dev_to_mISDN(dev); @@ -86,17 +90,19 @@ static ssize_t _show_protocol(struct device *dev, return -ENODEV; return sprintf(buf, "%d\n", mdev->D.protocol); } +static DEVICE_ATTR_RO(protocol); -static ssize_t _show_name(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t name_show(struct device *dev, + struct device_attribute *attr, char *buf) { strcpy(buf, dev_name(dev)); return strlen(buf); } +static DEVICE_ATTR_RO(name); #if 0 /* hangs */ -static ssize_t _set_name(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t name_set(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { int err = 0; char *out = kmalloc(count + 1, GFP_KERNEL); @@ -113,10 +119,11 @@ static ssize_t _set_name(struct device *dev, struct device_attribute *attr, return (err < 0) ? err : count; } +static DEVICE_ATTR_RW(name); #endif -static ssize_t _show_channelmap(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t channelmap_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct mISDNdevice *mdev = dev_to_mISDN(dev); char *bp = buf; @@ -127,18 +134,19 @@ static ssize_t _show_channelmap(struct device *dev, return bp - buf; } - -static struct device_attribute mISDN_dev_attrs[] = { - __ATTR(id, S_IRUGO, _show_id, NULL), - __ATTR(d_protocols, S_IRUGO, _show_d_protocols, NULL), - __ATTR(b_protocols, S_IRUGO, _show_b_protocols, NULL), - __ATTR(protocol, S_IRUGO, _show_protocol, NULL), - __ATTR(channelmap, S_IRUGO, _show_channelmap, NULL), - __ATTR(nrbchan, S_IRUGO, _show_nrbchan, NULL), - __ATTR(name, S_IRUGO, _show_name, NULL), -/* __ATTR(name, S_IRUGO | S_IWUSR, _show_name, _set_name), */ - {} +static DEVICE_ATTR_RO(channelmap); + +static struct attribute *mISDN_attrs[] = { + &dev_attr_id.attr, + &dev_attr_d_protocols.attr, + &dev_attr_b_protocols.attr, + &dev_attr_protocol.attr, + &dev_attr_channelmap.attr, + &dev_attr_nrbchan.attr, + &dev_attr_name.attr, + NULL, }; +ATTRIBUTE_GROUPS(mISDN); static int mISDN_uevent(struct device *dev, struct kobj_uevent_env *env) { @@ -162,7 +170,7 @@ static struct class mISDN_class = { .name = "mISDN", .owner = THIS_MODULE, .dev_uevent = mISDN_uevent, - .dev_attrs = mISDN_dev_attrs, + .dev_groups = mISDN_groups, .dev_release = mISDN_dev_release, .class_release = mISDN_class_release, }; -- cgit v1.2.3-70-g09d2 From 5baa7503a7a0b8d65308ff3b2ab887bf343c65d3 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:13 -0700 Subject: leds: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the led class code to use the correct field. Acked-by: Bryan Wu Cc: Richard Purdie Signed-off-by: Greg Kroah-Hartman --- drivers/leds/led-class.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c index 4336e37a97f..f37d63cf726 100644 --- a/drivers/leds/led-class.c +++ b/drivers/leds/led-class.c @@ -29,7 +29,7 @@ static void led_update_brightness(struct led_classdev *led_cdev) led_cdev->brightness = led_cdev->brightness_get(led_cdev); } -static ssize_t led_brightness_show(struct device *dev, +static ssize_t brightness_show(struct device *dev, struct device_attribute *attr, char *buf) { struct led_classdev *led_cdev = dev_get_drvdata(dev); @@ -40,7 +40,7 @@ static ssize_t led_brightness_show(struct device *dev, return sprintf(buf, "%u\n", led_cdev->brightness); } -static ssize_t led_brightness_store(struct device *dev, +static ssize_t brightness_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { struct led_classdev *led_cdev = dev_get_drvdata(dev); @@ -57,6 +57,7 @@ static ssize_t led_brightness_store(struct device *dev, return size; } +static DEVICE_ATTR_RW(brightness); static ssize_t led_max_brightness_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -65,14 +66,35 @@ static ssize_t led_max_brightness_show(struct device *dev, return sprintf(buf, "%u\n", led_cdev->max_brightness); } +static DEVICE_ATTR(max_brightness, 0444, led_max_brightness_show, NULL); -static struct device_attribute led_class_attrs[] = { - __ATTR(brightness, 0644, led_brightness_show, led_brightness_store), - __ATTR(max_brightness, 0444, led_max_brightness_show, NULL), #ifdef CONFIG_LEDS_TRIGGERS - __ATTR(trigger, 0644, led_trigger_show, led_trigger_store), +static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store); +static struct attribute *led_trigger_attrs[] = { + &dev_attr_trigger.attr, + NULL, +}; +static const struct attribute_group led_trigger_group = { + .attrs = led_trigger_attrs, +}; +#endif + +static struct attribute *led_class_attrs[] = { + &dev_attr_brightness.attr, + &dev_attr_max_brightness.attr, + NULL, +}; + +static const struct attribute_group led_group = { + .attrs = led_class_attrs, +}; + +static const struct attribute_group *led_groups[] = { + &led_group, +#ifdef CONFIG_LEDS_TRIGGERS + &led_trigger_group, #endif - __ATTR_NULL, + NULL, }; static void led_timer_function(unsigned long data) @@ -258,7 +280,7 @@ static int __init leds_init(void) if (IS_ERR(leds_class)) return PTR_ERR(leds_class); leds_class->pm = &leds_class_dev_pm_ops; - leds_class->dev_attrs = led_class_attrs; + leds_class->dev_groups = led_groups; return 0; } -- cgit v1.2.3-70-g09d2 From 3499116b915e260b275c167a471e0e05bbe3f1d6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:20 -0700 Subject: PTP: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the ptp class code to use the correct field. Acked-by: Richard Cochran Signed-off-by: Greg Kroah-Hartman --- drivers/ptp/ptp_clock.c | 2 +- drivers/ptp/ptp_private.h | 2 +- drivers/ptp/ptp_sysfs.c | 51 +++++++++++++++++++++++++++-------------------- 3 files changed, 31 insertions(+), 24 deletions(-) (limited to 'drivers') diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 4a8c388364c..a8319b26664 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -330,7 +330,7 @@ static int __init ptp_init(void) goto no_region; } - ptp_class->dev_attrs = ptp_dev_attrs; + ptp_class->dev_groups = ptp_groups; pr_info("PTP clock support registered\n"); return 0; diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index 69d32070cc6..df03f2e30ad 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -84,7 +84,7 @@ uint ptp_poll(struct posix_clock *pc, * see ptp_sysfs.c */ -extern struct device_attribute ptp_dev_attrs[]; +extern const struct attribute_group *ptp_groups[]; int ptp_cleanup_sysfs(struct ptp_clock *ptp); diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c index 2f93926ac97..13ec5311746 100644 --- a/drivers/ptp/ptp_sysfs.c +++ b/drivers/ptp/ptp_sysfs.c @@ -27,36 +27,43 @@ static ssize_t clock_name_show(struct device *dev, struct ptp_clock *ptp = dev_get_drvdata(dev); return snprintf(page, PAGE_SIZE-1, "%s\n", ptp->info->name); } +static DEVICE_ATTR(clock_name, 0444, clock_name_show, NULL); -#define PTP_SHOW_INT(name) \ -static ssize_t name##_show(struct device *dev, \ +#define PTP_SHOW_INT(name, var) \ +static ssize_t var##_show(struct device *dev, \ struct device_attribute *attr, char *page) \ { \ struct ptp_clock *ptp = dev_get_drvdata(dev); \ - return snprintf(page, PAGE_SIZE-1, "%d\n", ptp->info->name); \ -} - -PTP_SHOW_INT(max_adj); -PTP_SHOW_INT(n_alarm); -PTP_SHOW_INT(n_ext_ts); -PTP_SHOW_INT(n_per_out); -PTP_SHOW_INT(pps); + return snprintf(page, PAGE_SIZE-1, "%d\n", ptp->info->var); \ +} \ +static DEVICE_ATTR(name, 0444, var##_show, NULL); + +PTP_SHOW_INT(max_adjustment, max_adj); +PTP_SHOW_INT(n_alarms, n_alarm); +PTP_SHOW_INT(n_external_timestamps, n_ext_ts); +PTP_SHOW_INT(n_periodic_outputs, n_per_out); +PTP_SHOW_INT(pps_available, pps); + +static struct attribute *ptp_attrs[] = { + &dev_attr_clock_name.attr, + &dev_attr_max_adjustment.attr, + &dev_attr_n_alarms.attr, + &dev_attr_n_external_timestamps.attr, + &dev_attr_n_periodic_outputs.attr, + &dev_attr_pps_available.attr, + NULL, +}; -#define PTP_RO_ATTR(_var, _name) { \ - .attr = { .name = __stringify(_name), .mode = 0444 }, \ - .show = _var##_show, \ -} +static const struct attribute_group ptp_group = { + .attrs = ptp_attrs, +}; -struct device_attribute ptp_dev_attrs[] = { - PTP_RO_ATTR(clock_name, clock_name), - PTP_RO_ATTR(max_adj, max_adjustment), - PTP_RO_ATTR(n_alarm, n_alarms), - PTP_RO_ATTR(n_ext_ts, n_external_timestamps), - PTP_RO_ATTR(n_per_out, n_periodic_outputs), - PTP_RO_ATTR(pps, pps_available), - __ATTR_NULL, +const struct attribute_group *ptp_groups[] = { + &ptp_group, + NULL, }; + static ssize_t extts_enable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) -- cgit v1.2.3-70-g09d2 From f21e683508ead3ad8db7ffef3d8b5802c3b43e9a Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:22 -0700 Subject: rtc: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the rtc class code to use the correct field. Acked-by: Alessandro Zummo Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-sysfs.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'drivers') diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c index 4b26f8672b2..babd43bf3dd 100644 --- a/drivers/rtc/rtc-sysfs.c +++ b/drivers/rtc/rtc-sysfs.c @@ -25,15 +25,14 @@ */ static ssize_t -rtc_sysfs_show_name(struct device *dev, struct device_attribute *attr, - char *buf) +name_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%s\n", to_rtc_device(dev)->name); } +static DEVICE_ATTR_RO(name); static ssize_t -rtc_sysfs_show_date(struct device *dev, struct device_attribute *attr, - char *buf) +date_show(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t retval; struct rtc_time tm; @@ -46,10 +45,10 @@ rtc_sysfs_show_date(struct device *dev, struct device_attribute *attr, return retval; } +static DEVICE_ATTR_RO(date); static ssize_t -rtc_sysfs_show_time(struct device *dev, struct device_attribute *attr, - char *buf) +time_show(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t retval; struct rtc_time tm; @@ -62,10 +61,10 @@ rtc_sysfs_show_time(struct device *dev, struct device_attribute *attr, return retval; } +static DEVICE_ATTR_RO(time); static ssize_t -rtc_sysfs_show_since_epoch(struct device *dev, struct device_attribute *attr, - char *buf) +since_epoch_show(struct device *dev, struct device_attribute *attr, char *buf) { ssize_t retval; struct rtc_time tm; @@ -79,16 +78,16 @@ rtc_sysfs_show_since_epoch(struct device *dev, struct device_attribute *attr, return retval; } +static DEVICE_ATTR_RO(since_epoch); static ssize_t -rtc_sysfs_show_max_user_freq(struct device *dev, struct device_attribute *attr, - char *buf) +max_user_freq_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%d\n", to_rtc_device(dev)->max_user_freq); } static ssize_t -rtc_sysfs_set_max_user_freq(struct device *dev, struct device_attribute *attr, +max_user_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t n) { struct rtc_device *rtc = to_rtc_device(dev); @@ -101,6 +100,7 @@ rtc_sysfs_set_max_user_freq(struct device *dev, struct device_attribute *attr, return n; } +static DEVICE_ATTR_RW(max_user_freq); /** * rtc_sysfs_show_hctosys - indicate if the given RTC set the system time @@ -109,8 +109,7 @@ rtc_sysfs_set_max_user_freq(struct device *dev, struct device_attribute *attr, * boot or resume event. */ static ssize_t -rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr, - char *buf) +hctosys_show(struct device *dev, struct device_attribute *attr, char *buf) { #ifdef CONFIG_RTC_HCTOSYS_DEVICE if (rtc_hctosys_ret == 0 && @@ -121,17 +120,18 @@ rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr, #endif return sprintf(buf, "0\n"); } - -static struct device_attribute rtc_attrs[] = { - __ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL), - __ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL), - __ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL), - __ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL), - __ATTR(max_user_freq, S_IRUGO | S_IWUSR, rtc_sysfs_show_max_user_freq, - rtc_sysfs_set_max_user_freq), - __ATTR(hctosys, S_IRUGO, rtc_sysfs_show_hctosys, NULL), - { }, +static DEVICE_ATTR_RO(hctosys); + +static struct attribute *rtc_attrs[] = { + &dev_attr_name.attr, + &dev_attr_date.attr, + &dev_attr_time.attr, + &dev_attr_since_epoch.attr, + &dev_attr_max_user_freq.attr, + &dev_attr_hctosys.attr, + NULL, }; +ATTRIBUTE_GROUPS(rtc); static ssize_t rtc_sysfs_show_wakealarm(struct device *dev, struct device_attribute *attr, @@ -261,5 +261,5 @@ void rtc_sysfs_del_device(struct rtc_device *rtc) void __init rtc_sysfs_init(struct class *rtc_class) { - rtc_class->dev_attrs = rtc_attrs; + rtc_class->dev_groups = rtc_groups; } -- cgit v1.2.3-70-g09d2 From 29f1953d51faa3995192ba4ccff3b71c661940c2 Mon Sep 17 00:00:00 2001 From: Hanjun Guo Date: Sat, 27 Jul 2013 11:00:49 +0800 Subject: cpu topology: remove stale arch_provides_topology_pointers and define_siblings_show_map/list() arch_provides_topology_pointers was introduced in commit 23ca4bba3 (x86: cleanup early per cpu variables/accesses v4) to indicate pointers to the topology cpumask_t maps are valid to avoid copying data on to/off of the stack. But later in commit fbd59a8d (cpumask: Use topology_core_cpumask()/ topology_thread_cpumask()), the pointers to the topology struct cpumask maps are always valid. After that commit, the only difference is that there is a redundant "unsigned int cpu = dev->id;" if arch_provides_topology_pointers defined, but dev->id is type 'u32' which devolves to 'unsigned int' on all supported arches. So this arch_provides_topology_pointers define is pointless and only cause obfuscation now, remove it. Tested on x86 machine, topology information in sys/devices/system/cpu/ cpuX/topology/ is the same after appling this patch set. Signed-off-by: Hanjun Guo Signed-off-by: Greg Kroah-Hartman --- drivers/base/topology.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'drivers') diff --git a/drivers/base/topology.c b/drivers/base/topology.c index 2f5919ed91a..94ffee378f1 100644 --- a/drivers/base/topology.c +++ b/drivers/base/topology.c @@ -62,25 +62,6 @@ static ssize_t show_cpumap(int type, const struct cpumask *mask, char *buf) } #endif -#ifdef arch_provides_topology_pointers -#define define_siblings_show_map(name) \ -static ssize_t show_##name(struct device *dev, \ - struct device_attribute *attr, char *buf) \ -{ \ - unsigned int cpu = dev->id; \ - return show_cpumap(0, topology_##name(cpu), buf); \ -} - -#define define_siblings_show_list(name) \ -static ssize_t show_##name##_list(struct device *dev, \ - struct device_attribute *attr, \ - char *buf) \ -{ \ - unsigned int cpu = dev->id; \ - return show_cpumap(1, topology_##name(cpu), buf); \ -} - -#else #define define_siblings_show_map(name) \ static ssize_t show_##name(struct device *dev, \ struct device_attribute *attr, char *buf) \ @@ -95,7 +76,6 @@ static ssize_t show_##name##_list(struct device *dev, \ { \ return show_cpumap(1, topology_##name(dev->id), buf); \ } -#endif #define define_siblings_show_func(name) \ define_siblings_show_map(name); define_siblings_show_list(name) -- cgit v1.2.3-70-g09d2 From fa6fdb33b486a8afc5439c504da8d581e142c77d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:55 -0700 Subject: driver core: bus_type: add dev_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add dev_groups to struct bus_type which should be used instead of dev_attrs. dev_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 5 +++++ drivers/base/bus.c | 6 ++++++ drivers/base/core.c | 7 +++---- include/linux/device.h | 4 +++- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/base/base.h b/drivers/base/base.h index b8bdfe61daa..fccf954f82f 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -119,6 +119,11 @@ static inline int driver_match_device(struct device_driver *drv, return drv->bus->match ? drv->bus->match(dev, drv) : 1; } +extern int device_add_groups(struct device *dev, + const struct attribute_group **groups); +extern void device_remove_groups(struct device *dev, + const struct attribute_group **groups); + extern char *make_class_name(const char *name, struct kobject *kobj); extern int devres_release_all(struct device *dev); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index d414331b480..7b2dc5ba7d7 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -499,6 +499,9 @@ int bus_add_device(struct device *dev) error = device_add_attrs(bus, dev); if (error) goto out_put; + error = device_add_groups(dev, bus->dev_groups); + if (error) + goto out_groups; error = sysfs_create_link(&bus->p->devices_kset->kobj, &dev->kobj, dev_name(dev)); if (error) @@ -513,6 +516,8 @@ int bus_add_device(struct device *dev) out_subsys: sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); +out_groups: + device_remove_groups(dev, bus->dev_groups); out_id: device_remove_attrs(bus, dev); out_put: @@ -575,6 +580,7 @@ void bus_remove_device(struct device *dev) sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev_name(dev)); device_remove_attrs(dev->bus, dev); + device_remove_groups(dev, dev->bus->dev_groups); if (klist_node_attached(&dev->p->knode_bus)) klist_del(&dev->p->knode_bus); diff --git a/drivers/base/core.c b/drivers/base/core.c index e51c7878293..09a99d60964 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -491,8 +491,7 @@ static void device_remove_bin_attributes(struct device *dev, device_remove_bin_file(dev, &attrs[i]); } -static int device_add_groups(struct device *dev, - const struct attribute_group **groups) +int device_add_groups(struct device *dev, const struct attribute_group **groups) { int error = 0; int i; @@ -511,8 +510,8 @@ static int device_add_groups(struct device *dev, return error; } -static void device_remove_groups(struct device *dev, - const struct attribute_group **groups) +void device_remove_groups(struct device *dev, + const struct attribute_group **groups) { int i; diff --git a/include/linux/device.h b/include/linux/device.h index 22b546a5859..3aec4a68b1d 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -66,6 +66,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @bus_attrs: Default attributes of the bus. * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. + * @dev_groups: Default attributes of the devices on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver * is added for this bus. It should return a nonzero value if the * given device can be handled by the given driver. @@ -104,8 +105,9 @@ struct bus_type { const char *dev_name; struct device *dev_root; struct bus_attribute *bus_attrs; - struct device_attribute *dev_attrs; + struct device_attribute *dev_attrs; /* use dev_groups instead */ struct driver_attribute *drv_attrs; + const struct attribute_group **dev_groups; int (*match)(struct device *dev, struct device_driver *drv); int (*uevent)(struct device *dev, struct kobj_uevent_env *env); -- cgit v1.2.3-70-g09d2 From ed0617b5c0bcd7fd04053568aa0cc19a977a1f26 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:56 -0700 Subject: driver core: bus_type: add drv_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add drv_groups to struct bus_type which should be used instead of drv_attrs. drv_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 5 +++++ drivers/base/bus.c | 5 +++++ drivers/base/driver.c | 8 ++++---- include/linux/device.h | 4 +++- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/base/base.h b/drivers/base/base.h index fccf954f82f..2cbc6774f4c 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -119,6 +119,11 @@ static inline int driver_match_device(struct device_driver *drv, return drv->bus->match ? drv->bus->match(dev, drv) : 1; } +extern int driver_add_groups(struct device_driver *drv, + const struct attribute_group **groups); +extern void driver_remove_groups(struct device_driver *drv, + const struct attribute_group **groups); + extern int device_add_groups(struct device *dev, const struct attribute_group **groups); extern void device_remove_groups(struct device *dev, diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 7b2dc5ba7d7..de5ce22df30 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -725,6 +725,10 @@ int bus_add_driver(struct device_driver *drv) printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", __func__, drv->name); } + error = driver_add_groups(drv, bus->drv_groups); + if (error) + printk(KERN_ERR "%s: driver_create_groups(%s) failed\n", + __func__, drv->name); if (!drv->suppress_bind_attrs) { error = add_bind_files(drv); @@ -762,6 +766,7 @@ void bus_remove_driver(struct device_driver *drv) if (!drv->suppress_bind_attrs) remove_bind_files(drv); driver_remove_attrs(drv->bus, drv); + driver_remove_groups(drv, drv->bus->drv_groups); driver_remove_file(drv, &driver_attr_uevent); klist_remove(&drv->p->knode_bus); pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 974e301a1ef..89db726ebb9 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -123,8 +123,8 @@ void driver_remove_file(struct device_driver *drv, } EXPORT_SYMBOL_GPL(driver_remove_file); -static int driver_add_groups(struct device_driver *drv, - const struct attribute_group **groups) +int driver_add_groups(struct device_driver *drv, + const struct attribute_group **groups) { int error = 0; int i; @@ -143,8 +143,8 @@ static int driver_add_groups(struct device_driver *drv, return error; } -static void driver_remove_groups(struct device_driver *drv, - const struct attribute_group **groups) +void driver_remove_groups(struct device_driver *drv, + const struct attribute_group **groups) { int i; diff --git a/include/linux/device.h b/include/linux/device.h index 3aec4a68b1d..94d987f128b 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -67,6 +67,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. * @dev_groups: Default attributes of the devices on the bus. + * @drv_groups: Default attributes of the device drivers on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver * is added for this bus. It should return a nonzero value if the * given device can be handled by the given driver. @@ -106,8 +107,9 @@ struct bus_type { struct device *dev_root; struct bus_attribute *bus_attrs; struct device_attribute *dev_attrs; /* use dev_groups instead */ - struct driver_attribute *drv_attrs; + struct driver_attribute *drv_attrs; /* use drv_groups instead */ const struct attribute_group **dev_groups; + const struct attribute_group **drv_groups; int (*match)(struct device *dev, struct device_driver *drv); int (*uevent)(struct device *dev, struct kobj_uevent_env *env); -- cgit v1.2.3-70-g09d2 From 12478ba077adf8b53be6101b80dd8a65e4df9ea6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 8 Aug 2013 15:22:57 -0700 Subject: driver core: bus_type: add bus_groups attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add bus_groups to struct bus_type which should be used instead of bus_attrs. bus_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/device.h | 4 +++- 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index de5ce22df30..5ee5d3c1d74 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -881,6 +881,37 @@ static void bus_remove_attrs(struct bus_type *bus) } } +static int bus_add_groups(struct bus_type *bus, + const struct attribute_group **groups) +{ + int error = 0; + int i; + + if (groups) { + for (i = 0; groups[i]; i++) { + error = sysfs_create_group(&bus->p->subsys.kobj, + groups[i]); + if (error) { + while (--i >= 0) + sysfs_remove_group(&bus->p->subsys.kobj, + groups[i]); + break; + } + } + } + return error; +} + +static void bus_remove_groups(struct bus_type *bus, + const struct attribute_group **groups) +{ + int i; + + if (groups) + for (i = 0; groups[i]; i++) + sysfs_remove_group(&bus->p->subsys.kobj, groups[i]); +} + static void klist_devices_get(struct klist_node *n) { struct device_private *dev_prv = to_device_private_bus(n); @@ -973,10 +1004,15 @@ int bus_register(struct bus_type *bus) retval = bus_add_attrs(bus); if (retval) goto bus_attrs_fail; + retval = bus_add_groups(bus, bus->bus_groups); + if (retval) + goto bus_groups_fail; pr_debug("bus: '%s': registered\n", bus->name); return 0; +bus_groups_fail: + bus_remove_attrs(bus); bus_attrs_fail: remove_probe_files(bus); bus_probe_files_fail: @@ -1007,6 +1043,7 @@ void bus_unregister(struct bus_type *bus) if (bus->dev_root) device_unregister(bus->dev_root); bus_remove_attrs(bus); + bus_remove_groups(bus, bus->bus_groups); remove_probe_files(bus); kset_unregister(bus->p->drivers_kset); kset_unregister(bus->p->devices_kset); diff --git a/include/linux/device.h b/include/linux/device.h index 94d987f128b..26e23b22ed0 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -66,6 +66,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @bus_attrs: Default attributes of the bus. * @dev_attrs: Default attributes of the devices on the bus. * @drv_attrs: Default attributes of the device drivers on the bus. + * @bus_groups: Default attributes of the bus. * @dev_groups: Default attributes of the devices on the bus. * @drv_groups: Default attributes of the device drivers on the bus. * @match: Called, perhaps multiple times, whenever a new device or driver @@ -105,9 +106,10 @@ struct bus_type { const char *name; const char *dev_name; struct device *dev_root; - struct bus_attribute *bus_attrs; + struct bus_attribute *bus_attrs; /* use bus_groups instead */ struct device_attribute *dev_attrs; /* use dev_groups instead */ struct driver_attribute *drv_attrs; /* use drv_groups instead */ + const struct attribute_group **bus_groups; const struct attribute_group **dev_groups; const struct attribute_group **drv_groups; -- cgit v1.2.3-70-g09d2 From c7991b0b720efa5e0a590f6359d36e09bd187b76 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Tue, 13 Aug 2013 02:39:30 +0200 Subject: driver core / cpu: Check if NUMA node is valid before bringing CPU up There is a potential race condition between cpu_subsys_online() and either acpi_processor_remove() or remove_memory() that execute try_offline_node(). Namely, it is possible that cpu_subsys_online() will run right after the CPUs NUMA node has been put offline and cpu_to_node() executed by it will return NUMA_NO_NODE (-1). In that case the CPU is gone and it doesn't make sense to call cpu_up() for it, so make cpu_subsys_online() return -ENODEV then. Signed-off-by: Rafael J. Wysocki Acked-by: Toshi Kani Signed-off-by: Greg Kroah-Hartman --- drivers/base/cpu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index 4c358bc44c7..6bfaaca6955 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -43,11 +43,14 @@ static int __ref cpu_subsys_online(struct device *dev) struct cpu *cpu = container_of(dev, struct cpu, dev); int cpuid = dev->id; int from_nid, to_nid; - int ret; + int ret = -ENODEV; cpu_hotplug_driver_lock(); from_nid = cpu_to_node(cpuid); + if (from_nid == NUMA_NO_NODE) + goto out; + ret = cpu_up(cpuid); /* * When hot adding memory to memoryless node and enabling a cpu @@ -57,6 +60,7 @@ static int __ref cpu_subsys_online(struct device *dev) if (from_nid != to_nid) change_cpu_under_node(cpu, from_nid, to_nid); + out: cpu_hotplug_driver_unlock(); return ret; } -- cgit v1.2.3-70-g09d2 From 3454bf96041e8c4cecc7d85b87c35056050a15b5 Mon Sep 17 00:00:00 2001 From: Hanjun Guo Date: Sat, 17 Aug 2013 20:42:24 +0800 Subject: drivers / base: Fix sysfs_deprecated_setup() __init attribute location __init belongs after the return type on functions, not before it. Signed-off-by: Hanjun Guo Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/base/core.c b/drivers/base/core.c index 09a99d60964..af646afa5b7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -36,7 +36,7 @@ long sysfs_deprecated = 1; #else long sysfs_deprecated = 0; #endif -static __init int sysfs_deprecated_setup(char *arg) +static int __init sysfs_deprecated_setup(char *arg) { return kstrtol(arg, 10, &sysfs_deprecated); } -- cgit v1.2.3-70-g09d2 From a82579106c79484a5ea0c4c424c8860648c2e389 Mon Sep 17 00:00:00 2001 From: Hanjun Guo Date: Sat, 17 Aug 2013 20:42:25 +0800 Subject: drivers / platform: Fix __init attribute location __init belongs after the return type on functions, not before it. Signed-off-by: Hanjun Guo Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 3c3197a8de4..9d538cf9204 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1054,7 +1054,7 @@ void __init early_platform_driver_register_all(char *class_str) * @epdrv: early platform driver structure * @id: id to match against */ -static __init struct platform_device * +static struct platform_device * __init early_platform_match(struct early_platform_driver *epdrv, int id) { struct platform_device *pd; @@ -1072,7 +1072,7 @@ early_platform_match(struct early_platform_driver *epdrv, int id) * @epdrv: early platform driver structure * @id: return true if id or above exists */ -static __init int early_platform_left(struct early_platform_driver *epdrv, +static int __init early_platform_left(struct early_platform_driver *epdrv, int id) { struct platform_device *pd; -- cgit v1.2.3-70-g09d2 From cebcac7c59e812d17237c13405aa6886199a1b90 Mon Sep 17 00:00:00 2001 From: Hanjun Guo Date: Sat, 17 Aug 2013 20:42:26 +0800 Subject: drivers / dma-contiguous: Fix __init attribute location __init belongs after the return type on functions, not before it. Signed-off-by: Hanjun Guo Signed-off-by: Greg Kroah-Hartman --- drivers/base/dma-contiguous.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c index 0ca54421ce9..6c9cdaa9200 100644 --- a/drivers/base/dma-contiguous.c +++ b/drivers/base/dma-contiguous.c @@ -134,7 +134,7 @@ void __init dma_contiguous_reserve(phys_addr_t limit) static DEFINE_MUTEX(cma_mutex); -static __init int cma_activate_area(unsigned long base_pfn, unsigned long count) +static int __init cma_activate_area(unsigned long base_pfn, unsigned long count) { unsigned long pfn = base_pfn; unsigned i = count >> pageblock_order; @@ -156,7 +156,7 @@ static __init int cma_activate_area(unsigned long base_pfn, unsigned long count) return 0; } -static __init struct cma *cma_create_area(unsigned long base_pfn, +static struct cma * __init cma_create_area(unsigned long base_pfn, unsigned long count) { int bitmap_size = BITS_TO_LONGS(count) * sizeof(long); -- cgit v1.2.3-70-g09d2 From a93d6b0a879718a1a08553935744b0d5c58354c0 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:09 -0700 Subject: devfreq: convert devfreq_class to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the devfreq_class code to use the correct field. Cc: MyungJoo Ham Cc: Kyungmin Park Signed-off-by: Greg Kroah-Hartman --- drivers/devfreq/devfreq.c | 78 ++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 34 deletions(-) (limited to 'drivers') diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index e94e619fe05..c99c00d35d3 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -703,7 +703,7 @@ err_out: } EXPORT_SYMBOL(devfreq_remove_governor); -static ssize_t show_governor(struct device *dev, +static ssize_t governor_show(struct device *dev, struct device_attribute *attr, char *buf) { if (!to_devfreq(dev)->governor) @@ -712,7 +712,7 @@ static ssize_t show_governor(struct device *dev, return sprintf(buf, "%s\n", to_devfreq(dev)->governor->name); } -static ssize_t store_governor(struct device *dev, struct device_attribute *attr, +static ssize_t governor_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct devfreq *df = to_devfreq(dev); @@ -754,9 +754,11 @@ out: ret = count; return ret; } -static ssize_t show_available_governors(struct device *d, - struct device_attribute *attr, - char *buf) +static DEVICE_ATTR_RW(governor); + +static ssize_t available_governors_show(struct device *d, + struct device_attribute *attr, + char *buf) { struct devfreq_governor *tmp_governor; ssize_t count = 0; @@ -775,9 +777,10 @@ static ssize_t show_available_governors(struct device *d, return count; } +static DEVICE_ATTR_RO(available_governors); -static ssize_t show_freq(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t cur_freq_show(struct device *dev, struct device_attribute *attr, + char *buf) { unsigned long freq; struct devfreq *devfreq = to_devfreq(dev); @@ -788,20 +791,22 @@ static ssize_t show_freq(struct device *dev, return sprintf(buf, "%lu\n", devfreq->previous_freq); } +static DEVICE_ATTR_RO(cur_freq); -static ssize_t show_target_freq(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t target_freq_show(struct device *dev, + struct device_attribute *attr, char *buf) { return sprintf(buf, "%lu\n", to_devfreq(dev)->previous_freq); } +static DEVICE_ATTR_RO(target_freq); -static ssize_t show_polling_interval(struct device *dev, +static ssize_t polling_interval_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%d\n", to_devfreq(dev)->profile->polling_ms); } -static ssize_t store_polling_interval(struct device *dev, +static ssize_t polling_interval_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -821,8 +826,9 @@ static ssize_t store_polling_interval(struct device *dev, return ret; } +static DEVICE_ATTR_RW(polling_interval); -static ssize_t store_min_freq(struct device *dev, struct device_attribute *attr, +static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct devfreq *df = to_devfreq(dev); @@ -849,13 +855,13 @@ unlock: return ret; } -static ssize_t show_min_freq(struct device *dev, struct device_attribute *attr, +static ssize_t min_freq_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%lu\n", to_devfreq(dev)->min_freq); } -static ssize_t store_max_freq(struct device *dev, struct device_attribute *attr, +static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct devfreq *df = to_devfreq(dev); @@ -881,16 +887,18 @@ unlock: mutex_unlock(&df->lock); return ret; } +static DEVICE_ATTR_RW(min_freq); -static ssize_t show_max_freq(struct device *dev, struct device_attribute *attr, +static ssize_t max_freq_show(struct device *dev, struct device_attribute *attr, char *buf) { return sprintf(buf, "%lu\n", to_devfreq(dev)->max_freq); } +static DEVICE_ATTR_RW(max_freq); -static ssize_t show_available_freqs(struct device *d, - struct device_attribute *attr, - char *buf) +static ssize_t available_frequencies_show(struct device *d, + struct device_attribute *attr, + char *buf) { struct devfreq *df = to_devfreq(d); struct device *dev = df->dev.parent; @@ -918,9 +926,10 @@ static ssize_t show_available_freqs(struct device *d, return count; } +static DEVICE_ATTR_RO(available_frequencies); -static ssize_t show_trans_table(struct device *dev, struct device_attribute *attr, - char *buf) +static ssize_t trans_stat_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct devfreq *devfreq = to_devfreq(dev); ssize_t len; @@ -959,20 +968,21 @@ static ssize_t show_trans_table(struct device *dev, struct device_attribute *att devfreq->total_trans); return len; } - -static struct device_attribute devfreq_attrs[] = { - __ATTR(governor, S_IRUGO | S_IWUSR, show_governor, store_governor), - __ATTR(available_governors, S_IRUGO, show_available_governors, NULL), - __ATTR(cur_freq, S_IRUGO, show_freq, NULL), - __ATTR(available_frequencies, S_IRUGO, show_available_freqs, NULL), - __ATTR(target_freq, S_IRUGO, show_target_freq, NULL), - __ATTR(polling_interval, S_IRUGO | S_IWUSR, show_polling_interval, - store_polling_interval), - __ATTR(min_freq, S_IRUGO | S_IWUSR, show_min_freq, store_min_freq), - __ATTR(max_freq, S_IRUGO | S_IWUSR, show_max_freq, store_max_freq), - __ATTR(trans_stat, S_IRUGO, show_trans_table, NULL), - { }, +static DEVICE_ATTR_RO(trans_stat); + +static struct attribute *devfreq_attrs[] = { + &dev_attr_governor.attr, + &dev_attr_available_governors.attr, + &dev_attr_cur_freq.attr, + &dev_attr_available_frequencies.attr, + &dev_attr_target_freq.attr, + &dev_attr_polling_interval.attr, + &dev_attr_min_freq.attr, + &dev_attr_max_freq.attr, + &dev_attr_trans_stat.attr, + NULL, }; +ATTRIBUTE_GROUPS(devfreq); static int __init devfreq_init(void) { @@ -988,7 +998,7 @@ static int __init devfreq_init(void) pr_err("%s: couldn't create workqueue\n", __FILE__); return PTR_ERR(devfreq_wq); } - devfreq_class->dev_attrs = devfreq_attrs; + devfreq_class->dev_groups = devfreq_groups; return 0; } -- cgit v1.2.3-70-g09d2 From 46a58c44c173d3cbfa53931fbb7ad069ef59f190 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:11 -0700 Subject: HID: roccat: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the roccat class code to use the correct field. Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-arvo.c | 25 ++++++++++++++----------- drivers/hid/hid-roccat-isku.c | 13 +++++++------ drivers/hid/hid-roccat-kone.c | 30 ++++++++++++++++++------------ drivers/hid/hid-roccat-koneplus.c | 28 ++++++++++++++++------------ drivers/hid/hid-roccat-kovaplus.c | 33 +++++++++++++++++++-------------- drivers/hid/hid-roccat-pyra.c | 24 ++++++++++++++---------- 6 files changed, 88 insertions(+), 65 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-arvo.c b/drivers/hid/hid-roccat-arvo.c index 327f9b8ed1f..98bb89e0d91 100644 --- a/drivers/hid/hid-roccat-arvo.c +++ b/drivers/hid/hid-roccat-arvo.c @@ -75,6 +75,8 @@ static ssize_t arvo_sysfs_set_mode_key(struct device *dev, return size; } +static DEVICE_ATTR(mode_key, 0660, + arvo_sysfs_show_mode_key, arvo_sysfs_set_mode_key); static ssize_t arvo_sysfs_show_key_mask(struct device *dev, struct device_attribute *attr, char *buf) @@ -123,6 +125,8 @@ static ssize_t arvo_sysfs_set_key_mask(struct device *dev, return size; } +static DEVICE_ATTR(key_mask, 0660, + arvo_sysfs_show_key_mask, arvo_sysfs_set_key_mask); /* retval is 1-5 on success, < 0 on error */ static int arvo_get_actual_profile(struct usb_device *usb_dev) @@ -179,6 +183,9 @@ static ssize_t arvo_sysfs_set_actual_profile(struct device *dev, mutex_unlock(&arvo->arvo_lock); return retval; } +static DEVICE_ATTR(actual_profile, 0660, + arvo_sysfs_show_actual_profile, + arvo_sysfs_set_actual_profile); static ssize_t arvo_sysfs_write(struct file *fp, struct kobject *kobj, void const *buf, @@ -239,17 +246,13 @@ static ssize_t arvo_sysfs_read_info(struct file *fp, sizeof(struct arvo_info), ARVO_COMMAND_INFO); } - -static struct device_attribute arvo_attributes[] = { - __ATTR(mode_key, 0660, - arvo_sysfs_show_mode_key, arvo_sysfs_set_mode_key), - __ATTR(key_mask, 0660, - arvo_sysfs_show_key_mask, arvo_sysfs_set_key_mask), - __ATTR(actual_profile, 0660, - arvo_sysfs_show_actual_profile, - arvo_sysfs_set_actual_profile), - __ATTR_NULL +static struct attribute *arvo_attrs[] = { + &dev_attr_mode_key.attr, + &dev_attr_key_mask.attr, + &dev_attr_actual_profile.attr, + NULL, }; +ATTRIBUTE_GROUPS(arvo); static struct bin_attribute arvo_bin_attributes[] = { { @@ -430,7 +433,7 @@ static int __init arvo_init(void) arvo_class = class_create(THIS_MODULE, "arvo"); if (IS_ERR(arvo_class)) return PTR_ERR(arvo_class); - arvo_class->dev_attrs = arvo_attributes; + arvo_class->dev_groups = arvo_groups; arvo_class->dev_bin_attrs = arvo_bin_attributes; retval = hid_register_driver(&arvo_driver); diff --git a/drivers/hid/hid-roccat-isku.c b/drivers/hid/hid-roccat-isku.c index 8023751d525..3983dec062d 100644 --- a/drivers/hid/hid-roccat-isku.c +++ b/drivers/hid/hid-roccat-isku.c @@ -109,13 +109,14 @@ static ssize_t isku_sysfs_set_actual_profile(struct device *dev, return size; } +static DEVICE_ATTR(actual_profile, 0660, isku_sysfs_show_actual_profile, + isku_sysfs_set_actual_profile); -static struct device_attribute isku_attributes[] = { - __ATTR(actual_profile, 0660, - isku_sysfs_show_actual_profile, - isku_sysfs_set_actual_profile), - __ATTR_NULL +static struct attribute *isku_attrs[] = { + &dev_attr_actual_profile.attr, + NULL, }; +ATTRIBUTE_GROUPS(isku); static ssize_t isku_sysfs_read(struct file *fp, struct kobject *kobj, char *buf, loff_t off, size_t count, @@ -427,7 +428,7 @@ static int __init isku_init(void) isku_class = class_create(THIS_MODULE, "isku"); if (IS_ERR(isku_class)) return PTR_ERR(isku_class); - isku_class->dev_attrs = isku_attributes; + isku_class->dev_groups = isku_groups; isku_class->dev_bin_attrs = isku_bin_attributes; retval = hid_register_driver(&isku_driver); diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c index 7fae070788f..d36267339e3 100644 --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c @@ -386,6 +386,7 @@ static ssize_t kone_sysfs_show_actual_profile(struct device *dev, hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_profile); } +static DEVICE_ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL); static ssize_t kone_sysfs_show_actual_dpi(struct device *dev, struct device_attribute *attr, char *buf) @@ -394,6 +395,7 @@ static ssize_t kone_sysfs_show_actual_dpi(struct device *dev, hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); return snprintf(buf, PAGE_SIZE, "%d\n", kone->actual_dpi); } +static DEVICE_ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL); /* weight is read each time, since we don't get informed when it's changed */ static ssize_t kone_sysfs_show_weight(struct device *dev, @@ -416,6 +418,7 @@ static ssize_t kone_sysfs_show_weight(struct device *dev, return retval; return snprintf(buf, PAGE_SIZE, "%d\n", weight); } +static DEVICE_ATTR(weight, 0440, kone_sysfs_show_weight, NULL); static ssize_t kone_sysfs_show_firmware_version(struct device *dev, struct device_attribute *attr, char *buf) @@ -424,6 +427,8 @@ static ssize_t kone_sysfs_show_firmware_version(struct device *dev, hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); return snprintf(buf, PAGE_SIZE, "%d\n", kone->firmware_version); } +static DEVICE_ATTR(firmware_version, 0440, kone_sysfs_show_firmware_version, + NULL); static ssize_t kone_sysfs_show_tcu(struct device *dev, struct device_attribute *attr, char *buf) @@ -524,6 +529,7 @@ exit_unlock: mutex_unlock(&kone->kone_lock); return retval; } +static DEVICE_ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu); static ssize_t kone_sysfs_show_startup_profile(struct device *dev, struct device_attribute *attr, char *buf) @@ -570,15 +576,17 @@ static ssize_t kone_sysfs_set_startup_profile(struct device *dev, mutex_unlock(&kone->kone_lock); return size; } +static DEVICE_ATTR(startup_profile, 0660, kone_sysfs_show_startup_profile, + kone_sysfs_set_startup_profile); -static struct device_attribute kone_attributes[] = { +static struct attribute *kone_attrs[] = { /* * Read actual dpi settings. * Returns raw value for further processing. Refer to enum * kone_polling_rates to get real value. */ - __ATTR(actual_dpi, 0440, kone_sysfs_show_actual_dpi, NULL), - __ATTR(actual_profile, 0440, kone_sysfs_show_actual_profile, NULL), + &dev_attr_actual_dpi.attr, + &dev_attr_actual_profile.attr, /* * The mouse can be equipped with one of four supplied weights from 5 @@ -587,7 +595,7 @@ static struct device_attribute kone_attributes[] = { * by software. Refer to enum kone_weights to get corresponding real * weight. */ - __ATTR(weight, 0440, kone_sysfs_show_weight, NULL), + &dev_attr_weight.attr, /* * Prints firmware version stored in mouse as integer. @@ -595,22 +603,20 @@ static struct device_attribute kone_attributes[] = { * to get the real version number the decimal point has to be shifted 2 * positions to the left. E.g. a value of 138 means 1.38. */ - __ATTR(firmware_version, 0440, - kone_sysfs_show_firmware_version, NULL), + &dev_attr_firmware_version.attr, /* * Prints state of Tracking Control Unit as number where 0 = off and * 1 = on. Writing 0 deactivates tcu and writing 1 calibrates and * activates the tcu */ - __ATTR(tcu, 0660, kone_sysfs_show_tcu, kone_sysfs_set_tcu), + &dev_attr_tcu.attr, /* Prints and takes the number of the profile the mouse starts with */ - __ATTR(startup_profile, 0660, - kone_sysfs_show_startup_profile, - kone_sysfs_set_startup_profile), - __ATTR_NULL + &dev_attr_startup_profile.attr, + NULL, }; +ATTRIBUTE_GROUPS(kone); static struct bin_attribute kone_bin_attributes[] = { { @@ -891,7 +897,7 @@ static int __init kone_init(void) kone_class = class_create(THIS_MODULE, "kone"); if (IS_ERR(kone_class)) return PTR_ERR(kone_class); - kone_class->dev_attrs = kone_attributes; + kone_class->dev_groups = kone_groups; kone_class->dev_bin_attrs = kone_bin_attributes; retval = hid_register_driver(&kone_driver); diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c index 6a48fa3c7da..11906b4b42b 100644 --- a/drivers/hid/hid-roccat-koneplus.c +++ b/drivers/hid/hid-roccat-koneplus.c @@ -274,6 +274,12 @@ static ssize_t koneplus_sysfs_set_actual_profile(struct device *dev, return size; } +static DEVICE_ATTR(actual_profile, 0660, + koneplus_sysfs_show_actual_profile, + koneplus_sysfs_set_actual_profile); +static DEVICE_ATTR(startup_profile, 0660, + koneplus_sysfs_show_actual_profile, + koneplus_sysfs_set_actual_profile); static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev, struct device_attribute *attr, char *buf) @@ -293,18 +299,16 @@ static ssize_t koneplus_sysfs_show_firmware_version(struct device *dev, return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); } - -static struct device_attribute koneplus_attributes[] = { - __ATTR(actual_profile, 0660, - koneplus_sysfs_show_actual_profile, - koneplus_sysfs_set_actual_profile), - __ATTR(startup_profile, 0660, - koneplus_sysfs_show_actual_profile, - koneplus_sysfs_set_actual_profile), - __ATTR(firmware_version, 0440, - koneplus_sysfs_show_firmware_version, NULL), - __ATTR_NULL +static DEVICE_ATTR(firmware_version, 0440, + koneplus_sysfs_show_firmware_version, NULL); + +static struct attribute *koneplus_attrs[] = { + &dev_attr_actual_profile.attr, + &dev_attr_startup_profile.attr, + &dev_attr_firmware_version.attr, + NULL, }; +ATTRIBUTE_GROUPS(koneplus); static struct bin_attribute koneplus_bin_attributes[] = { KONEPLUS_BIN_ATTRIBUTE_W(control, CONTROL), @@ -572,7 +576,7 @@ static int __init koneplus_init(void) koneplus_class = class_create(THIS_MODULE, "koneplus"); if (IS_ERR(koneplus_class)) return PTR_ERR(koneplus_class); - koneplus_class->dev_attrs = koneplus_attributes; + koneplus_class->dev_groups = koneplus_groups; koneplus_class->dev_bin_attrs = koneplus_bin_attributes; retval = hid_register_driver(&koneplus_driver); diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c index b8b37789b86..ae630221f89 100644 --- a/drivers/hid/hid-roccat-kovaplus.c +++ b/drivers/hid/hid-roccat-kovaplus.c @@ -310,6 +310,9 @@ static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev, return size; } +static DEVICE_ATTR(actual_profile, 0660, + kovaplus_sysfs_show_actual_profile, + kovaplus_sysfs_set_actual_profile); static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev, struct device_attribute *attr, char *buf) @@ -318,6 +321,7 @@ static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev, hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi); } +static DEVICE_ATTR(actual_cpi, 0440, kovaplus_sysfs_show_actual_cpi, NULL); static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev, struct device_attribute *attr, char *buf) @@ -326,6 +330,8 @@ static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev, hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity); } +static DEVICE_ATTR(actual_sensitivity_x, 0440, + kovaplus_sysfs_show_actual_sensitivity_x, NULL); static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev, struct device_attribute *attr, char *buf) @@ -334,6 +340,8 @@ static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev, hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity); } +static DEVICE_ATTR(actual_sensitivity_y, 0440, + kovaplus_sysfs_show_actual_sensitivity_y, NULL); static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev, struct device_attribute *attr, char *buf) @@ -353,21 +361,18 @@ static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev, return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); } +static DEVICE_ATTR(firmware_version, 0440, + kovaplus_sysfs_show_firmware_version, NULL); -static struct device_attribute kovaplus_attributes[] = { - __ATTR(actual_cpi, 0440, - kovaplus_sysfs_show_actual_cpi, NULL), - __ATTR(firmware_version, 0440, - kovaplus_sysfs_show_firmware_version, NULL), - __ATTR(actual_profile, 0660, - kovaplus_sysfs_show_actual_profile, - kovaplus_sysfs_set_actual_profile), - __ATTR(actual_sensitivity_x, 0440, - kovaplus_sysfs_show_actual_sensitivity_x, NULL), - __ATTR(actual_sensitivity_y, 0440, - kovaplus_sysfs_show_actual_sensitivity_y, NULL), - __ATTR_NULL +static struct attribute *kovaplus_attrs[] = { + &dev_attr_actual_cpi.attr, + &dev_attr_firmware_version.attr, + &dev_attr_actual_profile.attr, + &dev_attr_actual_sensitivity_x.attr, + &dev_attr_actual_sensitivity_y.attr, + NULL, }; +ATTRIBUTE_GROUPS(kovaplus); static struct bin_attribute kovaplus_bin_attributes[] = { KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL), @@ -662,7 +667,7 @@ static int __init kovaplus_init(void) kovaplus_class = class_create(THIS_MODULE, "kovaplus"); if (IS_ERR(kovaplus_class)) return PTR_ERR(kovaplus_class); - kovaplus_class->dev_attrs = kovaplus_attributes; + kovaplus_class->dev_groups = kovaplus_groups; kovaplus_class->dev_bin_attrs = kovaplus_bin_attributes; retval = hid_register_driver(&kovaplus_driver); diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index d4f1e3bee59..7960d507ad9 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c @@ -266,6 +266,7 @@ static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev, hid_get_drvdata(dev_get_drvdata(dev->parent->parent)); return snprintf(buf, PAGE_SIZE, "%d\n", pyra->actual_cpi); } +static DEVICE_ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL); static ssize_t pyra_sysfs_show_actual_profile(struct device *dev, struct device_attribute *attr, char *buf) @@ -282,6 +283,8 @@ static ssize_t pyra_sysfs_show_actual_profile(struct device *dev, return snprintf(buf, PAGE_SIZE, "%d\n", settings.startup_profile); } +static DEVICE_ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL); +static DEVICE_ATTR(startup_profile, 0440, pyra_sysfs_show_actual_profile, NULL); static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, struct device_attribute *attr, char *buf) @@ -301,16 +304,17 @@ static ssize_t pyra_sysfs_show_firmware_version(struct device *dev, return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version); } - -static struct device_attribute pyra_attributes[] = { - __ATTR(actual_cpi, 0440, pyra_sysfs_show_actual_cpi, NULL), - __ATTR(actual_profile, 0440, pyra_sysfs_show_actual_profile, NULL), - __ATTR(firmware_version, 0440, - pyra_sysfs_show_firmware_version, NULL), - __ATTR(startup_profile, 0440, - pyra_sysfs_show_actual_profile, NULL), - __ATTR_NULL +static DEVICE_ATTR(firmware_version, 0440, pyra_sysfs_show_firmware_version, + NULL); + +static struct attribute *pyra_attrs[] = { + &dev_attr_actual_cpi.attr, + &dev_attr_actual_profile.attr, + &dev_attr_firmware_version.attr, + &dev_attr_startup_profile.attr, + NULL, }; +ATTRIBUTE_GROUPS(pyra); static struct bin_attribute pyra_bin_attributes[] = { PYRA_BIN_ATTRIBUTE_W(control, CONTROL), @@ -600,7 +604,7 @@ static int __init pyra_init(void) pyra_class = class_create(THIS_MODULE, "pyra"); if (IS_ERR(pyra_class)) return PTR_ERR(pyra_class); - pyra_class->dev_attrs = pyra_attributes; + pyra_class->dev_groups = pyra_groups; pyra_class->dev_bin_attrs = pyra_bin_attributes; retval = hid_register_driver(&pyra_driver); -- cgit v1.2.3-70-g09d2 From 13e2237f36874a7abef44b98969f399127b1917d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:14 -0700 Subject: v4l2: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the v4l2 class code to use the correct field. Cc: Mauro Carvalho Chehab Cc: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/media/v4l2-core/v4l2-dev.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'drivers') diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index c8859d6ff6a..b0f49b014bc 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -38,24 +38,25 @@ * sysfs stuff */ -static ssize_t show_index(struct device *cd, - struct device_attribute *attr, char *buf) +static ssize_t index_show(struct device *cd, + struct device_attribute *attr, char *buf) { struct video_device *vdev = to_video_device(cd); return sprintf(buf, "%i\n", vdev->index); } +static DEVICE_ATTR_RO(index); -static ssize_t show_debug(struct device *cd, - struct device_attribute *attr, char *buf) +static ssize_t debug_show(struct device *cd, + struct device_attribute *attr, char *buf) { struct video_device *vdev = to_video_device(cd); return sprintf(buf, "%i\n", vdev->debug); } -static ssize_t set_debug(struct device *cd, struct device_attribute *attr, - const char *buf, size_t len) +static ssize_t debug_store(struct device *cd, struct device_attribute *attr, + const char *buf, size_t len) { struct video_device *vdev = to_video_device(cd); int res = 0; @@ -68,21 +69,24 @@ static ssize_t set_debug(struct device *cd, struct device_attribute *attr, vdev->debug = value; return len; } +static DEVICE_ATTR_RW(debug); -static ssize_t show_name(struct device *cd, +static ssize_t name_show(struct device *cd, struct device_attribute *attr, char *buf) { struct video_device *vdev = to_video_device(cd); return sprintf(buf, "%.*s\n", (int)sizeof(vdev->name), vdev->name); } +static DEVICE_ATTR_RO(name); -static struct device_attribute video_device_attrs[] = { - __ATTR(name, S_IRUGO, show_name, NULL), - __ATTR(debug, 0644, show_debug, set_debug), - __ATTR(index, S_IRUGO, show_index, NULL), - __ATTR_NULL +static struct attribute *video_device_attrs[] = { + &dev_attr_name.attr, + &dev_attr_debug.attr, + &dev_attr_index.attr, + NULL, }; +ATTRIBUTE_GROUPS(video_device); /* * Active devices @@ -217,7 +221,7 @@ static void v4l2_device_release(struct device *cd) static struct class video_class = { .name = VIDEO_NAME, - .dev_attrs = video_device_attrs, + .dev_groups = video_device_groups, }; struct video_device *video_devdata(struct file *file) -- cgit v1.2.3-70-g09d2 From e80b89a5f1a4db0ce841f9baf2a192b37e8815e1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:18 -0700 Subject: x86: wmi: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the wmi class code to use the correct field. Cc: Matthew Garrett Signed-off-by: Greg Kroah-Hartman --- drivers/platform/x86/wmi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index b13344c5980..6e02c953d88 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -693,11 +693,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, return sprintf(buf, "wmi:%s\n", guid_string); } +static DEVICE_ATTR_RO(modalias); -static struct device_attribute wmi_dev_attrs[] = { - __ATTR_RO(modalias), - __ATTR_NULL +static struct attribute *wmi_attrs[] = { + &dev_attr_modalias.attr, + NULL, }; +ATTRIBUTE_GROUPS(wmi); static int wmi_dev_uevent(struct device *dev, struct kobj_uevent_env *env) { @@ -732,7 +734,7 @@ static struct class wmi_class = { .name = "wmi", .dev_release = wmi_dev_free, .dev_uevent = wmi_dev_uevent, - .dev_attrs = wmi_dev_attrs, + .dev_groups = wmi_groups, }; static int wmi_create_device(const struct guid_block *gblock, -- cgit v1.2.3-70-g09d2 From bd0eae4e1cd5c4ff7c2a9ebcb3e78ea4631251ef Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:19 -0700 Subject: PPS: convert class code to use dev_groups The dev_attrs field of struct class is going away soon, dev_groups should be used instead. This converts the pps class code to use the correct field. Cc: Rodolfo Giometti Signed-off-by: Greg Kroah-Hartman --- drivers/pps/pps.c | 2 +- drivers/pps/sysfs.c | 55 +++++++++++++++++++++++++++++----------------- include/linux/pps_kernel.h | 2 +- 3 files changed, 37 insertions(+), 22 deletions(-) (limited to 'drivers') diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c index 7173e3ad475..2f07cd61566 100644 --- a/drivers/pps/pps.c +++ b/drivers/pps/pps.c @@ -406,7 +406,7 @@ static int __init pps_init(void) pr_err("failed to allocate class\n"); return PTR_ERR(pps_class); } - pps_class->dev_attrs = pps_attrs; + pps_class->dev_groups = pps_groups; err = alloc_chrdev_region(&pps_devt, 0, PPS_MAX_SOURCES, "pps"); if (err < 0) { diff --git a/drivers/pps/sysfs.c b/drivers/pps/sysfs.c index ef0978c71ee..aefb75d6709 100644 --- a/drivers/pps/sysfs.c +++ b/drivers/pps/sysfs.c @@ -29,8 +29,8 @@ * Attribute functions */ -static ssize_t pps_show_assert(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t assert_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct pps_device *pps = dev_get_drvdata(dev); @@ -41,9 +41,10 @@ static ssize_t pps_show_assert(struct device *dev, (long long) pps->assert_tu.sec, pps->assert_tu.nsec, pps->assert_sequence); } +static DEVICE_ATTR_RO(assert); -static ssize_t pps_show_clear(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t clear_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct pps_device *pps = dev_get_drvdata(dev); @@ -54,45 +55,59 @@ static ssize_t pps_show_clear(struct device *dev, (long long) pps->clear_tu.sec, pps->clear_tu.nsec, pps->clear_sequence); } +static DEVICE_ATTR_RO(clear); -static ssize_t pps_show_mode(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t mode_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct pps_device *pps = dev_get_drvdata(dev); return sprintf(buf, "%4x\n", pps->info.mode); } +static DEVICE_ATTR_RO(mode); -static ssize_t pps_show_echo(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t echo_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct pps_device *pps = dev_get_drvdata(dev); return sprintf(buf, "%d\n", !!pps->info.echo); } +static DEVICE_ATTR_RO(echo); -static ssize_t pps_show_name(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t name_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct pps_device *pps = dev_get_drvdata(dev); return sprintf(buf, "%s\n", pps->info.name); } +static DEVICE_ATTR_RO(name); -static ssize_t pps_show_path(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t path_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct pps_device *pps = dev_get_drvdata(dev); return sprintf(buf, "%s\n", pps->info.path); } +static DEVICE_ATTR_RO(path); + +static struct attribute *pps_attrs[] = { + &dev_attr_assert.attr, + &dev_attr_clear.attr, + &dev_attr_mode.attr, + &dev_attr_echo.attr, + &dev_attr_name.attr, + &dev_attr_path.attr, + NULL, +}; + +static const struct attribute_group pps_group = { + .attrs = pps_attrs, +}; -struct device_attribute pps_attrs[] = { - __ATTR(assert, S_IRUGO, pps_show_assert, NULL), - __ATTR(clear, S_IRUGO, pps_show_clear, NULL), - __ATTR(mode, S_IRUGO, pps_show_mode, NULL), - __ATTR(echo, S_IRUGO, pps_show_echo, NULL), - __ATTR(name, S_IRUGO, pps_show_name, NULL), - __ATTR(path, S_IRUGO, pps_show_path, NULL), - __ATTR_NULL, +const struct attribute_group *pps_groups[] = { + &pps_group, + NULL, }; diff --git a/include/linux/pps_kernel.h b/include/linux/pps_kernel.h index 7db3eb93a07..1d2cd21242e 100644 --- a/include/linux/pps_kernel.h +++ b/include/linux/pps_kernel.h @@ -80,7 +80,7 @@ struct pps_device { * Global variables */ -extern struct device_attribute pps_attrs[]; +extern const struct attribute_group *pps_groups[]; /* * Internal functions. -- cgit v1.2.3-70-g09d2 From e0a00d86000729caf3a3e60732723183ebb6b144 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Aug 2013 21:40:26 -0700 Subject: hid: roccat-arvo: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-arvo.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-arvo.c b/drivers/hid/hid-roccat-arvo.c index 98bb89e0d91..eed7f52084c 100644 --- a/drivers/hid/hid-roccat-arvo.c +++ b/drivers/hid/hid-roccat-arvo.c @@ -237,6 +237,8 @@ static ssize_t arvo_sysfs_write_button(struct file *fp, return arvo_sysfs_write(fp, kobj, buf, off, count, sizeof(struct arvo_button), ARVO_COMMAND_BUTTON); } +static BIN_ATTR(button, 0220, NULL, arvo_sysfs_write_button, + sizeof(struct arvo_button)); static ssize_t arvo_sysfs_read_info(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, @@ -245,6 +247,8 @@ static ssize_t arvo_sysfs_read_info(struct file *fp, return arvo_sysfs_read(fp, kobj, buf, off, count, sizeof(struct arvo_info), ARVO_COMMAND_INFO); } +static BIN_ATTR(info, 0440, arvo_sysfs_read_info, NULL, + sizeof(struct arvo_info)); static struct attribute *arvo_attrs[] = { &dev_attr_mode_key.attr, @@ -252,20 +256,21 @@ static struct attribute *arvo_attrs[] = { &dev_attr_actual_profile.attr, NULL, }; -ATTRIBUTE_GROUPS(arvo); - -static struct bin_attribute arvo_bin_attributes[] = { - { - .attr = { .name = "button", .mode = 0220 }, - .size = sizeof(struct arvo_button), - .write = arvo_sysfs_write_button - }, - { - .attr = { .name = "info", .mode = 0440 }, - .size = sizeof(struct arvo_info), - .read = arvo_sysfs_read_info - }, - __ATTR_NULL + +static struct bin_attribute *arvo_bin_attributes[] = { + &bin_attr_button, + &bin_attr_info, + NULL, +}; + +static const struct attribute_group arvo_group = { + .attrs = arvo_attrs, + .bin_attrs = arvo_bin_attributes, +}; + +static const struct attribute_group *arvo_groups[] = { + &arvo_group, + NULL, }; static int arvo_init_arvo_device_struct(struct usb_device *usb_dev, @@ -434,7 +439,6 @@ static int __init arvo_init(void) if (IS_ERR(arvo_class)) return PTR_ERR(arvo_class); arvo_class->dev_groups = arvo_groups; - arvo_class->dev_bin_attrs = arvo_bin_attributes; retval = hid_register_driver(&arvo_driver); if (retval) -- cgit v1.2.3-70-g09d2 From 8daf8c3aa6b4cad8ec5b286c75c3115d7fbf3fdf Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Aug 2013 21:40:26 -0700 Subject: hid: roccat-isku: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-isku.c | 87 ++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 38 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-isku.c b/drivers/hid/hid-roccat-isku.c index 3983dec062d..b7a4e10e112 100644 --- a/drivers/hid/hid-roccat-isku.c +++ b/drivers/hid/hid-roccat-isku.c @@ -116,7 +116,6 @@ static struct attribute *isku_attrs[] = { &dev_attr_actual_profile.attr, NULL, }; -ATTRIBUTE_GROUPS(isku); static ssize_t isku_sysfs_read(struct file *fp, struct kobject *kobj, char *buf, loff_t off, size_t count, @@ -185,7 +184,8 @@ ISKU_SYSFS_R(thingy, THINGY) \ ISKU_SYSFS_W(thingy, THINGY) #define ISKU_BIN_ATTR_RW(thingy, THINGY) \ -{ \ +ISKU_SYSFS_RW(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0660 }, \ .size = ISKU_SIZE_ ## THINGY, \ .read = isku_sysfs_read_ ## thingy, \ @@ -193,52 +193,64 @@ ISKU_SYSFS_W(thingy, THINGY) } #define ISKU_BIN_ATTR_R(thingy, THINGY) \ -{ \ +ISKU_SYSFS_R(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0440 }, \ .size = ISKU_SIZE_ ## THINGY, \ .read = isku_sysfs_read_ ## thingy, \ } #define ISKU_BIN_ATTR_W(thingy, THINGY) \ -{ \ +ISKU_SYSFS_W(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0220 }, \ .size = ISKU_SIZE_ ## THINGY, \ .write = isku_sysfs_write_ ## thingy \ } -ISKU_SYSFS_RW(macro, MACRO) -ISKU_SYSFS_RW(keys_function, KEYS_FUNCTION) -ISKU_SYSFS_RW(keys_easyzone, KEYS_EASYZONE) -ISKU_SYSFS_RW(keys_media, KEYS_MEDIA) -ISKU_SYSFS_RW(keys_thumbster, KEYS_THUMBSTER) -ISKU_SYSFS_RW(keys_macro, KEYS_MACRO) -ISKU_SYSFS_RW(keys_capslock, KEYS_CAPSLOCK) -ISKU_SYSFS_RW(light, LIGHT) -ISKU_SYSFS_RW(key_mask, KEY_MASK) -ISKU_SYSFS_RW(last_set, LAST_SET) -ISKU_SYSFS_W(talk, TALK) -ISKU_SYSFS_W(talkfx, TALKFX) -ISKU_SYSFS_R(info, INFO) -ISKU_SYSFS_W(control, CONTROL) -ISKU_SYSFS_W(reset, RESET) - -static struct bin_attribute isku_bin_attributes[] = { - ISKU_BIN_ATTR_RW(macro, MACRO), - ISKU_BIN_ATTR_RW(keys_function, KEYS_FUNCTION), - ISKU_BIN_ATTR_RW(keys_easyzone, KEYS_EASYZONE), - ISKU_BIN_ATTR_RW(keys_media, KEYS_MEDIA), - ISKU_BIN_ATTR_RW(keys_thumbster, KEYS_THUMBSTER), - ISKU_BIN_ATTR_RW(keys_macro, KEYS_MACRO), - ISKU_BIN_ATTR_RW(keys_capslock, KEYS_CAPSLOCK), - ISKU_BIN_ATTR_RW(light, LIGHT), - ISKU_BIN_ATTR_RW(key_mask, KEY_MASK), - ISKU_BIN_ATTR_RW(last_set, LAST_SET), - ISKU_BIN_ATTR_W(talk, TALK), - ISKU_BIN_ATTR_W(talkfx, TALKFX), - ISKU_BIN_ATTR_R(info, INFO), - ISKU_BIN_ATTR_W(control, CONTROL), - ISKU_BIN_ATTR_W(reset, RESET), - __ATTR_NULL +ISKU_BIN_ATTR_RW(macro, MACRO); +ISKU_BIN_ATTR_RW(keys_function, KEYS_FUNCTION); +ISKU_BIN_ATTR_RW(keys_easyzone, KEYS_EASYZONE); +ISKU_BIN_ATTR_RW(keys_media, KEYS_MEDIA); +ISKU_BIN_ATTR_RW(keys_thumbster, KEYS_THUMBSTER); +ISKU_BIN_ATTR_RW(keys_macro, KEYS_MACRO); +ISKU_BIN_ATTR_RW(keys_capslock, KEYS_CAPSLOCK); +ISKU_BIN_ATTR_RW(light, LIGHT); +ISKU_BIN_ATTR_RW(key_mask, KEY_MASK); +ISKU_BIN_ATTR_RW(last_set, LAST_SET); +ISKU_BIN_ATTR_W(talk, TALK); +ISKU_BIN_ATTR_W(talkfx, TALKFX); +ISKU_BIN_ATTR_W(control, CONTROL); +ISKU_BIN_ATTR_W(reset, RESET); +ISKU_BIN_ATTR_R(info, INFO); + +static struct bin_attribute *isku_bin_attributes[] = { + &bin_attr_macro, + &bin_attr_keys_function, + &bin_attr_keys_easyzone, + &bin_attr_keys_media, + &bin_attr_keys_thumbster, + &bin_attr_keys_macro, + &bin_attr_keys_capslock, + &bin_attr_light, + &bin_attr_key_mask, + &bin_attr_last_set, + &bin_attr_talk, + &bin_attr_talkfx, + &bin_attr_control, + &bin_attr_reset, + &bin_attr_info, + NULL, +}; + +static const struct attribute_group isku_group = { + .attrs = isku_attrs, + .bin_attrs = isku_bin_attributes, +}; + +static const struct attribute_group *isku_groups[] = { + &isku_group, + NULL, }; static int isku_init_isku_device_struct(struct usb_device *usb_dev, @@ -429,7 +441,6 @@ static int __init isku_init(void) if (IS_ERR(isku_class)) return PTR_ERR(isku_class); isku_class->dev_groups = isku_groups; - isku_class->dev_bin_attrs = isku_bin_attributes; retval = hid_register_driver(&isku_driver); if (retval) -- cgit v1.2.3-70-g09d2 From 71b230af939ced7d67b65e7060e25d4cb18039ef Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Aug 2013 21:40:26 -0700 Subject: hid: roccat-kone: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-kone.c | 80 ++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 46 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c index d36267339e3..5eddf834c05 100644 --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c @@ -324,6 +324,8 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj, return sizeof(struct kone_settings); } +static BIN_ATTR(settings, 0660, kone_sysfs_read_settings, + kone_sysfs_write_settings, sizeof(struct kone_settings)); static ssize_t kone_sysfs_read_profilex(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, @@ -378,6 +380,19 @@ static ssize_t kone_sysfs_write_profilex(struct file *fp, return sizeof(struct kone_profile); } +#define PROFILE_ATTR(number) \ +static struct bin_attribute bin_attr_profile##number = { \ + .attr = { .name = "profile##number", .mode = 0660 }, \ + .size = sizeof(struct kone_profile), \ + .read = kone_sysfs_read_profilex, \ + .write = kone_sysfs_write_profilex, \ + .private = &profile_numbers[number], \ +}; +PROFILE_ATTR(1); +PROFILE_ATTR(2); +PROFILE_ATTR(3); +PROFILE_ATTR(4); +PROFILE_ATTR(5); static ssize_t kone_sysfs_show_actual_profile(struct device *dev, struct device_attribute *attr, char *buf) @@ -616,51 +631,25 @@ static struct attribute *kone_attrs[] = { &dev_attr_startup_profile.attr, NULL, }; -ATTRIBUTE_GROUPS(kone); - -static struct bin_attribute kone_bin_attributes[] = { - { - .attr = { .name = "settings", .mode = 0660 }, - .size = sizeof(struct kone_settings), - .read = kone_sysfs_read_settings, - .write = kone_sysfs_write_settings - }, - { - .attr = { .name = "profile1", .mode = 0660 }, - .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profilex, - .write = kone_sysfs_write_profilex, - .private = &profile_numbers[0] - }, - { - .attr = { .name = "profile2", .mode = 0660 }, - .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profilex, - .write = kone_sysfs_write_profilex, - .private = &profile_numbers[1] - }, - { - .attr = { .name = "profile3", .mode = 0660 }, - .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profilex, - .write = kone_sysfs_write_profilex, - .private = &profile_numbers[2] - }, - { - .attr = { .name = "profile4", .mode = 0660 }, - .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profilex, - .write = kone_sysfs_write_profilex, - .private = &profile_numbers[3] - }, - { - .attr = { .name = "profile5", .mode = 0660 }, - .size = sizeof(struct kone_profile), - .read = kone_sysfs_read_profilex, - .write = kone_sysfs_write_profilex, - .private = &profile_numbers[4] - }, - __ATTR_NULL + +static struct bin_attribute *kone_bin_attributes[] = { + &bin_attr_settings, + &bin_attr_profile1, + &bin_attr_profile2, + &bin_attr_profile3, + &bin_attr_profile4, + &bin_attr_profile5, + NULL, +}; + +static const struct attribute_group kone_group = { + .attrs = kone_attrs, + .bin_attrs = kone_bin_attributes, +}; + +static const struct attribute_group *kone_groups[] = { + &kone_group, + NULL, }; static int kone_init_kone_device_struct(struct usb_device *usb_dev, @@ -898,7 +887,6 @@ static int __init kone_init(void) if (IS_ERR(kone_class)) return PTR_ERR(kone_class); kone_class->dev_groups = kone_groups; - kone_class->dev_bin_attrs = kone_bin_attributes; retval = hid_register_driver(&kone_driver); if (retval) -- cgit v1.2.3-70-g09d2 From 080795482566ecaf599bfa8cb5656ff13ca4a4ce Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Aug 2013 21:40:27 -0700 Subject: hid: roccat-savu: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-savu.c | 58 +++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-savu.c b/drivers/hid/hid-roccat-savu.c index 31747a29c09..0332267199d 100644 --- a/drivers/hid/hid-roccat-savu.c +++ b/drivers/hid/hid-roccat-savu.c @@ -94,44 +94,48 @@ SAVU_SYSFS_W(thingy, THINGY) \ SAVU_SYSFS_R(thingy, THINGY) #define SAVU_BIN_ATTRIBUTE_RW(thingy, THINGY) \ -{ \ +SAVU_SYSFS_RW(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0660 }, \ .size = SAVU_SIZE_ ## THINGY, \ .read = savu_sysfs_read_ ## thingy, \ .write = savu_sysfs_write_ ## thingy \ } -#define SAVU_BIN_ATTRIBUTE_R(thingy, THINGY) \ -{ \ - .attr = { .name = #thingy, .mode = 0440 }, \ - .size = SAVU_SIZE_ ## THINGY, \ - .read = savu_sysfs_read_ ## thingy, \ -} - #define SAVU_BIN_ATTRIBUTE_W(thingy, THINGY) \ -{ \ +SAVU_SYSFS_W(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0220 }, \ .size = SAVU_SIZE_ ## THINGY, \ .write = savu_sysfs_write_ ## thingy \ } -SAVU_SYSFS_W(control, CONTROL) -SAVU_SYSFS_RW(profile, PROFILE) -SAVU_SYSFS_RW(general, GENERAL) -SAVU_SYSFS_RW(buttons, BUTTONS) -SAVU_SYSFS_RW(macro, MACRO) -SAVU_SYSFS_RW(info, INFO) -SAVU_SYSFS_RW(sensor, SENSOR) - -static struct bin_attribute savu_bin_attributes[] = { - SAVU_BIN_ATTRIBUTE_W(control, CONTROL), - SAVU_BIN_ATTRIBUTE_RW(profile, PROFILE), - SAVU_BIN_ATTRIBUTE_RW(general, GENERAL), - SAVU_BIN_ATTRIBUTE_RW(buttons, BUTTONS), - SAVU_BIN_ATTRIBUTE_RW(macro, MACRO), - SAVU_BIN_ATTRIBUTE_RW(info, INFO), - SAVU_BIN_ATTRIBUTE_RW(sensor, SENSOR), - __ATTR_NULL +SAVU_BIN_ATTRIBUTE_W(control, CONTROL); +SAVU_BIN_ATTRIBUTE_RW(profile, PROFILE); +SAVU_BIN_ATTRIBUTE_RW(general, GENERAL); +SAVU_BIN_ATTRIBUTE_RW(buttons, BUTTONS); +SAVU_BIN_ATTRIBUTE_RW(macro, MACRO); +SAVU_BIN_ATTRIBUTE_RW(info, INFO); +SAVU_BIN_ATTRIBUTE_RW(sensor, SENSOR); + +static struct bin_attribute *savu_bin_attributes[] = { + &bin_attr_control, + &bin_attr_profile, + &bin_attr_general, + &bin_attr_buttons, + &bin_attr_macro, + &bin_attr_info, + &bin_attr_sensor, + NULL, +}; + +static const struct attribute_group savu_group = { + .bin_attrs = savu_bin_attributes, +}; + +static const struct attribute_group *savu_groups[] = { + &savu_group, + NULL, }; static int savu_init_savu_device_struct(struct usb_device *usb_dev, @@ -294,7 +298,7 @@ static int __init savu_init(void) savu_class = class_create(THIS_MODULE, "savu"); if (IS_ERR(savu_class)) return PTR_ERR(savu_class); - savu_class->dev_bin_attrs = savu_bin_attributes; + savu_class->dev_groups = savu_groups; retval = hid_register_driver(&savu_driver); if (retval) -- cgit v1.2.3-70-g09d2 From eb3156e0a6cdde402cdf3bcc7e2ecc98d7ac5c49 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Aug 2013 21:50:27 -0700 Subject: hid: roccat-koneplus: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-koneplus.c | 153 ++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 87 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-koneplus.c b/drivers/hid/hid-roccat-koneplus.c index 11906b4b42b..db4d8b6a254 100644 --- a/drivers/hid/hid-roccat-koneplus.c +++ b/drivers/hid/hid-roccat-koneplus.c @@ -156,7 +156,8 @@ KONEPLUS_SYSFS_W(thingy, THINGY) \ KONEPLUS_SYSFS_R(thingy, THINGY) #define KONEPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \ -{ \ +KONEPLUS_SYSFS_RW(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0660 }, \ .size = KONEPLUS_SIZE_ ## THINGY, \ .read = koneplus_sysfs_read_ ## thingy, \ @@ -164,28 +165,29 @@ KONEPLUS_SYSFS_R(thingy, THINGY) } #define KONEPLUS_BIN_ATTRIBUTE_R(thingy, THINGY) \ -{ \ +KONEPLUS_SYSFS_R(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0440 }, \ .size = KONEPLUS_SIZE_ ## THINGY, \ .read = koneplus_sysfs_read_ ## thingy, \ } #define KONEPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \ -{ \ +KONEPLUS_SYSFS_W(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0220 }, \ .size = KONEPLUS_SIZE_ ## THINGY, \ .write = koneplus_sysfs_write_ ## thingy \ } - -KONEPLUS_SYSFS_W(control, CONTROL) -KONEPLUS_SYSFS_RW(info, INFO) -KONEPLUS_SYSFS_W(talk, TALK) -KONEPLUS_SYSFS_W(macro, MACRO) -KONEPLUS_SYSFS_RW(sensor, SENSOR) -KONEPLUS_SYSFS_RW(tcu, TCU) -KONEPLUS_SYSFS_R(tcu_image, TCU_IMAGE) -KONEPLUS_SYSFS_RW(profile_settings, PROFILE_SETTINGS) -KONEPLUS_SYSFS_RW(profile_buttons, PROFILE_BUTTONS) +KONEPLUS_BIN_ATTRIBUTE_W(control, CONTROL); +KONEPLUS_BIN_ATTRIBUTE_W(talk, TALK); +KONEPLUS_BIN_ATTRIBUTE_W(macro, MACRO); +KONEPLUS_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE); +KONEPLUS_BIN_ATTRIBUTE_RW(info, INFO); +KONEPLUS_BIN_ATTRIBUTE_RW(sensor, SENSOR); +KONEPLUS_BIN_ATTRIBUTE_RW(tcu, TCU); +KONEPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS); +KONEPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, @@ -225,6 +227,25 @@ static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp, KONEPLUS_COMMAND_PROFILE_BUTTONS); } +#define PROFILE_ATTR(number) \ +static struct bin_attribute bin_attr_profile##number##_settings = { \ + .attr = { .name = "profile##number##_settings", .mode = 0440 }, \ + .size = KONEPLUS_SIZE_PROFILE_SETTINGS, \ + .read = koneplus_sysfs_read_profilex_settings, \ + .private = &profile_numbers[number-1], \ +}; \ +static struct bin_attribute bin_attr_profile##number##_buttons = { \ + .attr = { .name = "profile##number##_buttons", .mode = 0440 }, \ + .size = KONEPLUS_SIZE_PROFILE_BUTTONS, \ + .read = koneplus_sysfs_read_profilex_buttons, \ + .private = &profile_numbers[number-1], \ +}; +PROFILE_ATTR(1); +PROFILE_ATTR(2); +PROFILE_ATTR(3); +PROFILE_ATTR(4); +PROFILE_ATTR(5); + static ssize_t koneplus_sysfs_show_actual_profile(struct device *dev, struct device_attribute *attr, char *buf) { @@ -308,79 +329,38 @@ static struct attribute *koneplus_attrs[] = { &dev_attr_firmware_version.attr, NULL, }; -ATTRIBUTE_GROUPS(koneplus); - -static struct bin_attribute koneplus_bin_attributes[] = { - KONEPLUS_BIN_ATTRIBUTE_W(control, CONTROL), - KONEPLUS_BIN_ATTRIBUTE_RW(info, INFO), - KONEPLUS_BIN_ATTRIBUTE_W(talk, TALK), - KONEPLUS_BIN_ATTRIBUTE_W(macro, MACRO), - KONEPLUS_BIN_ATTRIBUTE_RW(sensor, SENSOR), - KONEPLUS_BIN_ATTRIBUTE_RW(tcu, TCU), - KONEPLUS_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE), - KONEPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS), - KONEPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS), - { - .attr = { .name = "profile1_settings", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_SETTINGS, - .read = koneplus_sysfs_read_profilex_settings, - .private = &profile_numbers[0] - }, - { - .attr = { .name = "profile2_settings", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_SETTINGS, - .read = koneplus_sysfs_read_profilex_settings, - .private = &profile_numbers[1] - }, - { - .attr = { .name = "profile3_settings", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_SETTINGS, - .read = koneplus_sysfs_read_profilex_settings, - .private = &profile_numbers[2] - }, - { - .attr = { .name = "profile4_settings", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_SETTINGS, - .read = koneplus_sysfs_read_profilex_settings, - .private = &profile_numbers[3] - }, - { - .attr = { .name = "profile5_settings", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_SETTINGS, - .read = koneplus_sysfs_read_profilex_settings, - .private = &profile_numbers[4] - }, - { - .attr = { .name = "profile1_buttons", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_BUTTONS, - .read = koneplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[0] - }, - { - .attr = { .name = "profile2_buttons", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_BUTTONS, - .read = koneplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[1] - }, - { - .attr = { .name = "profile3_buttons", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_BUTTONS, - .read = koneplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[2] - }, - { - .attr = { .name = "profile4_buttons", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_BUTTONS, - .read = koneplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[3] - }, - { - .attr = { .name = "profile5_buttons", .mode = 0440 }, - .size = KONEPLUS_SIZE_PROFILE_BUTTONS, - .read = koneplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[4] - }, - __ATTR_NULL + +static struct bin_attribute *koneplus_bin_attributes[] = { + &bin_attr_control, + &bin_attr_talk, + &bin_attr_macro, + &bin_attr_tcu_image, + &bin_attr_info, + &bin_attr_sensor, + &bin_attr_tcu, + &bin_attr_profile_settings, + &bin_attr_profile_buttons, + &bin_attr_profile1_settings, + &bin_attr_profile2_settings, + &bin_attr_profile3_settings, + &bin_attr_profile4_settings, + &bin_attr_profile5_settings, + &bin_attr_profile1_buttons, + &bin_attr_profile2_buttons, + &bin_attr_profile3_buttons, + &bin_attr_profile4_buttons, + &bin_attr_profile5_buttons, + NULL, +}; + +static const struct attribute_group koneplus_group = { + .attrs = koneplus_attrs, + .bin_attrs = koneplus_bin_attributes, +}; + +static const struct attribute_group *koneplus_groups[] = { + &koneplus_group, + NULL, }; static int koneplus_init_koneplus_device_struct(struct usb_device *usb_dev, @@ -577,7 +557,6 @@ static int __init koneplus_init(void) if (IS_ERR(koneplus_class)) return PTR_ERR(koneplus_class); koneplus_class->dev_groups = koneplus_groups; - koneplus_class->dev_bin_attrs = koneplus_bin_attributes; retval = hid_register_driver(&koneplus_driver); if (retval) -- cgit v1.2.3-70-g09d2 From 0f1947f3561e7e6df7164cf1e0f14f541ddc29bd Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Aug 2013 21:50:28 -0700 Subject: hid: roccat-konepure: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-konepure.c | 67 +++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-konepure.c b/drivers/hid/hid-roccat-konepure.c index c79d0b06c14..fa02b1f4497 100644 --- a/drivers/hid/hid-roccat-konepure.c +++ b/drivers/hid/hid-roccat-konepure.c @@ -94,7 +94,8 @@ KONEPURE_SYSFS_W(thingy, THINGY) \ KONEPURE_SYSFS_R(thingy, THINGY) #define KONEPURE_BIN_ATTRIBUTE_RW(thingy, THINGY) \ -{ \ +KONEPURE_SYSFS_RW(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0660 }, \ .size = KONEPURE_SIZE_ ## THINGY, \ .read = konepure_sysfs_read_ ## thingy, \ @@ -102,44 +103,56 @@ KONEPURE_SYSFS_R(thingy, THINGY) } #define KONEPURE_BIN_ATTRIBUTE_R(thingy, THINGY) \ -{ \ +KONEPURE_SYSFS_R(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0440 }, \ .size = KONEPURE_SIZE_ ## THINGY, \ .read = konepure_sysfs_read_ ## thingy, \ } #define KONEPURE_BIN_ATTRIBUTE_W(thingy, THINGY) \ -{ \ +KONEPURE_SYSFS_W(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0220 }, \ .size = KONEPURE_SIZE_ ## THINGY, \ .write = konepure_sysfs_write_ ## thingy \ } -KONEPURE_SYSFS_RW(actual_profile, ACTUAL_PROFILE) -KONEPURE_SYSFS_W(control, CONTROL) -KONEPURE_SYSFS_RW(info, INFO) -KONEPURE_SYSFS_W(talk, TALK) -KONEPURE_SYSFS_W(macro, MACRO) -KONEPURE_SYSFS_RW(sensor, SENSOR) -KONEPURE_SYSFS_RW(tcu, TCU) -KONEPURE_SYSFS_R(tcu_image, TCU_IMAGE) -KONEPURE_SYSFS_RW(profile_settings, PROFILE_SETTINGS) -KONEPURE_SYSFS_RW(profile_buttons, PROFILE_BUTTONS) - -static struct bin_attribute konepure_bin_attributes[] = { - KONEPURE_BIN_ATTRIBUTE_RW(actual_profile, ACTUAL_PROFILE), - KONEPURE_BIN_ATTRIBUTE_W(control, CONTROL), - KONEPURE_BIN_ATTRIBUTE_RW(info, INFO), - KONEPURE_BIN_ATTRIBUTE_W(talk, TALK), - KONEPURE_BIN_ATTRIBUTE_W(macro, MACRO), - KONEPURE_BIN_ATTRIBUTE_RW(sensor, SENSOR), - KONEPURE_BIN_ATTRIBUTE_RW(tcu, TCU), - KONEPURE_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE), - KONEPURE_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS), - KONEPURE_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS), - __ATTR_NULL +KONEPURE_BIN_ATTRIBUTE_RW(actual_profile, ACTUAL_PROFILE); +KONEPURE_BIN_ATTRIBUTE_RW(info, INFO); +KONEPURE_BIN_ATTRIBUTE_RW(sensor, SENSOR); +KONEPURE_BIN_ATTRIBUTE_RW(tcu, TCU); +KONEPURE_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS); +KONEPURE_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); +KONEPURE_BIN_ATTRIBUTE_W(control, CONTROL); +KONEPURE_BIN_ATTRIBUTE_W(talk, TALK); +KONEPURE_BIN_ATTRIBUTE_W(macro, MACRO); +KONEPURE_BIN_ATTRIBUTE_R(tcu_image, TCU_IMAGE); + +static struct bin_attribute *konepure_bin_attributes[] = { + &bin_attr_actual_profile, + &bin_attr_info, + &bin_attr_sensor, + &bin_attr_tcu, + &bin_attr_profile_settings, + &bin_attr_profile_buttons, + &bin_attr_control, + &bin_attr_talk, + &bin_attr_macro, + &bin_attr_tcu_image, + NULL, +}; + +static const struct attribute_group konepure_group = { + .bin_attrs = konepure_bin_attributes, +}; + +static const struct attribute_group *konepure_groups[] = { + &konepure_group, + NULL, }; + static int konepure_init_konepure_device_struct(struct usb_device *usb_dev, struct konepure_device *konepure) { @@ -282,7 +295,7 @@ static int __init konepure_init(void) konepure_class = class_create(THIS_MODULE, "konepure"); if (IS_ERR(konepure_class)) return PTR_ERR(konepure_class); - konepure_class->dev_bin_attrs = konepure_bin_attributes; + konepure_class->dev_groups = konepure_groups; retval = hid_register_driver(&konepure_driver); if (retval) -- cgit v1.2.3-70-g09d2 From 975b53cc903033b7ac30a37e06452394d6734018 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Aug 2013 21:50:28 -0700 Subject: hid: roccat-kovaplus: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-kovaplus.c | 137 +++++++++++++++----------------------- 1 file changed, 54 insertions(+), 83 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c index ae630221f89..8a0f2993411 100644 --- a/drivers/hid/hid-roccat-kovaplus.c +++ b/drivers/hid/hid-roccat-kovaplus.c @@ -197,31 +197,25 @@ KOVAPLUS_SYSFS_W(thingy, THINGY) \ KOVAPLUS_SYSFS_R(thingy, THINGY) #define KOVAPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \ -{ \ +KOVAPLUS_SYSFS_RW(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0660 }, \ .size = KOVAPLUS_SIZE_ ## THINGY, \ .read = kovaplus_sysfs_read_ ## thingy, \ .write = kovaplus_sysfs_write_ ## thingy \ } -#define KOVAPLUS_BIN_ATTRIBUTE_R(thingy, THINGY) \ -{ \ - .attr = { .name = #thingy, .mode = 0440 }, \ - .size = KOVAPLUS_SIZE_ ## THINGY, \ - .read = kovaplus_sysfs_read_ ## thingy, \ -} - #define KOVAPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \ -{ \ +KOVAPLUS_SYSFS_W(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0220 }, \ .size = KOVAPLUS_SIZE_ ## THINGY, \ .write = kovaplus_sysfs_write_ ## thingy \ } - -KOVAPLUS_SYSFS_W(control, CONTROL) -KOVAPLUS_SYSFS_RW(info, INFO) -KOVAPLUS_SYSFS_RW(profile_settings, PROFILE_SETTINGS) -KOVAPLUS_SYSFS_RW(profile_buttons, PROFILE_BUTTONS) +KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL); +KOVAPLUS_BIN_ATTRIBUTE_RW(info, INFO); +KOVAPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS); +KOVAPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, @@ -261,6 +255,25 @@ static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp, KOVAPLUS_COMMAND_PROFILE_BUTTONS); } +#define PROFILE_ATTR(number) \ +static struct bin_attribute bin_attr_profile##number##_settings = { \ + .attr = { .name = "profile##number##_settings", .mode = 0440 }, \ + .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, \ + .read = kovaplus_sysfs_read_profilex_settings, \ + .private = &profile_numbers[number-1], \ +}; \ +static struct bin_attribute bin_attr_profile##number##_buttons = { \ + .attr = { .name = "profile##number##_buttons", .mode = 0440 }, \ + .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, \ + .read = kovaplus_sysfs_read_profilex_buttons, \ + .private = &profile_numbers[number-1], \ +}; +PROFILE_ATTR(1); +PROFILE_ATTR(2); +PROFILE_ATTR(3); +PROFILE_ATTR(4); +PROFILE_ATTR(5); + static ssize_t kovaplus_sysfs_show_actual_profile(struct device *dev, struct device_attribute *attr, char *buf) { @@ -372,74 +385,33 @@ static struct attribute *kovaplus_attrs[] = { &dev_attr_actual_sensitivity_y.attr, NULL, }; -ATTRIBUTE_GROUPS(kovaplus); - -static struct bin_attribute kovaplus_bin_attributes[] = { - KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL), - KOVAPLUS_BIN_ATTRIBUTE_RW(info, INFO), - KOVAPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS), - KOVAPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS), - { - .attr = { .name = "profile1_settings", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, - .read = kovaplus_sysfs_read_profilex_settings, - .private = &profile_numbers[0] - }, - { - .attr = { .name = "profile2_settings", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, - .read = kovaplus_sysfs_read_profilex_settings, - .private = &profile_numbers[1] - }, - { - .attr = { .name = "profile3_settings", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, - .read = kovaplus_sysfs_read_profilex_settings, - .private = &profile_numbers[2] - }, - { - .attr = { .name = "profile4_settings", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, - .read = kovaplus_sysfs_read_profilex_settings, - .private = &profile_numbers[3] - }, - { - .attr = { .name = "profile5_settings", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_SETTINGS, - .read = kovaplus_sysfs_read_profilex_settings, - .private = &profile_numbers[4] - }, - { - .attr = { .name = "profile1_buttons", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, - .read = kovaplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[0] - }, - { - .attr = { .name = "profile2_buttons", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, - .read = kovaplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[1] - }, - { - .attr = { .name = "profile3_buttons", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, - .read = kovaplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[2] - }, - { - .attr = { .name = "profile4_buttons", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, - .read = kovaplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[3] - }, - { - .attr = { .name = "profile5_buttons", .mode = 0440 }, - .size = KOVAPLUS_SIZE_PROFILE_BUTTONS, - .read = kovaplus_sysfs_read_profilex_buttons, - .private = &profile_numbers[4] - }, - __ATTR_NULL + +static struct bin_attribute *kovaplus_bin_attributes[] = { + &bin_attr_control, + &bin_attr_info, + &bin_attr_profile_settings, + &bin_attr_profile_buttons, + &bin_attr_profile1_settings, + &bin_attr_profile2_settings, + &bin_attr_profile3_settings, + &bin_attr_profile4_settings, + &bin_attr_profile5_settings, + &bin_attr_profile1_buttons, + &bin_attr_profile2_buttons, + &bin_attr_profile3_buttons, + &bin_attr_profile4_buttons, + &bin_attr_profile5_buttons, + NULL, +}; + +static const struct attribute_group kovaplus_group = { + .attrs = kovaplus_attrs, + .bin_attrs = kovaplus_bin_attributes, +}; + +static const struct attribute_group *kovaplus_groups[] = { + &kovaplus_group, + NULL, }; static int kovaplus_init_kovaplus_device_struct(struct usb_device *usb_dev, @@ -668,7 +640,6 @@ static int __init kovaplus_init(void) if (IS_ERR(kovaplus_class)) return PTR_ERR(kovaplus_class); kovaplus_class->dev_groups = kovaplus_groups; - kovaplus_class->dev_bin_attrs = kovaplus_bin_attributes; retval = hid_register_driver(&kovaplus_driver); if (retval) -- cgit v1.2.3-70-g09d2 From 515ad4d678128affa7788a685d79664463f3b1e3 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Aug 2013 21:56:46 -0700 Subject: hid: roccat-kone: fix off-by-one bug in attributes Stefan pointed out that I messed up the array for the binary attributes, so fix it properly. Reported-by: Stefan Achatz Cc: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-kone.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c index 5eddf834c05..6e614a85f17 100644 --- a/drivers/hid/hid-roccat-kone.c +++ b/drivers/hid/hid-roccat-kone.c @@ -386,7 +386,7 @@ static struct bin_attribute bin_attr_profile##number = { \ .size = sizeof(struct kone_profile), \ .read = kone_sysfs_read_profilex, \ .write = kone_sysfs_write_profilex, \ - .private = &profile_numbers[number], \ + .private = &profile_numbers[number-1], \ }; PROFILE_ATTR(1); PROFILE_ATTR(2); -- cgit v1.2.3-70-g09d2 From a749245168ccda07b4200a8d55e2042679b7ecd4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 24 Jul 2013 15:05:38 -0700 Subject: hid: roccat-pyra: convert class code to use bin_attrs in groups Now that attribute groups support binary attributes, use them instead of the dev_bin_attrs field in struct class, as that is going away soon. Cc: Jiri Kosina Cc: Stefan Achatz Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-roccat-pyra.c | 140 +++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 78 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c index 7960d507ad9..5a6dbbeee79 100644 --- a/drivers/hid/hid-roccat-pyra.c +++ b/drivers/hid/hid-roccat-pyra.c @@ -156,7 +156,8 @@ PYRA_SYSFS_W(thingy, THINGY) \ PYRA_SYSFS_R(thingy, THINGY) #define PYRA_BIN_ATTRIBUTE_RW(thingy, THINGY) \ -{ \ +PYRA_SYSFS_RW(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0660 }, \ .size = PYRA_SIZE_ ## THINGY, \ .read = pyra_sysfs_read_ ## thingy, \ @@ -164,24 +165,25 @@ PYRA_SYSFS_R(thingy, THINGY) } #define PYRA_BIN_ATTRIBUTE_R(thingy, THINGY) \ -{ \ +PYRA_SYSFS_R(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0440 }, \ .size = PYRA_SIZE_ ## THINGY, \ .read = pyra_sysfs_read_ ## thingy, \ } #define PYRA_BIN_ATTRIBUTE_W(thingy, THINGY) \ -{ \ +PYRA_SYSFS_W(thingy, THINGY); \ +static struct bin_attribute bin_attr_##thingy = { \ .attr = { .name = #thingy, .mode = 0220 }, \ .size = PYRA_SIZE_ ## THINGY, \ .write = pyra_sysfs_write_ ## thingy \ } -PYRA_SYSFS_W(control, CONTROL) -PYRA_SYSFS_RW(info, INFO) -PYRA_SYSFS_RW(profile_settings, PROFILE_SETTINGS) -PYRA_SYSFS_RW(profile_buttons, PROFILE_BUTTONS) -PYRA_SYSFS_R(settings, SETTINGS) +PYRA_BIN_ATTRIBUTE_W(control, CONTROL); +PYRA_BIN_ATTRIBUTE_RW(info, INFO); +PYRA_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS); +PYRA_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS); static ssize_t pyra_sysfs_read_profilex_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, @@ -221,6 +223,25 @@ static ssize_t pyra_sysfs_read_profilex_buttons(struct file *fp, PYRA_COMMAND_PROFILE_BUTTONS); } +#define PROFILE_ATTR(number) \ +static struct bin_attribute bin_attr_profile##number##_settings = { \ + .attr = { .name = "profile##number##_settings", .mode = 0440 }, \ + .size = PYRA_SIZE_PROFILE_SETTINGS, \ + .read = pyra_sysfs_read_profilex_settings, \ + .private = &profile_numbers[number-1], \ +}; \ +static struct bin_attribute bin_attr_profile##number##_buttons = { \ + .attr = { .name = "profile##number##_buttons", .mode = 0440 }, \ + .size = PYRA_SIZE_PROFILE_BUTTONS, \ + .read = pyra_sysfs_read_profilex_buttons, \ + .private = &profile_numbers[number-1], \ +}; +PROFILE_ATTR(1); +PROFILE_ATTR(2); +PROFILE_ATTR(3); +PROFILE_ATTR(4); +PROFILE_ATTR(5); + static ssize_t pyra_sysfs_write_settings(struct file *fp, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) @@ -258,6 +279,11 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp, return PYRA_SIZE_SETTINGS; } +PYRA_SYSFS_R(settings, SETTINGS); +static struct bin_attribute bin_attr_settings = + __BIN_ATTR(settings, (S_IWUSR | S_IRUGO), + pyra_sysfs_read_settings, pyra_sysfs_write_settings, + PYRA_SIZE_SETTINGS); static ssize_t pyra_sysfs_show_actual_cpi(struct device *dev, struct device_attribute *attr, char *buf) @@ -314,75 +340,34 @@ static struct attribute *pyra_attrs[] = { &dev_attr_startup_profile.attr, NULL, }; -ATTRIBUTE_GROUPS(pyra); - -static struct bin_attribute pyra_bin_attributes[] = { - PYRA_BIN_ATTRIBUTE_W(control, CONTROL), - PYRA_BIN_ATTRIBUTE_RW(info, INFO), - PYRA_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS), - PYRA_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS), - PYRA_BIN_ATTRIBUTE_RW(settings, SETTINGS), - { - .attr = { .name = "profile1_settings", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_SETTINGS, - .read = pyra_sysfs_read_profilex_settings, - .private = &profile_numbers[0] - }, - { - .attr = { .name = "profile2_settings", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_SETTINGS, - .read = pyra_sysfs_read_profilex_settings, - .private = &profile_numbers[1] - }, - { - .attr = { .name = "profile3_settings", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_SETTINGS, - .read = pyra_sysfs_read_profilex_settings, - .private = &profile_numbers[2] - }, - { - .attr = { .name = "profile4_settings", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_SETTINGS, - .read = pyra_sysfs_read_profilex_settings, - .private = &profile_numbers[3] - }, - { - .attr = { .name = "profile5_settings", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_SETTINGS, - .read = pyra_sysfs_read_profilex_settings, - .private = &profile_numbers[4] - }, - { - .attr = { .name = "profile1_buttons", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_BUTTONS, - .read = pyra_sysfs_read_profilex_buttons, - .private = &profile_numbers[0] - }, - { - .attr = { .name = "profile2_buttons", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_BUTTONS, - .read = pyra_sysfs_read_profilex_buttons, - .private = &profile_numbers[1] - }, - { - .attr = { .name = "profile3_buttons", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_BUTTONS, - .read = pyra_sysfs_read_profilex_buttons, - .private = &profile_numbers[2] - }, - { - .attr = { .name = "profile4_buttons", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_BUTTONS, - .read = pyra_sysfs_read_profilex_buttons, - .private = &profile_numbers[3] - }, - { - .attr = { .name = "profile5_buttons", .mode = 0440 }, - .size = PYRA_SIZE_PROFILE_BUTTONS, - .read = pyra_sysfs_read_profilex_buttons, - .private = &profile_numbers[4] - }, - __ATTR_NULL + +static struct bin_attribute *pyra_bin_attributes[] = { + &bin_attr_control, + &bin_attr_info, + &bin_attr_profile_settings, + &bin_attr_profile_buttons, + &bin_attr_settings, + &bin_attr_profile1_settings, + &bin_attr_profile2_settings, + &bin_attr_profile3_settings, + &bin_attr_profile4_settings, + &bin_attr_profile5_settings, + &bin_attr_profile1_buttons, + &bin_attr_profile2_buttons, + &bin_attr_profile3_buttons, + &bin_attr_profile4_buttons, + &bin_attr_profile5_buttons, + NULL, +}; + +static const struct attribute_group pyra_group = { + .attrs = pyra_attrs, + .bin_attrs = pyra_bin_attributes, +}; + +static const struct attribute_group *pyra_groups[] = { + &pyra_group, + NULL, }; static int pyra_init_pyra_device_struct(struct usb_device *usb_dev, @@ -605,7 +590,6 @@ static int __init pyra_init(void) if (IS_ERR(pyra_class)) return PTR_ERR(pyra_class); pyra_class->dev_groups = pyra_groups; - pyra_class->dev_bin_attrs = pyra_bin_attributes; retval = hid_register_driver(&pyra_driver); if (retval) -- cgit v1.2.3-70-g09d2 From 65f44679580de05d267f026ed8164539ec5c7a88 Mon Sep 17 00:00:00 2001 From: Greg KH Date: Tue, 20 Aug 2013 17:11:49 -0700 Subject: ACPI: bgrt: take advantage of binary sysfs groups Attribute groups now can handle binary sysfs attributes, so clean up the code here by using a binary attribute array. This saves us the extra call to create the binary attribute at saves 6 lines overall. Cc: Len Brown Acked-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman -- I can take this in my driver-core tree if someone from ACPI acks it, otherwise, feel free to take it through the ACPI trees instead, just let me know. drivers/acpi/bgrt.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) --- drivers/acpi/bgrt.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'drivers') diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c index be603995854..7a4128d9611 100644 --- a/drivers/acpi/bgrt.c +++ b/drivers/acpi/bgrt.c @@ -51,20 +51,14 @@ static ssize_t show_yoffset(struct device *dev, } static DEVICE_ATTR(yoffset, S_IRUGO, show_yoffset, NULL); -static ssize_t show_image(struct file *file, struct kobject *kobj, +static ssize_t image_read(struct file *file, struct kobject *kobj, struct bin_attribute *attr, char *buf, loff_t off, size_t count) { memcpy(buf, attr->private + off, count); return count; } -static struct bin_attribute image_attr = { - .attr = { - .name = "image", - .mode = S_IRUGO, - }, - .read = show_image, -}; +static BIN_ATTR_RO(image, 0); /* size gets filled in later */ static struct attribute *bgrt_attributes[] = { &dev_attr_version.attr, @@ -75,8 +69,14 @@ static struct attribute *bgrt_attributes[] = { NULL, }; +static struct bin_attribute *bgrt_bin_attributes[] = { + &bin_attr_image, + NULL, +}; + static struct attribute_group bgrt_attribute_group = { .attrs = bgrt_attributes, + .bin_attrs = bgrt_bin_attributes, }; static int __init bgrt_init(void) @@ -87,8 +87,8 @@ static int __init bgrt_init(void) return -ENODEV; sysfs_bin_attr_init(&image_attr); - image_attr.private = bgrt_image; - image_attr.size = bgrt_image_size; + bin_attr_image.private = bgrt_image; + bin_attr_image.size = bgrt_image_size; bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj); if (!bgrt_kobj) @@ -98,14 +98,8 @@ static int __init bgrt_init(void) if (ret) goto out_kobject; - ret = sysfs_create_bin_file(bgrt_kobj, &image_attr); - if (ret) - goto out_group; - return 0; -out_group: - sysfs_remove_group(bgrt_kobj, &bgrt_attribute_group); out_kobject: kobject_put(bgrt_kobj); return ret; -- cgit v1.2.3-70-g09d2 From b1eaef3da5a7bbc48fa9dbefaa2a28e45367fdb1 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:12:57 -0500 Subject: drivers: base: move mutex lock out of add_memory_section() There is no point in releasing the mutex for each section that is added during boot time. Just hold it over the entire initialization loop. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index ddd14ce6654..ed3ada244a0 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -613,8 +613,6 @@ static int add_memory_section(int nid, struct mem_section *section, int scn_nr = __section_nr(section); int ret = 0; - mutex_lock(&mem_sysfs_mutex); - if (context == BOOT) { /* same memory block ? */ if (mem_p && *mem_p) @@ -643,7 +641,6 @@ static int add_memory_section(int nid, struct mem_section *section, ret = register_mem_sect_under_node(mem, nid); } - mutex_unlock(&mem_sysfs_mutex); return ret; } @@ -653,7 +650,13 @@ static int add_memory_section(int nid, struct mem_section *section, */ int register_new_memory(int nid, struct mem_section *section) { - return add_memory_section(nid, section, NULL, MEM_OFFLINE, HOTPLUG); + int ret; + + mutex_lock(&mem_sysfs_mutex); + ret = add_memory_section(nid, section, NULL, MEM_OFFLINE, HOTPLUG); + mutex_unlock(&mem_sysfs_mutex); + + return ret; } #ifdef CONFIG_MEMORY_HOTREMOVE @@ -746,6 +749,7 @@ int __init memory_dev_init(void) * Create entries for memory sections that were found * during boot and have been initialized */ + mutex_lock(&mem_sysfs_mutex); for (i = 0; i < NR_MEM_SECTIONS; i++) { if (!present_section_nr(i)) continue; @@ -757,6 +761,7 @@ int __init memory_dev_init(void) if (!ret) ret = err; } + mutex_unlock(&mem_sysfs_mutex); out: if (ret) -- cgit v1.2.3-70-g09d2 From 879f1bec8e136c7bc71e38715e62a73b75f91d78 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:12:58 -0500 Subject: drivers: base: remove unneeded variable The error variable is not needed. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index ed3ada244a0..b31d998a63a 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -565,16 +565,13 @@ static const struct attribute_group *memory_memblk_attr_groups[] = { static int register_memory(struct memory_block *memory) { - int error; - memory->dev.bus = &memory_subsys; memory->dev.id = memory->start_section_nr / sections_per_block; memory->dev.release = memory_block_release; memory->dev.groups = memory_memblk_attr_groups; memory->dev.offline = memory->state == MEM_OFFLINE; - error = device_register(&memory->dev); - return error; + return device_register(&memory->dev); } static int init_memory_block(struct memory_block **memory, -- cgit v1.2.3-70-g09d2 From df2b717c667d2cab37d1bbd585e891f10ed2bca4 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:12:59 -0500 Subject: drivers: base: use device get/put functions Use the [get|put]_device functions for ref'ing the memory block device rather than the kobject functions which should be hidden away by the device layer. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index b31d998a63a..e97519bc3d0 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -616,14 +616,14 @@ static int add_memory_section(int nid, struct mem_section *section, if (scn_nr >= (*mem_p)->start_section_nr && scn_nr <= (*mem_p)->end_section_nr) { mem = *mem_p; - kobject_get(&mem->dev.kobj); + get_device(&mem->dev); } } else mem = find_memory_block(section); if (mem) { mem->section_count++; - kobject_put(&mem->dev.kobj); + put_device(&mem->dev); } else { ret = init_memory_block(&mem, section, state); /* store memory_block pointer for next loop */ @@ -663,7 +663,7 @@ unregister_memory(struct memory_block *memory) BUG_ON(memory->dev.bus != &memory_subsys); /* drop the ref. we got in remove_memory_block() */ - kobject_put(&memory->dev.kobj); + put_device(&memory->dev); device_unregister(&memory->dev); } @@ -680,7 +680,7 @@ static int remove_memory_block(unsigned long node_id, if (mem->section_count == 0) unregister_memory(mem); else - kobject_put(&mem->dev.kobj); + put_device(&mem->dev); mutex_unlock(&mem_sysfs_mutex); return 0; -- cgit v1.2.3-70-g09d2 From d7f80530ad0a71615f54607128c30d2422bf4c02 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:13:00 -0500 Subject: drivers: base: unshare add_memory_section() from hotplug add_memory_section() is currently called from both boot time and run time via hotplug and there is a lot of nastiness to allow for shared code including an enum parameter to convey the calling context to add_memory_section(). This patch is the first step in breaking up the messy code sharing by pulling the hotplug path for add_memory_section() directly into register_new_memory(). Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index e97519bc3d0..2e9a68c6467 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -647,12 +647,25 @@ static int add_memory_section(int nid, struct mem_section *section, */ int register_new_memory(int nid, struct mem_section *section) { - int ret; + int ret = 0; + struct memory_block *mem; mutex_lock(&mem_sysfs_mutex); - ret = add_memory_section(nid, section, NULL, MEM_OFFLINE, HOTPLUG); - mutex_unlock(&mem_sysfs_mutex); + mem = find_memory_block(section); + if (mem) { + mem->section_count++; + put_device(&mem->dev); + } else { + ret = init_memory_block(&mem, section, MEM_OFFLINE); + if (ret) + goto out; + } + + if (mem->section_count == sections_per_block) + ret = register_mem_sect_under_node(mem, nid); +out: + mutex_unlock(&mem_sysfs_mutex); return ret; } -- cgit v1.2.3-70-g09d2 From 37a7bd6255b415afe197489b5cd1f9568a7ae058 Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:13:01 -0500 Subject: drivers: base: reduce add_memory_section() for boot-time only Now that add_memory_section() is only called from boot time, reduce the logic and remove the enum. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 41 ++++++++++++++--------------------------- include/linux/memory.h | 1 - 2 files changed, 14 insertions(+), 28 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 2e9a68c6467..a9e9c0902cc 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -602,40 +602,29 @@ static int init_memory_block(struct memory_block **memory, return ret; } -static int add_memory_section(int nid, struct mem_section *section, - struct memory_block **mem_p, - unsigned long state, enum mem_add_context context) +static int add_memory_section(struct mem_section *section, + struct memory_block **mem_p) { struct memory_block *mem = NULL; int scn_nr = __section_nr(section); int ret = 0; - if (context == BOOT) { - /* same memory block ? */ - if (mem_p && *mem_p) - if (scn_nr >= (*mem_p)->start_section_nr && - scn_nr <= (*mem_p)->end_section_nr) { - mem = *mem_p; - get_device(&mem->dev); - } - } else - mem = find_memory_block(section); + if (mem_p && *mem_p) { + if (scn_nr >= (*mem_p)->start_section_nr && + scn_nr <= (*mem_p)->end_section_nr) { + mem = *mem_p; + get_device(&mem->dev); + } + } if (mem) { mem->section_count++; put_device(&mem->dev); } else { - ret = init_memory_block(&mem, section, state); + ret = init_memory_block(&mem, section, MEM_ONLINE); /* store memory_block pointer for next loop */ - if (!ret && context == BOOT) - if (mem_p) - *mem_p = mem; - } - - if (!ret) { - if (context == HOTPLUG && - mem->section_count == sections_per_block) - ret = register_mem_sect_under_node(mem, nid); + if (!ret && mem_p) + *mem_p = mem; } return ret; @@ -764,10 +753,8 @@ int __init memory_dev_init(void) if (!present_section_nr(i)) continue; /* don't need to reuse memory_block if only one per block */ - err = add_memory_section(0, __nr_to_section(i), - (sections_per_block == 1) ? NULL : &mem, - MEM_ONLINE, - BOOT); + err = add_memory_section(__nr_to_section(i), + (sections_per_block == 1) ? NULL : &mem); if (!ret) ret = err; } diff --git a/include/linux/memory.h b/include/linux/memory.h index 85c31a8e290..4c89fb0c8f4 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -125,7 +125,6 @@ extern struct memory_block *find_memory_block_hinted(struct mem_section *, struct memory_block *); extern struct memory_block *find_memory_block(struct mem_section *); #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION< Date: Tue, 20 Aug 2013 12:13:02 -0500 Subject: drivers: base: remove improper get/put in add_memory_section() The path through add_memory_section() when the memory block already exists uses flawed refcounting logic. A get_device() is done on a memory block using a pointer that might not be valid as we dropped our previous reference and didn't obtain a new reference in the proper way. Lets stop pretending and just remove the get/put. The mem_sysfs_mutex, which we hold over the entire init loop now, will prevent the memory blocks from disappearing from under us. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index a9e9c0902cc..9438d541b5c 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -613,14 +613,12 @@ static int add_memory_section(struct mem_section *section, if (scn_nr >= (*mem_p)->start_section_nr && scn_nr <= (*mem_p)->end_section_nr) { mem = *mem_p; - get_device(&mem->dev); } } - if (mem) { + if (mem) mem->section_count++; - put_device(&mem->dev); - } else { + else { ret = init_memory_block(&mem, section, MEM_ONLINE); /* store memory_block pointer for next loop */ if (!ret && mem_p) -- cgit v1.2.3-70-g09d2 From cb5e39b8038be913030a7b01d4396cfa5f9ded7b Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 12:13:03 -0500 Subject: drivers: base: refactor add_memory_section() to add_memory_block() Right now memory_dev_init() maintains the memory block pointer between iterations of add_memory_section(). This is nasty. This patch refactors add_memory_section() to become add_memory_block(). The refactoring pulls the section scanning out of memory_dev_init() and simplifies the signature. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 9438d541b5c..0187fe483d7 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -602,32 +602,31 @@ static int init_memory_block(struct memory_block **memory, return ret; } -static int add_memory_section(struct mem_section *section, - struct memory_block **mem_p) +static int add_memory_block(int base_section_nr) { - struct memory_block *mem = NULL; - int scn_nr = __section_nr(section); - int ret = 0; - - if (mem_p && *mem_p) { - if (scn_nr >= (*mem_p)->start_section_nr && - scn_nr <= (*mem_p)->end_section_nr) { - mem = *mem_p; - } - } + struct memory_block *mem; + int i, ret, section_count = 0, section_nr; - if (mem) - mem->section_count++; - else { - ret = init_memory_block(&mem, section, MEM_ONLINE); - /* store memory_block pointer for next loop */ - if (!ret && mem_p) - *mem_p = mem; + for (i = base_section_nr; + (i < base_section_nr + sections_per_block) && i < NR_MEM_SECTIONS; + i++) { + if (!present_section_nr(i)) + continue; + if (section_count == 0) + section_nr = i; + section_count++; } - return ret; + if (section_count == 0) + return 0; + ret = init_memory_block(&mem, __nr_to_section(section_nr), MEM_ONLINE); + if (ret) + return ret; + mem->section_count = section_count; + return 0; } + /* * need an interface for the VM to add new memory regions, * but without onlining it. @@ -733,7 +732,6 @@ int __init memory_dev_init(void) int ret; int err; unsigned long block_sz; - struct memory_block *mem = NULL; ret = subsys_system_register(&memory_subsys, memory_root_attr_groups); if (ret) @@ -747,12 +745,8 @@ int __init memory_dev_init(void) * during boot and have been initialized */ mutex_lock(&mem_sysfs_mutex); - for (i = 0; i < NR_MEM_SECTIONS; i++) { - if (!present_section_nr(i)) - continue; - /* don't need to reuse memory_block if only one per block */ - err = add_memory_section(__nr_to_section(i), - (sections_per_block == 1) ? NULL : &mem); + for (i = 0; i < NR_MEM_SECTIONS; i += sections_per_block) { + err = add_memory_block(i); if (!ret) ret = err; } -- cgit v1.2.3-70-g09d2 From fa2be40fe7c0aa3b7accbf6dfa9ef0976e191d4c Mon Sep 17 00:00:00 2001 From: Seth Jennings Date: Tue, 20 Aug 2013 16:05:05 -0500 Subject: drivers: base: use standard device online/offline for state change There are two ways to set the online/offline state for a memory block: echo 0|1 > online and echo online|online_kernel|online_movable|offline > state. The state attribute can online a memory block with extra data, the "online type", where the online attribute uses a default online type of ONLINE_KEEP, same as echo online > state. Currently there is a state_mutex that provides consistency between the memory block state and the underlying memory. The problem is that this code does a lot of things that the common device layer can do for us, such as the serialization of the online/offline handlers using the device lock, setting the dev->offline field, and calling kobject_uevent(). This patch refactors the online/offline code to allow the common device_[online|offline] functions to be used. The result is a simpler and more common code path for the two state setting mechanisms. It also removes the state_mutex from the struct memory_block as the memory block device lock provides the state consistency. No functional change is intended by this patch. Signed-off-by: Seth Jennings Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 127 +++++++++++++++++++++---------------------------- include/linux/memory.h | 13 ++--- 2 files changed, 58 insertions(+), 82 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 0187fe483d7..2a38cd2da2e 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -261,9 +260,8 @@ memory_block_action(unsigned long phys_index, unsigned long action, int online_t return ret; } -static int __memory_block_change_state(struct memory_block *mem, - unsigned long to_state, unsigned long from_state_req, - int online_type) +static int memory_block_change_state(struct memory_block *mem, + unsigned long to_state, unsigned long from_state_req) { int ret = 0; @@ -273,105 +271,91 @@ static int __memory_block_change_state(struct memory_block *mem, if (to_state == MEM_OFFLINE) mem->state = MEM_GOING_OFFLINE; - ret = memory_block_action(mem->start_section_nr, to_state, online_type); + ret = memory_block_action(mem->start_section_nr, to_state, + mem->online_type); + mem->state = ret ? from_state_req : to_state; + return ret; } +/* The device lock serializes operations on memory_subsys_[online|offline] */ static int memory_subsys_online(struct device *dev) { struct memory_block *mem = container_of(dev, struct memory_block, dev); int ret; - mutex_lock(&mem->state_mutex); + if (mem->state == MEM_ONLINE) + return 0; - ret = mem->state == MEM_ONLINE ? 0 : - __memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE, - ONLINE_KEEP); + /* + * If we are called from store_mem_state(), online_type will be + * set >= 0 Otherwise we were called from the device online + * attribute and need to set the online_type. + */ + if (mem->online_type < 0) + mem->online_type = ONLINE_KEEP; + + ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); + + /* clear online_type */ + mem->online_type = -1; - mutex_unlock(&mem->state_mutex); return ret; } static int memory_subsys_offline(struct device *dev) { struct memory_block *mem = container_of(dev, struct memory_block, dev); - int ret; - mutex_lock(&mem->state_mutex); - - ret = mem->state == MEM_OFFLINE ? 0 : - __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE, -1); - - mutex_unlock(&mem->state_mutex); - return ret; -} + if (mem->state == MEM_OFFLINE) + return 0; -static int __memory_block_change_state_uevent(struct memory_block *mem, - unsigned long to_state, unsigned long from_state_req, - int online_type) -{ - int ret = __memory_block_change_state(mem, to_state, from_state_req, - online_type); - if (!ret) { - switch (mem->state) { - case MEM_OFFLINE: - kobject_uevent(&mem->dev.kobj, KOBJ_OFFLINE); - break; - case MEM_ONLINE: - kobject_uevent(&mem->dev.kobj, KOBJ_ONLINE); - break; - default: - break; - } - } - return ret; + return memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); } -static int memory_block_change_state(struct memory_block *mem, - unsigned long to_state, unsigned long from_state_req, - int online_type) -{ - int ret; - - mutex_lock(&mem->state_mutex); - ret = __memory_block_change_state_uevent(mem, to_state, from_state_req, - online_type); - mutex_unlock(&mem->state_mutex); - - return ret; -} static ssize_t store_mem_state(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct memory_block *mem; - bool offline; - int ret = -EINVAL; + int ret, online_type; mem = container_of(dev, struct memory_block, dev); lock_device_hotplug(); - if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) { - offline = false; - ret = memory_block_change_state(mem, MEM_ONLINE, - MEM_OFFLINE, ONLINE_KERNEL); - } else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) { - offline = false; - ret = memory_block_change_state(mem, MEM_ONLINE, - MEM_OFFLINE, ONLINE_MOVABLE); - } else if (!strncmp(buf, "online", min_t(int, count, 6))) { - offline = false; - ret = memory_block_change_state(mem, MEM_ONLINE, - MEM_OFFLINE, ONLINE_KEEP); - } else if(!strncmp(buf, "offline", min_t(int, count, 7))) { - offline = true; - ret = memory_block_change_state(mem, MEM_OFFLINE, - MEM_ONLINE, -1); + if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) + online_type = ONLINE_KERNEL; + else if (!strncmp(buf, "online_movable", min_t(int, count, 14))) + online_type = ONLINE_MOVABLE; + else if (!strncmp(buf, "online", min_t(int, count, 6))) + online_type = ONLINE_KEEP; + else if (!strncmp(buf, "offline", min_t(int, count, 7))) + online_type = -1; + else + return -EINVAL; + + switch (online_type) { + case ONLINE_KERNEL: + case ONLINE_MOVABLE: + case ONLINE_KEEP: + /* + * mem->online_type is not protected so there can be a + * race here. However, when racing online, the first + * will succeed and the second will just return as the + * block will already be online. The online type + * could be either one, but that is expected. + */ + mem->online_type = online_type; + ret = device_online(&mem->dev); + break; + case -1: + ret = device_offline(&mem->dev); + break; + default: + ret = -EINVAL; /* should never happen */ } - if (!ret) - dev->offline = offline; unlock_device_hotplug(); @@ -592,7 +576,6 @@ static int init_memory_block(struct memory_block **memory, mem->end_section_nr = mem->start_section_nr + sections_per_block - 1; mem->state = state; mem->section_count++; - mutex_init(&mem->state_mutex); start_pfn = section_nr_to_pfn(mem->start_section_nr); mem->phys_device = arch_get_memory_phys_device(start_pfn); diff --git a/include/linux/memory.h b/include/linux/memory.h index 4c89fb0c8f4..9a6bbf76452 100644 --- a/include/linux/memory.h +++ b/include/linux/memory.h @@ -25,16 +25,9 @@ struct memory_block { unsigned long start_section_nr; unsigned long end_section_nr; - unsigned long state; - int section_count; - - /* - * This serializes all state change requests. It isn't - * held during creation because the control files are - * created long after the critical areas during - * initialization. - */ - struct mutex state_mutex; + unsigned long state; /* serialized by the dev->lock */ + int section_count; /* serialized by mem_sysfs_mutex */ + int online_type; /* for passing data to online routine */ int phys_device; /* to which fru does this belong? */ void *hw; /* optional pointer to fw/hw data */ int (*phys_callback)(struct memory_block *); -- cgit v1.2.3-70-g09d2 From 3e9b2bae8369661070622d05570cbcdfa01770e6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 13:47:50 -0700 Subject: sysfs: add sysfs_create/remove_groups() These functions are being open-coded in 3 different places in the driver core, and other driver subsystems will want to start doing this as well, so move it to the sysfs core to keep it all in one place, where we know it is written properly. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 23 ++-------------------- drivers/base/core.c | 22 ++------------------- drivers/base/driver.c | 22 ++------------------- fs/sysfs/group.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/sysfs.h | 4 ++++ 5 files changed, 64 insertions(+), 61 deletions(-) (limited to 'drivers') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 5ee5d3c1d74..f099af0b41a 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -884,32 +884,13 @@ static void bus_remove_attrs(struct bus_type *bus) static int bus_add_groups(struct bus_type *bus, const struct attribute_group **groups) { - int error = 0; - int i; - - if (groups) { - for (i = 0; groups[i]; i++) { - error = sysfs_create_group(&bus->p->subsys.kobj, - groups[i]); - if (error) { - while (--i >= 0) - sysfs_remove_group(&bus->p->subsys.kobj, - groups[i]); - break; - } - } - } - return error; + return sysfs_create_groups(&bus->p->subsys.kobj, groups); } static void bus_remove_groups(struct bus_type *bus, const struct attribute_group **groups) { - int i; - - if (groups) - for (i = 0; groups[i]; i++) - sysfs_remove_group(&bus->p->subsys.kobj, groups[i]); + sysfs_remove_groups(&bus->p->subsys.kobj, groups); } static void klist_devices_get(struct klist_node *n) diff --git a/drivers/base/core.c b/drivers/base/core.c index af646afa5b7..d743dcee1e7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -493,31 +493,13 @@ static void device_remove_bin_attributes(struct device *dev, int device_add_groups(struct device *dev, const struct attribute_group **groups) { - int error = 0; - int i; - - if (groups) { - for (i = 0; groups[i]; i++) { - error = sysfs_create_group(&dev->kobj, groups[i]); - if (error) { - while (--i >= 0) - sysfs_remove_group(&dev->kobj, - groups[i]); - break; - } - } - } - return error; + return sysfs_create_groups(&dev->kobj, groups); } void device_remove_groups(struct device *dev, const struct attribute_group **groups) { - int i; - - if (groups) - for (i = 0; groups[i]; i++) - sysfs_remove_group(&dev->kobj, groups[i]); + sysfs_remove_groups(&dev->kobj, groups); } static int device_add_attrs(struct device *dev) diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 89db726ebb9..c7efccb6f3b 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -126,31 +126,13 @@ EXPORT_SYMBOL_GPL(driver_remove_file); int driver_add_groups(struct device_driver *drv, const struct attribute_group **groups) { - int error = 0; - int i; - - if (groups) { - for (i = 0; groups[i]; i++) { - error = sysfs_create_group(&drv->p->kobj, groups[i]); - if (error) { - while (--i >= 0) - sysfs_remove_group(&drv->p->kobj, - groups[i]); - break; - } - } - } - return error; + return sysfs_create_groups(&drv->p->kobj, groups); } void driver_remove_groups(struct device_driver *drv, const struct attribute_group **groups) { - int i; - - if (groups) - for (i = 0; groups[i]; i++) - sysfs_remove_group(&drv->p->kobj, groups[i]); + sysfs_remove_groups(&drv->p->kobj, groups); } /** diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 09a1a25cd14..68baf850155 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -130,6 +130,40 @@ int sysfs_create_group(struct kobject *kobj, return internal_create_group(kobj, 0, grp); } +/** + * sysfs_create_groups - given a directory kobject, create a bunch of attribute groups + * @kobj: The kobject to create the group on + * @groups: The attribute groups to create, NULL terminated + * + * This function creates a bunch of attribute groups. If an error occurs when + * creating a group, all previously created groups will be removed, unwinding + * everything back to the original state when this function was called. + * It will explicitly warn and error if any of the attribute files being + * created already exist. + * + * Returns 0 on success or error code from sysfs_create_groups on error. + */ +int sysfs_create_groups(struct kobject *kobj, + const struct attribute_group **groups) +{ + int error = 0; + int i; + + if (!groups) + return 0; + + for (i = 0; groups[i]; i++) { + error = sysfs_create_group(kobj, groups[i]); + if (error) { + while (--i >= 0) + sysfs_remove_group(kobj, groups[i]); + break; + } + } + return error; +} +EXPORT_SYMBOL_GPL(sysfs_create_groups); + /** * sysfs_update_group - given a directory kobject, update an attribute group * @kobj: The kobject to update the group on @@ -178,6 +212,26 @@ void sysfs_remove_group(struct kobject * kobj, sysfs_put(sd); } +/** + * sysfs_remove_groups - remove a list of groups + * + * kobj: The kobject for the groups to be removed from + * groups: NULL terminated list of groups to be removed + * + * If groups is not NULL, the all groups will be removed from the kobject + */ +void sysfs_remove_groups(struct kobject *kobj, + const struct attribute_group **groups) +{ + int i; + + if (!groups) + return; + for (i = 0; groups[i]; i++) + sysfs_remove_group(kobj, groups[i]); +} +EXPORT_SYMBOL_GPL(sysfs_remove_groups); + /** * sysfs_merge_group - merge files into a pre-existing attribute group. * @kobj: The kobject containing the group. diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 0f04958623d..4dbb9d31daa 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -215,10 +215,14 @@ void sysfs_delete_link(struct kobject *dir, struct kobject *targ, int __must_check sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp); +int __must_check sysfs_create_groups(struct kobject *kobj, + const struct attribute_group **groups); int sysfs_update_group(struct kobject *kobj, const struct attribute_group *grp); void sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp); +void sysfs_remove_groups(struct kobject *kobj, + const struct attribute_group **groups); int sysfs_add_file_to_group(struct kobject *kobj, const struct attribute *attr, const char *group); void sysfs_remove_file_from_group(struct kobject *kobj, -- cgit v1.2.3-70-g09d2 From 028718a5cc6e35ae7e220839fa6b61e2a6f12ca3 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 22 Aug 2013 08:34:39 -0700 Subject: acpi: bgrt: fix build error due to attribute change No need to call sysfs_bin_attr_init, as the attribute is not dynamically created. Also, we renamed the attribute, so this one isn't even valid anymore. Reported-by: Stephen Rothwell Cc: Len Brown Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/bgrt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers') diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c index 7a4128d9611..a83e3c62c5a 100644 --- a/drivers/acpi/bgrt.c +++ b/drivers/acpi/bgrt.c @@ -86,7 +86,6 @@ static int __init bgrt_init(void) if (!bgrt_image) return -ENODEV; - sysfs_bin_attr_init(&image_attr); bin_attr_image.private = bgrt_image; bin_attr_image.size = bgrt_image_size; -- cgit v1.2.3-70-g09d2 From 3e1026b3fa2f61d33ce6a9e42a22398cc4ab8e58 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 22 Aug 2013 10:25:34 -0700 Subject: sysfs.h: remove attr_name() macro Gotta love a macro that doesn't reduce the typing you have to do. Also, only the driver core, and one network driver uses this. The driver core functions will be going away soon, and I'll convert the network driver soon to not need this as well, so delete it for now before anyone else gets some bright ideas and wants to use it. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 12 ++++++------ drivers/base/class.c | 4 ++-- drivers/base/core.c | 8 ++++---- drivers/net/ethernet/sun/niu.c | 2 +- include/linux/sysfs.h | 2 -- 5 files changed, 13 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index f099af0b41a..235e2b06ac0 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -460,7 +460,7 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev) if (!bus->dev_attrs) return 0; - for (i = 0; attr_name(bus->dev_attrs[i]); i++) { + for (i = 0; bus->dev_attrs[i].attr.name; i++) { error = device_create_file(dev, &bus->dev_attrs[i]); if (error) { while (--i >= 0) @@ -476,7 +476,7 @@ static void device_remove_attrs(struct bus_type *bus, struct device *dev) int i; if (bus->dev_attrs) { - for (i = 0; attr_name(bus->dev_attrs[i]); i++) + for (i = 0; bus->dev_attrs[i].attr.name; i++) device_remove_file(dev, &bus->dev_attrs[i]); } } @@ -596,7 +596,7 @@ static int driver_add_attrs(struct bus_type *bus, struct device_driver *drv) int i; if (bus->drv_attrs) { - for (i = 0; attr_name(bus->drv_attrs[i]); i++) { + for (i = 0; bus->drv_attrs[i].attr.name; i++) { error = driver_create_file(drv, &bus->drv_attrs[i]); if (error) goto err; @@ -616,7 +616,7 @@ static void driver_remove_attrs(struct bus_type *bus, int i; if (bus->drv_attrs) { - for (i = 0; attr_name(bus->drv_attrs[i]); i++) + for (i = 0; bus->drv_attrs[i].attr.name; i++) driver_remove_file(drv, &bus->drv_attrs[i]); } } @@ -857,7 +857,7 @@ static int bus_add_attrs(struct bus_type *bus) int i; if (bus->bus_attrs) { - for (i = 0; attr_name(bus->bus_attrs[i]); i++) { + for (i = 0; bus->bus_attrs[i].attr.name; i++) { error = bus_create_file(bus, &bus->bus_attrs[i]); if (error) goto err; @@ -876,7 +876,7 @@ static void bus_remove_attrs(struct bus_type *bus) int i; if (bus->bus_attrs) { - for (i = 0; attr_name(bus->bus_attrs[i]); i++) + for (i = 0; bus->bus_attrs[i].attr.name; i++) bus_remove_file(bus, &bus->bus_attrs[i]); } } diff --git a/drivers/base/class.c b/drivers/base/class.c index 3ce84547132..8b7818b8005 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c @@ -135,7 +135,7 @@ static int add_class_attrs(struct class *cls) int error = 0; if (cls->class_attrs) { - for (i = 0; attr_name(cls->class_attrs[i]); i++) { + for (i = 0; cls->class_attrs[i].attr.name; i++) { error = class_create_file(cls, &cls->class_attrs[i]); if (error) goto error; @@ -154,7 +154,7 @@ static void remove_class_attrs(struct class *cls) int i; if (cls->class_attrs) { - for (i = 0; attr_name(cls->class_attrs[i]); i++) + for (i = 0; cls->class_attrs[i].attr.name; i++) class_remove_file(cls, &cls->class_attrs[i]); } } diff --git a/drivers/base/core.c b/drivers/base/core.c index d743dcee1e7..ae1acdf21bd 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -440,7 +440,7 @@ static int device_add_attributes(struct device *dev, int i; if (attrs) { - for (i = 0; attr_name(attrs[i]); i++) { + for (i = 0; attrs[i].attr.name; i++) { error = device_create_file(dev, &attrs[i]); if (error) break; @@ -458,7 +458,7 @@ static void device_remove_attributes(struct device *dev, int i; if (attrs) - for (i = 0; attr_name(attrs[i]); i++) + for (i = 0; attrs[i].attr.name; i++) device_remove_file(dev, &attrs[i]); } @@ -469,7 +469,7 @@ static int device_add_bin_attributes(struct device *dev, int i; if (attrs) { - for (i = 0; attr_name(attrs[i]); i++) { + for (i = 0; attrs[i].attr.name; i++) { error = device_create_bin_file(dev, &attrs[i]); if (error) break; @@ -487,7 +487,7 @@ static void device_remove_bin_attributes(struct device *dev, int i; if (attrs) - for (i = 0; attr_name(attrs[i]); i++) + for (i = 0; attrs[i].attr.name; i++) device_remove_bin_file(dev, &attrs[i]); } diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c index fa322409bff..52b2adf63cb 100644 --- a/drivers/net/ethernet/sun/niu.c +++ b/drivers/net/ethernet/sun/niu.c @@ -9478,7 +9478,7 @@ static struct niu_parent *niu_new_parent(struct niu *np, if (IS_ERR(plat_dev)) return NULL; - for (i = 0; attr_name(niu_parent_attributes[i]); i++) { + for (i = 0; niu_parent_attributes[i].attr.name; i++) { int err = device_create_file(&plat_dev->dev, &niu_parent_attributes[i]); if (err) diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index a864b8d918e..b5a9d9b26bd 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -108,8 +108,6 @@ static const struct attribute_group _name##_group = { \ }; \ __ATTRIBUTE_GROUPS(_name) -#define attr_name(_attr) (_attr).attr.name - struct file; struct vm_area_struct; -- cgit v1.2.3-70-g09d2 From 47eba33a0997fc7362ae41cf28cea687e28bd731 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 13:24:32 -0700 Subject: w1: remove race with sysfs file creation W1 slave sysfs files are created _after_ userspace is notified that the device has been added to the system. Fix that race by moving the creation/remove of the files to the bus notifier that is there for doing this type of thing. Acked-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1.c | 111 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 38 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 0459df843c5..3c798db0152 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -587,6 +587,73 @@ end: return err; } +/* + * Handle sysfs file creation and removal here, before userspace is told that + * the device is added / removed from the system + */ +static int w1_bus_notify(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct device *dev = data; + struct w1_slave *sl; + int err; + + /* + * Only care about slave devices at the moment. Yes, we should use a + * separate "type" for this, but for now, look at the release function + * to know which type it is... + */ + if (dev->release != w1_slave_release) + return 0; + + sl = dev_to_w1_slave(dev); + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + /* Create our sysfs files before userspace is told about it */ + /* Create "name" entry */ + err = device_create_file(&sl->dev, &w1_slave_attr_name); + if (err < 0) { + dev_err(&sl->dev, + "sysfs file creation for [%s] failed. err=%d\n", + dev_name(&sl->dev), err); + return err; + } + + /* Create "id" entry */ + err = device_create_file(&sl->dev, &w1_slave_attr_id); + if (err < 0) { + dev_err(&sl->dev, + "sysfs file creation for [%s] failed. err=%d\n", + dev_name(&sl->dev), err); + return err; + } + + /* if the family driver needs to initialize something... */ + if (sl->family->fops && sl->family->fops->add_slave && + ((err = sl->family->fops->add_slave(sl)) < 0)) { + dev_err(&sl->dev, + "sysfs file creation for [%s] failed. err=%d\n", + dev_name(&sl->dev), err); + return err; + } + + break; + case BUS_NOTIFY_DEL_DEVICE: + /* Remove our sysfs files */ + if (sl->family->fops && sl->family->fops->remove_slave) + sl->family->fops->remove_slave(sl); + device_remove_file(&sl->dev, &w1_slave_attr_id); + device_remove_file(&sl->dev, &w1_slave_attr_name); + break; + } + return 0; +} + +static struct notifier_block w1_bus_nb = { + .notifier_call = w1_bus_notify, +}; + static int __w1_attach_slave_device(struct w1_slave *sl) { int err; @@ -615,44 +682,13 @@ static int __w1_attach_slave_device(struct w1_slave *sl) return err; } - /* Create "name" entry */ - err = device_create_file(&sl->dev, &w1_slave_attr_name); - if (err < 0) { - dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - dev_name(&sl->dev), err); - goto out_unreg; - } - - /* Create "id" entry */ - err = device_create_file(&sl->dev, &w1_slave_attr_id); - if (err < 0) { - dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - dev_name(&sl->dev), err); - goto out_rem1; - } - /* if the family driver needs to initialize something... */ - if (sl->family->fops && sl->family->fops->add_slave && - ((err = sl->family->fops->add_slave(sl)) < 0)) { - dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - dev_name(&sl->dev), err); - goto out_rem2; - } + dev_set_uevent_suppress(&sl->dev, false); + kobject_uevent(&sl->dev.kobj, KOBJ_ADD); list_add_tail(&sl->w1_slave_entry, &sl->master->slist); return 0; - -out_rem2: - device_remove_file(&sl->dev, &w1_slave_attr_id); -out_rem1: - device_remove_file(&sl->dev, &w1_slave_attr_name); -out_unreg: - device_unregister(&sl->dev); - return err; } static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) @@ -723,16 +759,11 @@ void w1_slave_detach(struct w1_slave *sl) list_del(&sl->w1_slave_entry); - if (sl->family->fops && sl->family->fops->remove_slave) - sl->family->fops->remove_slave(sl); - memset(&msg, 0, sizeof(msg)); memcpy(msg.id.id, &sl->reg_num, sizeof(msg.id)); msg.type = W1_SLAVE_REMOVE; w1_netlink_send(sl->master, &msg); - device_remove_file(&sl->dev, &w1_slave_attr_id); - device_remove_file(&sl->dev, &w1_slave_attr_name); device_unregister(&sl->dev); wait_for_completion(&sl->released); @@ -1017,6 +1048,10 @@ static int __init w1_init(void) goto err_out_exit_init; } + retval = bus_register_notifier(&w1_bus_type, &w1_bus_nb); + if (retval) + goto err_out_bus_unregister; + retval = driver_register(&w1_master_driver); if (retval) { printk(KERN_ERR -- cgit v1.2.3-70-g09d2 From 5b187b3c0edf9aae6ebbad61b9fbb4ec1795e18b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 13:24:33 -0700 Subject: w1: use default attribute groups for w1 slave devices As we have 2 sysfs files for the w1 slave devices, let the driver core create / destroy them automatically by setting the default attribute group for them, saving code and housekeeping logic. Acked-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1.c | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 3c798db0152..52b6c2f02f7 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -96,14 +96,15 @@ static void w1_slave_release(struct device *dev) complete(&sl->released); } -static ssize_t w1_slave_read_name(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) { struct w1_slave *sl = dev_to_w1_slave(dev); return sprintf(buf, "%s\n", sl->name); } +static DEVICE_ATTR_RO(name); -static ssize_t w1_slave_read_id(struct device *dev, +static ssize_t id_show(struct device *dev, struct device_attribute *attr, char *buf) { struct w1_slave *sl = dev_to_w1_slave(dev); @@ -112,11 +113,14 @@ static ssize_t w1_slave_read_id(struct device *dev, memcpy(buf, (u8 *)&sl->reg_num, count); return count; } +static DEVICE_ATTR_RO(id); -static struct device_attribute w1_slave_attr_name = - __ATTR(name, S_IRUGO, w1_slave_read_name, NULL); -static struct device_attribute w1_slave_attr_id = - __ATTR(id, S_IRUGO, w1_slave_read_id, NULL); +static struct attribute *w1_slave_attrs[] = { + &dev_attr_name.attr, + &dev_attr_id.attr, + NULL, +}; +ATTRIBUTE_GROUPS(w1_slave); /* Default family */ @@ -610,25 +614,6 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action, switch (action) { case BUS_NOTIFY_ADD_DEVICE: - /* Create our sysfs files before userspace is told about it */ - /* Create "name" entry */ - err = device_create_file(&sl->dev, &w1_slave_attr_name); - if (err < 0) { - dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - dev_name(&sl->dev), err); - return err; - } - - /* Create "id" entry */ - err = device_create_file(&sl->dev, &w1_slave_attr_id); - if (err < 0) { - dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - dev_name(&sl->dev), err); - return err; - } - /* if the family driver needs to initialize something... */ if (sl->family->fops && sl->family->fops->add_slave && ((err = sl->family->fops->add_slave(sl)) < 0)) { @@ -643,8 +628,6 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action, /* Remove our sysfs files */ if (sl->family->fops && sl->family->fops->remove_slave) sl->family->fops->remove_slave(sl); - device_remove_file(&sl->dev, &w1_slave_attr_id); - device_remove_file(&sl->dev, &w1_slave_attr_name); break; } return 0; @@ -662,6 +645,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl) sl->dev.driver = &w1_slave_driver; sl->dev.bus = &w1_bus_type; sl->dev.release = &w1_slave_release; + sl->dev.groups = w1_slave_groups; dev_set_name(&sl->dev, "%02x-%012llx", (unsigned int) sl->reg_num.family, -- cgit v1.2.3-70-g09d2 From 36c27a655a531f16b5567066600f0ea7fcb973b4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:44:55 -0700 Subject: w1: add attribute groups to struct w1_family_ops This lets w1 slave drivers declare an attribute group, and not have to create/destroy sysfs files directly. All w1 slave drivers will be fixed to use this field up in follow-on patches to this one. Acked-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1.c | 73 ++++++++++++++++++++++++++++---------------------- drivers/w1/w1_family.h | 1 + 2 files changed, 42 insertions(+), 32 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 52b6c2f02f7..22013ca2119 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -124,9 +124,9 @@ ATTRIBUTE_GROUPS(w1_slave); /* Default family */ -static ssize_t w1_default_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t rw_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, + size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); @@ -143,9 +143,9 @@ out_up: return count; } -static ssize_t w1_default_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t rw_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, + size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); @@ -155,29 +155,24 @@ static ssize_t w1_default_read(struct file *filp, struct kobject *kobj, return count; } -static struct bin_attribute w1_default_attr = { - .attr = { - .name = "rw", - .mode = S_IRUGO | S_IWUSR, - }, - .size = PAGE_SIZE, - .read = w1_default_read, - .write = w1_default_write, +static BIN_ATTR_RW(rw, PAGE_SIZE); + +static struct bin_attribute *w1_slave_bin_attrs[] = { + &bin_attr_rw, + NULL, }; -static int w1_default_add_slave(struct w1_slave *sl) -{ - return sysfs_create_bin_file(&sl->dev.kobj, &w1_default_attr); -} +static const struct attribute_group w1_slave_default_group = { + .bin_attrs = w1_slave_bin_attrs, +}; -static void w1_default_remove_slave(struct w1_slave *sl) -{ - sysfs_remove_bin_file(&sl->dev.kobj, &w1_default_attr); -} +static const struct attribute_group *w1_slave_default_groups[] = { + &w1_slave_default_group, + NULL, +}; static struct w1_family_ops w1_default_fops = { - .add_slave = w1_default_add_slave, - .remove_slave = w1_default_remove_slave, + .groups = w1_slave_default_groups, }; static struct w1_family w1_default_family = { @@ -600,6 +595,7 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action, { struct device *dev = data; struct w1_slave *sl; + struct w1_family_ops *fops; int err; /* @@ -611,23 +607,36 @@ static int w1_bus_notify(struct notifier_block *nb, unsigned long action, return 0; sl = dev_to_w1_slave(dev); + fops = sl->family->fops; switch (action) { case BUS_NOTIFY_ADD_DEVICE: /* if the family driver needs to initialize something... */ - if (sl->family->fops && sl->family->fops->add_slave && - ((err = sl->family->fops->add_slave(sl)) < 0)) { - dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - dev_name(&sl->dev), err); - return err; + if (fops->add_slave) { + err = fops->add_slave(sl); + if (err < 0) { + dev_err(&sl->dev, + "add_slave() call failed. err=%d\n", + err); + return err; + } + } + if (fops->groups) { + err = sysfs_create_groups(&sl->dev.kobj, fops->groups); + if (err) { + dev_err(&sl->dev, + "sysfs group creation failed. err=%d\n", + err); + return err; + } } break; case BUS_NOTIFY_DEL_DEVICE: - /* Remove our sysfs files */ - if (sl->family->fops && sl->family->fops->remove_slave) + if (fops->remove_slave) sl->family->fops->remove_slave(sl); + if (fops->groups) + sysfs_remove_groups(&sl->dev.kobj, fops->groups); break; } return 0; diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h index 625dd08f775..4ad0e81b640 100644 --- a/drivers/w1/w1_family.h +++ b/drivers/w1/w1_family.h @@ -52,6 +52,7 @@ struct w1_family_ops { int (* add_slave)(struct w1_slave *); void (* remove_slave)(struct w1_slave *); + const struct attribute_group **groups; }; struct w1_family -- cgit v1.2.3-70-g09d2 From b8a9f44fea2b97f34d95f983ecf5f1072632b421 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:44:56 -0700 Subject: w1: slaves: w1_therm: 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 Cc: David Stevenson Cc: Alexander Stein Cc: Michael Arndt Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_therm.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c index 8978360bd38..8b5ff33f72c 100644 --- a/drivers/w1/slaves/w1_therm.c +++ b/drivers/w1/slaves/w1_therm.c @@ -59,25 +59,19 @@ static int w1_strong_pullup = 1; module_param_named(strong_pullup, w1_strong_pullup, int, 0); -static ssize_t w1_therm_read(struct device *device, +static ssize_t w1_slave_show(struct device *device, struct device_attribute *attr, char *buf); -static struct device_attribute w1_therm_attr = - __ATTR(w1_slave, S_IRUGO, w1_therm_read, NULL); +static DEVICE_ATTR_RO(w1_slave); -static int w1_therm_add_slave(struct w1_slave *sl) -{ - return device_create_file(&sl->dev, &w1_therm_attr); -} - -static void w1_therm_remove_slave(struct w1_slave *sl) -{ - device_remove_file(&sl->dev, &w1_therm_attr); -} +static struct attribute *w1_therm_attrs[] = { + &dev_attr_w1_slave.attr, + NULL, +}; +ATTRIBUTE_GROUPS(w1_therm); static struct w1_family_ops w1_therm_fops = { - .add_slave = w1_therm_add_slave, - .remove_slave = w1_therm_remove_slave, + .groups = w1_therm_groups, }; static struct w1_family w1_therm_family_DS18S20 = { @@ -178,7 +172,7 @@ static inline int w1_convert_temp(u8 rom[9], u8 fid) } -static ssize_t w1_therm_read(struct device *device, +static ssize_t w1_slave_show(struct device *device, struct device_attribute *attr, char *buf) { struct w1_slave *sl = dev_to_w1_slave(device); -- cgit v1.2.3-70-g09d2 From 32ea4175aea26181e2ed9a87853bb4bebd44e59e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:44:57 -0700 Subject: 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 Cc: Jean-Francois Dagenais Cc: Andrew Morton Cc: Alexander Stein Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds2408.c | 174 +++++++++++++----------------------------- 1 file changed, 52 insertions(+), 122 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds2408.c b/drivers/w1/slaves/w1_ds2408.c index cb8a8e5d957..7dfa0e11688 100644 --- a/drivers/w1/slaves/w1_ds2408.c +++ b/drivers/w1/slaves/w1_ds2408.c @@ -72,10 +72,9 @@ static int _read_reg(struct w1_slave *sl, u8 address, unsigned char* buf) return 1; } -static ssize_t w1_f29_read_state( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t state_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, + size_t count) { dev_dbg(&kobj_to_w1_slave(kobj)->dev, "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", @@ -85,10 +84,9 @@ static ssize_t w1_f29_read_state( return _read_reg(kobj_to_w1_slave(kobj), W1_F29_REG_LOGIG_STATE, buf); } -static ssize_t w1_f29_read_output( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t output_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { dev_dbg(&kobj_to_w1_slave(kobj)->dev, "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", @@ -99,10 +97,9 @@ static ssize_t w1_f29_read_output( W1_F29_REG_OUTPUT_LATCH_STATE, buf); } -static ssize_t w1_f29_read_activity( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t activity_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { dev_dbg(&kobj_to_w1_slave(kobj)->dev, "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", @@ -113,10 +110,9 @@ static ssize_t w1_f29_read_activity( W1_F29_REG_ACTIVITY_LATCH_STATE, buf); } -static ssize_t w1_f29_read_cond_search_mask( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t cond_search_mask_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { dev_dbg(&kobj_to_w1_slave(kobj)->dev, "Reading %s kobj: %p, off: %0#10x, count: %zu, buff addr: %p", @@ -127,10 +123,10 @@ static ssize_t w1_f29_read_cond_search_mask( W1_F29_REG_COND_SEARCH_SELECT_MASK, buf); } -static ssize_t w1_f29_read_cond_search_polarity( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t cond_search_polarity_read(struct file *filp, + struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t off, size_t count) { if (count != 1 || off != 0) return -EFAULT; @@ -138,10 +134,9 @@ static ssize_t w1_f29_read_cond_search_polarity( W1_F29_REG_COND_SEARCH_POL_SELECT, buf); } -static ssize_t w1_f29_read_status_control( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t status_control_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { if (count != 1 || off != 0) return -EFAULT; @@ -149,13 +144,9 @@ static ssize_t w1_f29_read_status_control( W1_F29_REG_CONTROL_AND_STATUS, buf); } - - - -static ssize_t w1_f29_write_output( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t output_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); u8 w1_buf[3]; @@ -224,10 +215,9 @@ error: /** * Writing to the activity file resets the activity latches. */ -static ssize_t w1_f29_write_activity( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t activity_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); unsigned int retries = W1_F29_RETRIES; @@ -255,13 +245,9 @@ error: return -EIO; } -static ssize_t w1_f29_write_status_control( - struct file *filp, - struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, - loff_t off, - size_t count) +static ssize_t status_control_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); u8 w1_buf[4]; @@ -330,91 +316,35 @@ out: return res; } -static struct bin_attribute w1_f29_sysfs_bin_files[] = { - { - .attr = { - .name = "state", - .mode = S_IRUGO, - }, - .size = 1, - .read = w1_f29_read_state, - }, - { - .attr = { - .name = "output", - .mode = S_IRUGO | S_IWUSR | S_IWGRP, - }, - .size = 1, - .read = w1_f29_read_output, - .write = w1_f29_write_output, - }, - { - .attr = { - .name = "activity", - .mode = S_IRUGO, - }, - .size = 1, - .read = w1_f29_read_activity, - .write = w1_f29_write_activity, - }, - { - .attr = { - .name = "cond_search_mask", - .mode = S_IRUGO, - }, - .size = 1, - .read = w1_f29_read_cond_search_mask, - }, - { - .attr = { - .name = "cond_search_polarity", - .mode = S_IRUGO, - }, - .size = 1, - .read = w1_f29_read_cond_search_polarity, - }, - { - .attr = { - .name = "status_control", - .mode = S_IRUGO | S_IWUSR | S_IWGRP, - }, - .size = 1, - .read = w1_f29_read_status_control, - .write = w1_f29_write_status_control, - } +static BIN_ATTR_RO(state, 1); +static BIN_ATTR_RW(output, 1); +static BIN_ATTR_RW(activity, 1); +static BIN_ATTR_RO(cond_search_mask, 1); +static BIN_ATTR_RO(cond_search_polarity, 1); +static BIN_ATTR_RW(status_control, 1); + +static struct bin_attribute *w1_f29_bin_attrs[] = { + &bin_attr_state, + &bin_attr_output, + &bin_attr_activity, + &bin_attr_cond_search_mask, + &bin_attr_cond_search_polarity, + &bin_attr_status_control, + NULL, }; -static int w1_f29_add_slave(struct w1_slave *sl) -{ - int err = 0; - int i; - - err = w1_f29_disable_test_mode(sl); - if (err) - return err; - - for (i = 0; i < ARRAY_SIZE(w1_f29_sysfs_bin_files) && !err; ++i) - err = sysfs_create_bin_file( - &sl->dev.kobj, - &(w1_f29_sysfs_bin_files[i])); - if (err) - while (--i >= 0) - sysfs_remove_bin_file(&sl->dev.kobj, - &(w1_f29_sysfs_bin_files[i])); - return err; -} +static const struct attribute_group w1_f29_group = { + .bin_attrs = w1_f29_bin_attrs, +}; -static void w1_f29_remove_slave(struct w1_slave *sl) -{ - int i; - for (i = ARRAY_SIZE(w1_f29_sysfs_bin_files) - 1; i >= 0; --i) - sysfs_remove_bin_file(&sl->dev.kobj, - &(w1_f29_sysfs_bin_files[i])); -} +static const struct attribute_group *w1_f29_groups[] = { + &w1_f29_group, + NULL, +}; static struct w1_family_ops w1_f29_fops = { - .add_slave = w1_f29_add_slave, - .remove_slave = w1_f29_remove_slave, + .add_slave = w1_f29_disable_test_mode, + .groups = w1_f29_groups, }; static struct w1_family w1_family_29 = { -- cgit v1.2.3-70-g09d2 From 729fb9d33fe239e350a7e33e9f6aec2767086bd4 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:44:58 -0700 Subject: 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 Cc: Andrew Morton Cc: Alexander Stein Cc: Mariusz Bialonczyk Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds2413.c | 72 +++++++++++++------------------------------ 1 file changed, 22 insertions(+), 50 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds2413.c b/drivers/w1/slaves/w1_ds2413.c index 85937773a96..ee28fc1ff39 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)); #define W1_F3A_FUNC_PIO_ACCESS_WRITE 0x5A #define W1_F3A_SUCCESS_CONFIRM_BYTE 0xAA -static ssize_t w1_f3a_read_state( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t state_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, + size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); dev_dbg(&sl->dev, @@ -66,10 +65,11 @@ static ssize_t w1_f3a_read_state( return 1; } -static ssize_t w1_f3a_write_output( - struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static BIN_ATTR_RO(state, 1); + +static ssize_t output_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); u8 w1_buf[3]; @@ -110,53 +110,25 @@ error: return -EIO; } -#define NB_SYSFS_BIN_FILES 2 -static struct bin_attribute w1_f3a_sysfs_bin_files[NB_SYSFS_BIN_FILES] = { - { - .attr = { - .name = "state", - .mode = S_IRUGO, - }, - .size = 1, - .read = w1_f3a_read_state, - }, - { - .attr = { - .name = "output", - .mode = S_IRUGO | S_IWUSR | S_IWGRP, - }, - .size = 1, - .write = w1_f3a_write_output, - } +static BIN_ATTR(output, S_IRUGO | S_IWUSR | S_IWGRP, NULL, output_write, 1); + +static struct bin_attribute *w1_f3a_bin_attrs[] = { + &bin_attr_state, + &bin_attr_output, + NULL, }; -static int w1_f3a_add_slave(struct w1_slave *sl) -{ - int err = 0; - int i; - - for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i) - err = sysfs_create_bin_file( - &sl->dev.kobj, - &(w1_f3a_sysfs_bin_files[i])); - if (err) - while (--i >= 0) - sysfs_remove_bin_file(&sl->dev.kobj, - &(w1_f3a_sysfs_bin_files[i])); - return err; -} +static const struct attribute_group w1_f3a_group = { + .bin_attrs = w1_f3a_bin_attrs, +}; -static void w1_f3a_remove_slave(struct w1_slave *sl) -{ - int i; - for (i = NB_SYSFS_BIN_FILES - 1; i >= 0; --i) - sysfs_remove_bin_file(&sl->dev.kobj, - &(w1_f3a_sysfs_bin_files[i])); -} +static const struct attribute_group *w1_f3a_groups[] = { + &w1_f3a_group, + NULL, +}; static struct w1_family_ops w1_f3a_fops = { - .add_slave = w1_f3a_add_slave, - .remove_slave = w1_f3a_remove_slave, + .groups = w1_f3a_groups, }; static struct w1_family w1_family_3a = { -- cgit v1.2.3-70-g09d2 From 94c9e6d665011a9926c5f6fd349a6c665093e721 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:44:59 -0700 Subject: w1: slaves: w1_ds2423: 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 Cc: Alexander Stein Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds2423.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds2423.c b/drivers/w1/slaves/w1_ds2423.c index 7f86aec7408..7e41b7d91fb 100644 --- a/drivers/w1/slaves/w1_ds2423.c +++ b/drivers/w1/slaves/w1_ds2423.c @@ -40,14 +40,8 @@ #define COUNTER_COUNT 4 #define READ_BYTE_COUNT 42 -static ssize_t w1_counter_read(struct device *device, - struct device_attribute *attr, char *buf); - -static struct device_attribute w1_counter_attr = - __ATTR(w1_slave, S_IRUGO, w1_counter_read, NULL); - -static ssize_t w1_counter_read(struct device *device, - struct device_attribute *attr, char *out_buf) +static ssize_t w1_slave_show(struct device *device, + struct device_attribute *attr, char *out_buf) { struct w1_slave *sl = dev_to_w1_slave(device); struct w1_master *dev = sl->master; @@ -128,19 +122,16 @@ static ssize_t w1_counter_read(struct device *device, return PAGE_SIZE - c; } -static int w1_f1d_add_slave(struct w1_slave *sl) -{ - return device_create_file(&sl->dev, &w1_counter_attr); -} +static DEVICE_ATTR_RO(w1_slave); -static void w1_f1d_remove_slave(struct w1_slave *sl) -{ - device_remove_file(&sl->dev, &w1_counter_attr); -} +static struct attribute *w1_f1d_attrs[] = { + &dev_attr_w1_slave.attr, + NULL, +}; +ATTRIBUTE_GROUPS(w1_f1d); static struct w1_family_ops w1_f1d_fops = { - .add_slave = w1_f1d_add_slave, - .remove_slave = w1_f1d_remove_slave, + .groups = w1_f1d_groups, }; static struct w1_family w1_family_1d = { -- cgit v1.2.3-70-g09d2 From b3c6061daca33c1e97b8da675a2529fc5d49c05e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:45:00 -0700 Subject: w1: slaves: w1_ds2431: 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 Cc: Alexander Stein Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds2431.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds2431.c b/drivers/w1/slaves/w1_ds2431.c index cef8605e43e..9c4ff9d28ad 100644 --- a/drivers/w1/slaves/w1_ds2431.c +++ b/drivers/w1/slaves/w1_ds2431.c @@ -96,9 +96,9 @@ static int w1_f2d_readblock(struct w1_slave *sl, int off, int count, char *buf) return -1; } -static ssize_t w1_f2d_read_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t eeprom_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); int todo = count; @@ -202,9 +202,9 @@ retry: return 0; } -static ssize_t w1_f2d_write_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t eeprom_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); int addr, len; @@ -264,29 +264,24 @@ out_up: return count; } -static struct bin_attribute w1_f2d_bin_attr = { - .attr = { - .name = "eeprom", - .mode = S_IRUGO | S_IWUSR, - }, - .size = W1_F2D_EEPROM_SIZE, - .read = w1_f2d_read_bin, - .write = w1_f2d_write_bin, +static BIN_ATTR_RW(eeprom, W1_F2D_EEPROM_SIZE); + +static struct bin_attribute *w1_f2d_bin_attrs[] = { + &bin_attr_eeprom, + NULL, }; -static int w1_f2d_add_slave(struct w1_slave *sl) -{ - return sysfs_create_bin_file(&sl->dev.kobj, &w1_f2d_bin_attr); -} +static const struct attribute_group w1_f2d_group = { + .bin_attrs = w1_f2d_bin_attrs, +}; -static void w1_f2d_remove_slave(struct w1_slave *sl) -{ - sysfs_remove_bin_file(&sl->dev.kobj, &w1_f2d_bin_attr); -} +static const struct attribute_group *w1_f2d_groups[] = { + &w1_f2d_group, + NULL, +}; static struct w1_family_ops w1_f2d_fops = { - .add_slave = w1_f2d_add_slave, - .remove_slave = w1_f2d_remove_slave, + .groups = w1_f2d_groups, }; static struct w1_family w1_family_2d = { -- cgit v1.2.3-70-g09d2 From 38f40982e16fde872b8c11bb1cc6553cc42884b0 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:45:01 -0700 Subject: w1: slaves: w1_ds2433: 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 Cc: Alexander Stein Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds2433.c | 47 ++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds2433.c b/drivers/w1/slaves/w1_ds2433.c index 10cc1b6176e..72319a968a9 100644 --- a/drivers/w1/slaves/w1_ds2433.c +++ b/drivers/w1/slaves/w1_ds2433.c @@ -93,9 +93,9 @@ static int w1_f23_refresh_block(struct w1_slave *sl, struct w1_f23_data *data, } #endif /* CONFIG_W1_SLAVE_DS2433_CRC */ -static ssize_t w1_f23_read_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t eeprom_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); #ifdef CONFIG_W1_SLAVE_DS2433_CRC @@ -207,9 +207,9 @@ static int w1_f23_write(struct w1_slave *sl, int addr, int len, const u8 *data) return 0; } -static ssize_t w1_f23_write_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t eeprom_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); int addr, len, idx; @@ -257,19 +257,24 @@ out_up: return count; } -static struct bin_attribute w1_f23_bin_attr = { - .attr = { - .name = "eeprom", - .mode = S_IRUGO | S_IWUSR, - }, - .size = W1_EEPROM_SIZE, - .read = w1_f23_read_bin, - .write = w1_f23_write_bin, +static BIN_ATTR_RW(eeprom, W1_EEPROM_SIZE); + +static struct bin_attribute *w1_f23_bin_attributes[] = { + &bin_attr_eeprom, + NULL, +}; + +static const struct attribute_group w1_f23_group = { + .bin_attrs = w1_f23_bin_attributes, +}; + +static const struct attribute_group *w1_f23_groups[] = { + &w1_f23_group, + NULL, }; static int w1_f23_add_slave(struct w1_slave *sl) { - int err; #ifdef CONFIG_W1_SLAVE_DS2433_CRC struct w1_f23_data *data; @@ -279,15 +284,7 @@ static int w1_f23_add_slave(struct w1_slave *sl) sl->family_data = data; #endif /* CONFIG_W1_SLAVE_DS2433_CRC */ - - err = sysfs_create_bin_file(&sl->dev.kobj, &w1_f23_bin_attr); - -#ifdef CONFIG_W1_SLAVE_DS2433_CRC - if (err) - kfree(data); -#endif /* CONFIG_W1_SLAVE_DS2433_CRC */ - - return err; + return 0; } static void w1_f23_remove_slave(struct w1_slave *sl) @@ -296,12 +293,12 @@ static void w1_f23_remove_slave(struct w1_slave *sl) kfree(sl->family_data); sl->family_data = NULL; #endif /* CONFIG_W1_SLAVE_DS2433_CRC */ - sysfs_remove_bin_file(&sl->dev.kobj, &w1_f23_bin_attr); } static struct w1_family_ops w1_f23_fops = { .add_slave = w1_f23_add_slave, .remove_slave = w1_f23_remove_slave, + .groups = w1_f23_groups, }; static struct w1_family w1_family_23 = { -- cgit v1.2.3-70-g09d2 From fa33a65a9cf7e2069cc1f26b057867e865daadba Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:45:02 -0700 Subject: 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 Cc: Alexander Stein Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds28e04.c | 112 ++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 70 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds28e04.c b/drivers/w1/slaves/w1_ds28e04.c index cd30a6d95ea..365d6dff21d 100644 --- a/drivers/w1/slaves/w1_ds28e04.c +++ b/drivers/w1/slaves/w1_ds28e04.c @@ -118,9 +118,9 @@ static int w1_f1C_read(struct w1_slave *sl, int addr, int len, char *data) return w1_read_block(sl->master, data, len); } -static ssize_t w1_f1C_read_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t eeprom_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); struct w1_f1C_data *data = sl->family_data; @@ -226,9 +226,9 @@ static int w1_f1C_write(struct w1_slave *sl, int addr, int len, const u8 *data) return 0; } -static ssize_t w1_f1C_write_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t eeprom_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); @@ -280,9 +280,11 @@ out_up: return count; } -static ssize_t w1_f1C_read_pio(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static BIN_ATTR_RW(eeprom, W1_EEPROM_SIZE); + +static ssize_t pio_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, + size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); @@ -299,9 +301,9 @@ static ssize_t w1_f1C_read_pio(struct file *filp, struct kobject *kobj, return ret; } -static ssize_t w1_f1C_write_pio(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t pio_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, loff_t off, + size_t count) { struct w1_slave *sl = kobj_to_w1_slave(kobj); @@ -339,8 +341,10 @@ static ssize_t w1_f1C_write_pio(struct file *filp, struct kobject *kobj, return count; } -static ssize_t w1_f1C_show_crccheck(struct device *dev, - struct device_attribute *attr, char *buf) +static BIN_ATTR_RW(pio, 1); + +static ssize_t crccheck_show(struct device *dev, struct device_attribute *attr, + char *buf) { if (put_user(w1_enable_crccheck + 0x30, buf)) return -EFAULT; @@ -348,9 +352,8 @@ static ssize_t w1_f1C_show_crccheck(struct device *dev, return sizeof(w1_enable_crccheck); } -static ssize_t w1_f1C_store_crccheck(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t crccheck_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { char val; @@ -371,35 +374,31 @@ static ssize_t w1_f1C_store_crccheck(struct device *dev, return sizeof(w1_enable_crccheck); } -#define NB_SYSFS_BIN_FILES 2 -static struct bin_attribute w1_f1C_bin_attr[NB_SYSFS_BIN_FILES] = { - { - .attr = { - .name = "eeprom", - .mode = S_IRUGO | S_IWUSR, - }, - .size = W1_EEPROM_SIZE, - .read = w1_f1C_read_bin, - .write = w1_f1C_write_bin, - }, - { - .attr = { - .name = "pio", - .mode = S_IRUGO | S_IWUSR, - }, - .size = 1, - .read = w1_f1C_read_pio, - .write = w1_f1C_write_pio, - } +static DEVICE_ATTR_RW(crccheck); + +static struct attribute *w1_f1C_attrs[] = { + &dev_attr_crccheck.attr, + NULL, }; -static DEVICE_ATTR(crccheck, S_IWUSR | S_IRUGO, - w1_f1C_show_crccheck, w1_f1C_store_crccheck); +static struct bin_attribute *w1_f1C_bin_attrs[] = { + &bin_attr_eeprom, + &bin_attr_pio, + NULL, +}; + +static const struct attribute_group w1_f1C_group = { + .attrs = w1_f1C_attrs, + .bin_attrs = w1_f1C_bin_attrs, +}; + +static const struct attribute_group *w1_f1C_groups[] = { + &w1_f1C_group, + NULL, +}; static int w1_f1C_add_slave(struct w1_slave *sl) { - int err = 0; - int i; struct w1_f1C_data *data = NULL; if (w1_enable_crccheck) { @@ -409,46 +408,19 @@ static int w1_f1C_add_slave(struct w1_slave *sl) sl->family_data = data; } - /* create binary sysfs attributes */ - for (i = 0; i < NB_SYSFS_BIN_FILES && !err; ++i) - err = sysfs_create_bin_file( - &sl->dev.kobj, &(w1_f1C_bin_attr[i])); - - if (!err) { - /* create device attributes */ - err = device_create_file(&sl->dev, &dev_attr_crccheck); - } - - if (err) { - /* remove binary sysfs attributes */ - for (i = 0; i < NB_SYSFS_BIN_FILES; ++i) - sysfs_remove_bin_file( - &sl->dev.kobj, &(w1_f1C_bin_attr[i])); - - kfree(data); - } - - return err; + return 0; } static void w1_f1C_remove_slave(struct w1_slave *sl) { - int i; - kfree(sl->family_data); sl->family_data = NULL; - - /* remove device attributes */ - device_remove_file(&sl->dev, &dev_attr_crccheck); - - /* remove binary sysfs attributes */ - for (i = 0; i < NB_SYSFS_BIN_FILES; ++i) - sysfs_remove_bin_file(&sl->dev.kobj, &(w1_f1C_bin_attr[i])); } static struct w1_family_ops w1_f1C_fops = { .add_slave = w1_f1C_add_slave, .remove_slave = w1_f1C_remove_slave, + .groups = w1_f1C_groups, }; static struct w1_family w1_family_1C = { -- cgit v1.2.3-70-g09d2 From 9365261db45ddf1dc0800ce70830928beb0efd78 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:45:03 -0700 Subject: w1: slaves: w1_ds2780: 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 Cc: Alexander Stein Cc: Andrew Morton Cc: Wei Yongjun Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds2780.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds2780.c b/drivers/w1/slaves/w1_ds2780.c index 0cd7a27b5d6..50e85f7929d 100644 --- a/drivers/w1/slaves/w1_ds2780.c +++ b/drivers/w1/slaves/w1_ds2780.c @@ -89,22 +89,28 @@ int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd) } EXPORT_SYMBOL(w1_ds2780_eeprom_cmd); -static ssize_t w1_ds2780_read_bin(struct file *filp, - struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj); return w1_ds2780_io(dev, buf, off, count, 0); } -static struct bin_attribute w1_ds2780_bin_attr = { - .attr = { - .name = "w1_slave", - .mode = S_IRUGO, - }, - .size = DS2780_DATA_SIZE, - .read = w1_ds2780_read_bin, +static BIN_ATTR_RO(w1_slave, DS2780_DATA_SIZE); + +static struct bin_attribute *w1_ds2780_bin_attrs[] = { + &bin_attr_w1_slave, + NULL, +}; + +static const struct attribute_group w1_ds2780_group = { + .bin_attrs = w1_ds2780_bin_attrs, +}; + +static const struct attribute_group *w1_ds2780_groups[] = { + &w1_ds2780_group, + NULL, }; static DEFINE_IDA(bat_ida); @@ -132,16 +138,10 @@ static int w1_ds2780_add_slave(struct w1_slave *sl) if (ret) goto pdev_add_failed; - ret = sysfs_create_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr); - if (ret) - goto bin_attr_failed; - dev_set_drvdata(&sl->dev, pdev); return 0; -bin_attr_failed: - platform_device_del(pdev); pdev_add_failed: platform_device_put(pdev); pdev_alloc_failed: @@ -157,12 +157,12 @@ static void w1_ds2780_remove_slave(struct w1_slave *sl) platform_device_unregister(pdev); ida_simple_remove(&bat_ida, id); - sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr); } static struct w1_family_ops w1_ds2780_fops = { .add_slave = w1_ds2780_add_slave, .remove_slave = w1_ds2780_remove_slave, + .groups = w1_ds2780_groups, }; static struct w1_family w1_ds2780_family = { -- cgit v1.2.3-70-g09d2 From 0597129cdc464ba3723f340a5a6cbd1e80e78210 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:45:04 -0700 Subject: w1: slaves: w1_ds2760: 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 Cc: Alexander Stein Cc: Andrew Morton Cc: Wei Yongjun Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds2760.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c index 93719d25d84..65f90dccd60 100644 --- a/drivers/w1/slaves/w1_ds2760.c +++ b/drivers/w1/slaves/w1_ds2760.c @@ -97,21 +97,28 @@ int w1_ds2760_recall_eeprom(struct device *dev, int addr) return w1_ds2760_eeprom_cmd(dev, addr, W1_DS2760_RECALL_DATA); } -static ssize_t w1_ds2760_read_bin(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj); return w1_ds2760_read(dev, buf, off, count); } -static struct bin_attribute w1_ds2760_bin_attr = { - .attr = { - .name = "w1_slave", - .mode = S_IRUGO, - }, - .size = DS2760_DATA_SIZE, - .read = w1_ds2760_read_bin, +static BIN_ATTR_RO(w1_slave, DS2760_DATA_SIZE); + +static struct bin_attribute *w1_ds2760_bin_attrs[] = { + &bin_attr_w1_slave, + NULL, +}; + +static const struct attribute_group w1_ds2760_group = { + .bin_attrs = w1_ds2760_bin_attrs, +}; + +static const struct attribute_group *w1_ds2760_groups[] = { + &w1_ds2760_group, + NULL, }; static DEFINE_IDA(bat_ida); @@ -139,16 +146,10 @@ static int w1_ds2760_add_slave(struct w1_slave *sl) if (ret) goto pdev_add_failed; - ret = sysfs_create_bin_file(&sl->dev.kobj, &w1_ds2760_bin_attr); - if (ret) - goto bin_attr_failed; - dev_set_drvdata(&sl->dev, pdev); goto success; -bin_attr_failed: - platform_device_del(pdev); pdev_add_failed: platform_device_put(pdev); pdev_alloc_failed: @@ -165,12 +166,12 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl) platform_device_unregister(pdev); ida_simple_remove(&bat_ida, id); - sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2760_bin_attr); } static struct w1_family_ops w1_ds2760_fops = { .add_slave = w1_ds2760_add_slave, .remove_slave = w1_ds2760_remove_slave, + .groups = w1_ds2760_groups, }; static struct w1_family w1_ds2760_family = { -- cgit v1.2.3-70-g09d2 From eefafb79a4489b7eeb1853621f95139e3f7cb94c Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 15:45:05 -0700 Subject: w1: slaves: w1_ds2781: 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 Cc: Alexander Stein Cc: Andrew Morton Cc: Wei Yongjun Signed-off-by: Greg Kroah-Hartman --- drivers/w1/slaves/w1_ds2781.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/slaves/w1_ds2781.c b/drivers/w1/slaves/w1_ds2781.c index 1aba8e41ad4..1eb98fb1688 100644 --- a/drivers/w1/slaves/w1_ds2781.c +++ b/drivers/w1/slaves/w1_ds2781.c @@ -87,22 +87,28 @@ int w1_ds2781_eeprom_cmd(struct device *dev, int addr, int cmd) } EXPORT_SYMBOL(w1_ds2781_eeprom_cmd); -static ssize_t w1_ds2781_read_bin(struct file *filp, - struct kobject *kobj, - struct bin_attribute *bin_attr, - char *buf, loff_t off, size_t count) +static ssize_t w1_slave_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) { struct device *dev = container_of(kobj, struct device, kobj); return w1_ds2781_io(dev, buf, off, count, 0); } -static struct bin_attribute w1_ds2781_bin_attr = { - .attr = { - .name = "w1_slave", - .mode = S_IRUGO, - }, - .size = DS2781_DATA_SIZE, - .read = w1_ds2781_read_bin, +static BIN_ATTR_RO(w1_slave, DS2781_DATA_SIZE); + +static struct bin_attribute *w1_ds2781_bin_attrs[] = { + &bin_attr_w1_slave, + NULL, +}; + +static const struct attribute_group w1_ds2781_group = { + .bin_attrs = w1_ds2781_bin_attrs, +}; + +static const struct attribute_group *w1_ds2781_groups[] = { + &w1_ds2781_group, + NULL, }; static DEFINE_IDA(bat_ida); @@ -130,16 +136,10 @@ static int w1_ds2781_add_slave(struct w1_slave *sl) if (ret) goto pdev_add_failed; - ret = sysfs_create_bin_file(&sl->dev.kobj, &w1_ds2781_bin_attr); - if (ret) - goto bin_attr_failed; - dev_set_drvdata(&sl->dev, pdev); return 0; -bin_attr_failed: - platform_device_del(pdev); pdev_add_failed: platform_device_put(pdev); pdev_alloc_failed: @@ -155,12 +155,12 @@ static void w1_ds2781_remove_slave(struct w1_slave *sl) platform_device_unregister(pdev); ida_simple_remove(&bat_ida, id); - sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2781_bin_attr); } static struct w1_family_ops w1_ds2781_fops = { .add_slave = w1_ds2781_add_slave, .remove_slave = w1_ds2781_remove_slave, + .groups = w1_ds2781_groups, }; static struct w1_family w1_ds2781_family = { -- cgit v1.2.3-70-g09d2 From d13a280faec9c2c7d530fd3c6787a4d09f3f1c0f Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 14:24:36 -0700 Subject: USB: serial: convert bus code to use drv_groups The drv_attrs field of struct bus_type is going away soon, drv_groups should be used instead. This converts the USB serial bus code to use the correct field. Signed-off-by: Greg Kroah-Hartman --- drivers/usb/serial/bus.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c index f053b302a00..24624339ef8 100644 --- a/drivers/usb/serial/bus.c +++ b/drivers/usb/serial/bus.c @@ -122,7 +122,7 @@ static int usb_serial_device_remove(struct device *dev) return retval; } -static ssize_t store_new_id(struct device_driver *driver, +static ssize_t new_id_store(struct device_driver *driver, const char *buf, size_t count) { struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver); @@ -135,17 +135,19 @@ static ssize_t store_new_id(struct device_driver *driver, return retval; } -static ssize_t show_dynids(struct device_driver *driver, char *buf) +static ssize_t new_id_show(struct device_driver *driver, char *buf) { struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver); return usb_show_dynids(&usb_drv->dynids, buf); } +static DRIVER_ATTR_RW(new_id); -static struct driver_attribute drv_attrs[] = { - __ATTR(new_id, S_IRUGO | S_IWUSR, show_dynids, store_new_id), - __ATTR_NULL, +static struct attribute *usb_serial_drv_attrs[] = { + &driver_attr_new_id.attr, + NULL, }; +ATTRIBUTE_GROUPS(usb_serial_drv); static void free_dynids(struct usb_serial_driver *drv) { @@ -164,7 +166,7 @@ struct bus_type usb_serial_bus_type = { .match = usb_serial_device_match, .probe = usb_serial_device_probe, .remove = usb_serial_device_remove, - .drv_attrs = drv_attrs, + .drv_groups = usb_serial_drv_groups, }; int usb_serial_bus_register(struct usb_serial_driver *driver) -- cgit v1.2.3-70-g09d2 From 32f389ec5689751bae758c9b3e3982b2acb696c1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 14:24:39 -0700 Subject: MEI: convert bus code to use dev_groups The dev_attrs field of struct bus_type is going away soon, dev_groups should be used instead. This converts the MEI bus code to use the correct field. Acked-by: Tomas Winkler Cc: Samuel Ortiz Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/bus.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 9ecd49a7be1..2ce92a6a9b5 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -108,11 +108,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a, return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; } +static DEVICE_ATTR_RO(modalias); -static struct device_attribute mei_cl_dev_attrs[] = { - __ATTR_RO(modalias), - __ATTR_NULL, +static struct attribute *mei_cl_dev_attrs[] = { + &dev_attr_modalias.attr, + NULL, }; +ATTRIBUTE_GROUPS(mei_cl_dev); static int mei_cl_uevent(struct device *dev, struct kobj_uevent_env *env) { @@ -124,7 +126,7 @@ static int mei_cl_uevent(struct device *dev, struct kobj_uevent_env *env) static struct bus_type mei_cl_bus_type = { .name = "mei", - .dev_attrs = mei_cl_dev_attrs, + .dev_groups = mei_cl_dev_groups, .match = mei_cl_device_match, .probe = mei_cl_device_probe, .remove = mei_cl_device_remove, -- cgit v1.2.3-70-g09d2 From d06262e58546e5bf5669ef185fb913cca4637bd6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 14:24:37 -0700 Subject: driver-core: platform: convert bus code to use dev_groups The dev_attrs field of struct bus_type is going away soon, dev_groups should be used instead. This converts the platform bus code to use the correct field. Signed-off-by: Greg Kroah-Hartman --- drivers/base/platform.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 9d538cf9204..4f8bef3eb5a 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -672,11 +672,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a, return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; } +static DEVICE_ATTR_RO(modalias); -static struct device_attribute platform_dev_attrs[] = { - __ATTR_RO(modalias), - __ATTR_NULL, +static struct attribute *platform_dev_attrs[] = { + &dev_attr_modalias.attr, + NULL, }; +ATTRIBUTE_GROUPS(platform_dev); static int platform_uevent(struct device *dev, struct kobj_uevent_env *env) { @@ -893,7 +895,7 @@ static const struct dev_pm_ops platform_dev_pm_ops = { struct bus_type platform_bus_type = { .name = "platform", - .dev_attrs = platform_dev_attrs, + .dev_groups = platform_dev_groups, .match = platform_match, .uevent = platform_uevent, .pm = &platform_dev_pm_ops, -- cgit v1.2.3-70-g09d2 From 2581c9cc0de6eeba8d5553c98aab6e0f75d184e0 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 15:04:42 -0700 Subject: driver core: bus: use DRIVER_ATTR_WO() There are two bus attributes that can better be defined using DRIVER_ATTR_WO(), so convert them to the new macro, making it easier to audit attribute permissions. Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 235e2b06ac0..7fc2a13e84a 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -165,8 +165,8 @@ static const struct kset_uevent_ops bus_uevent_ops = { static struct kset *bus_kset; /* Manually detach a device from its associated driver. */ -static ssize_t driver_unbind(struct device_driver *drv, - const char *buf, size_t count) +static ssize_t unbind_store(struct device_driver *drv, const char *buf, + size_t count) { struct bus_type *bus = bus_get(drv->bus); struct device *dev; @@ -185,15 +185,15 @@ static ssize_t driver_unbind(struct device_driver *drv, bus_put(bus); return err; } -static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); +static DRIVER_ATTR_WO(unbind); /* * Manually attach a device to a driver. * Note: the driver must want to bind to the device, * it is not possible to override the driver's id table. */ -static ssize_t driver_bind(struct device_driver *drv, - const char *buf, size_t count) +static ssize_t bind_store(struct device_driver *drv, const char *buf, + size_t count) { struct bus_type *bus = bus_get(drv->bus); struct device *dev; @@ -221,7 +221,7 @@ static ssize_t driver_bind(struct device_driver *drv, bus_put(bus); return err; } -static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); +static DRIVER_ATTR_WO(bind); static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf) { @@ -665,8 +665,8 @@ static void remove_probe_files(struct bus_type *bus) bus_remove_file(bus, &bus_attr_drivers_probe); } -static ssize_t driver_uevent_store(struct device_driver *drv, - const char *buf, size_t count) +static ssize_t uevent_store(struct device_driver *drv, const char *buf, + size_t count) { enum kobject_action action; @@ -674,7 +674,7 @@ static ssize_t driver_uevent_store(struct device_driver *drv, kobject_uevent(&drv->p->kobj, action); return count; } -static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store); +static DRIVER_ATTR_WO(uevent); /** * bus_add_driver - Add a driver to the bus. -- cgit v1.2.3-70-g09d2 From c5e064a6981603de65c61c4989856e984c7ad66d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 17:07:26 -0700 Subject: driver core: core: use DEVICE_ATTR_RO Use DEVICE_ATTR_RO() instead of a "raw" __ATTR macro, making it easier to audit exactly what is going on with the sysfs files. Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'drivers') diff --git a/drivers/base/core.c b/drivers/base/core.c index ae1acdf21bd..921b94184dc 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -345,7 +345,7 @@ static const struct kset_uevent_ops device_uevent_ops = { .uevent = dev_uevent, }; -static ssize_t show_uevent(struct device *dev, struct device_attribute *attr, +static ssize_t uevent_show(struct device *dev, struct device_attribute *attr, char *buf) { struct kobject *top_kobj; @@ -388,7 +388,7 @@ out: return count; } -static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, +static ssize_t uevent_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { enum kobject_action action; @@ -399,11 +399,9 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, dev_err(dev, "uevent: unknown action-string\n"); return count; } +static DEVICE_ATTR_RW(uevent); -static struct device_attribute uevent_attr = - __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent); - -static ssize_t show_online(struct device *dev, struct device_attribute *attr, +static ssize_t online_show(struct device *dev, struct device_attribute *attr, char *buf) { bool val; @@ -414,7 +412,7 @@ static ssize_t show_online(struct device *dev, struct device_attribute *attr, return sprintf(buf, "%u\n", val); } -static ssize_t store_online(struct device *dev, struct device_attribute *attr, +static ssize_t online_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { bool val; @@ -429,9 +427,7 @@ static ssize_t store_online(struct device *dev, struct device_attribute *attr, unlock_device_hotplug(); return ret < 0 ? ret : count; } - -static struct device_attribute online_attr = - __ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online); +static DEVICE_ATTR_RW(online); static int device_add_attributes(struct device *dev, struct device_attribute *attrs) @@ -531,7 +527,7 @@ static int device_add_attrs(struct device *dev) goto err_remove_type_groups; if (device_supports_offline(dev) && !dev->offline_disabled) { - error = device_create_file(dev, &online_attr); + error = device_create_file(dev, &dev_attr_online); if (error) goto err_remove_type_groups; } @@ -559,7 +555,7 @@ static void device_remove_attrs(struct device *dev) struct class *class = dev->class; const struct device_type *type = dev->type; - device_remove_file(dev, &online_attr); + device_remove_file(dev, &dev_attr_online); device_remove_groups(dev, dev->groups); if (type) @@ -572,15 +568,12 @@ static void device_remove_attrs(struct device *dev) } } - -static ssize_t show_dev(struct device *dev, struct device_attribute *attr, +static ssize_t dev_show(struct device *dev, struct device_attribute *attr, char *buf) { return print_dev_t(buf, dev->devt); } - -static struct device_attribute devt_attr = - __ATTR(dev, S_IRUGO, show_dev, NULL); +static DEVICE_ATTR_RO(dev); /* /sys/devices/ */ struct kset *devices_kset; @@ -1084,12 +1077,12 @@ int device_add(struct device *dev) if (platform_notify) platform_notify(dev); - error = device_create_file(dev, &uevent_attr); + error = device_create_file(dev, &dev_attr_uevent); if (error) goto attrError; if (MAJOR(dev->devt)) { - error = device_create_file(dev, &devt_attr); + error = device_create_file(dev, &dev_attr_dev); if (error) goto ueventattrError; @@ -1156,9 +1149,9 @@ done: device_remove_sys_dev_entry(dev); devtattrError: if (MAJOR(dev->devt)) - device_remove_file(dev, &devt_attr); + device_remove_file(dev, &dev_attr_dev); ueventattrError: - device_remove_file(dev, &uevent_attr); + device_remove_file(dev, &dev_attr_uevent); attrError: kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_del(&dev->kobj); @@ -1254,7 +1247,7 @@ void device_del(struct device *dev) if (MAJOR(dev->devt)) { devtmpfs_delete_node(dev); device_remove_sys_dev_entry(dev); - device_remove_file(dev, &devt_attr); + device_remove_file(dev, &dev_attr_dev); } if (dev->class) { device_remove_class_symlinks(dev); @@ -1269,7 +1262,7 @@ void device_del(struct device *dev) klist_del(&dev->knode_class); mutex_unlock(&dev->class->p->mutex); } - device_remove_file(dev, &uevent_attr); + device_remove_file(dev, &dev_attr_uevent); device_remove_attrs(dev); bus_remove_device(dev); device_pm_remove(dev); -- cgit v1.2.3-70-g09d2 From 14adbe5307a4110af7d1e95fb604a1abcdaa6cce Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 17:08:48 -0700 Subject: driver core: firmware: use __ATTR_RW() Use __ATTR_RW() instead of __ATTR() to make it more obvious what the type of attribute is being created. Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_class.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index a439602ea91..e4107d5f036 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -486,9 +486,8 @@ static struct notifier_block fw_shutdown_nb = { .notifier_call = fw_shutdown_notify, }; -static ssize_t firmware_timeout_show(struct class *class, - struct class_attribute *attr, - char *buf) +static ssize_t timeout_show(struct class *class, struct class_attribute *attr, + char *buf) { return sprintf(buf, "%d\n", loading_timeout); } @@ -506,9 +505,8 @@ static ssize_t firmware_timeout_show(struct class *class, * * Note: zero means 'wait forever'. **/ -static ssize_t firmware_timeout_store(struct class *class, - struct class_attribute *attr, - const char *buf, size_t count) +static ssize_t timeout_store(struct class *class, struct class_attribute *attr, + const char *buf, size_t count) { loading_timeout = simple_strtol(buf, NULL, 10); if (loading_timeout < 0) @@ -518,8 +516,7 @@ static ssize_t firmware_timeout_store(struct class *class, } static struct class_attribute firmware_class_attrs[] = { - __ATTR(timeout, S_IWUSR | S_IRUGO, - firmware_timeout_show, firmware_timeout_store), + __ATTR_RW(timeout), __ATTR_NULL }; -- cgit v1.2.3-70-g09d2 From 5e9e4911a5b3c6ae0fed6b3d23a9deff7825d86c Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 14:24:33 -0700 Subject: Input: gameport: convert bus code to use drv_groups The drv_attrs field of struct bus_type is going away soon, drv_groups should be used instead. This converts the gameport bus code to use the correct field. Acked: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/gameport/gameport.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c index da739d9d190..922a7fea2ce 100644 --- a/drivers/input/gameport/gameport.c +++ b/drivers/input/gameport/gameport.c @@ -639,16 +639,18 @@ EXPORT_SYMBOL(gameport_unregister_port); * Gameport driver operations */ -static ssize_t gameport_driver_show_description(struct device_driver *drv, char *buf) +static ssize_t description_show(struct device_driver *drv, char *buf) { struct gameport_driver *driver = to_gameport_driver(drv); return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)"); } +static DRIVER_ATTR_RO(description); -static struct driver_attribute gameport_driver_attrs[] = { - __ATTR(description, S_IRUGO, gameport_driver_show_description, NULL), - __ATTR_NULL +static struct attribute *gameport_driver_attrs[] = { + &driver_attr_description.attr, + NULL }; +ATTRIBUTE_GROUPS(gameport_driver); static int gameport_driver_probe(struct device *dev) { @@ -749,7 +751,7 @@ static int gameport_bus_match(struct device *dev, struct device_driver *drv) static struct bus_type gameport_bus = { .name = "gameport", .dev_attrs = gameport_device_attrs, - .drv_attrs = gameport_driver_attrs, + .drv_groups = gameport_driver_groups, .match = gameport_bus_match, .probe = gameport_driver_probe, .remove = gameport_driver_remove, -- cgit v1.2.3-70-g09d2 From 7048f5d027364b8567c71016a74891f81d682073 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 14:24:34 -0700 Subject: Input: serio: convert bus code to use drv_groups The drv_attrs field of struct bus_type is going away soon, drv_groups should be used instead. This converts the serio bus code to use the correct field. Acked-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/serio/serio.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c index 25fc5971f42..2b56855c2c7 100644 --- a/drivers/input/serio/serio.c +++ b/drivers/input/serio/serio.c @@ -732,19 +732,20 @@ EXPORT_SYMBOL(serio_unregister_child_port); * Serio driver operations */ -static ssize_t serio_driver_show_description(struct device_driver *drv, char *buf) +static ssize_t description_show(struct device_driver *drv, char *buf) { struct serio_driver *driver = to_serio_driver(drv); return sprintf(buf, "%s\n", driver->description ? driver->description : "(none)"); } +static DRIVER_ATTR_RO(description); -static ssize_t serio_driver_show_bind_mode(struct device_driver *drv, char *buf) +static ssize_t bind_mode_show(struct device_driver *drv, char *buf) { struct serio_driver *serio_drv = to_serio_driver(drv); return sprintf(buf, "%s\n", serio_drv->manual_bind ? "manual" : "auto"); } -static ssize_t serio_driver_set_bind_mode(struct device_driver *drv, const char *buf, size_t count) +static ssize_t bind_mode_store(struct device_driver *drv, const char *buf, size_t count) { struct serio_driver *serio_drv = to_serio_driver(drv); int retval; @@ -760,14 +761,14 @@ static ssize_t serio_driver_set_bind_mode(struct device_driver *drv, const char return retval; } +static DRIVER_ATTR_RW(bind_mode); - -static struct driver_attribute serio_driver_attrs[] = { - __ATTR(description, S_IRUGO, serio_driver_show_description, NULL), - __ATTR(bind_mode, S_IWUSR | S_IRUGO, - serio_driver_show_bind_mode, serio_driver_set_bind_mode), - __ATTR_NULL +static struct attribute *serio_driver_attrs[] = { + &driver_attr_description.attr, + &driver_attr_bind_mode.attr, + NULL, }; +ATTRIBUTE_GROUPS(serio_driver); static int serio_driver_probe(struct device *dev) { @@ -996,7 +997,7 @@ EXPORT_SYMBOL(serio_interrupt); static struct bus_type serio_bus = { .name = "serio", .dev_attrs = serio_device_attrs, - .drv_attrs = serio_driver_attrs, + .drv_groups = serio_driver_groups, .match = serio_bus_match, .uevent = serio_uevent, .probe = serio_driver_probe, -- cgit v1.2.3-70-g09d2 From 0d4260e04d6e6c25dd091b1605c1d05c37891387 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 14:24:38 -0700 Subject: HID: convert bus code to use dev_groups The dev_attrs field of struct bus_type is going away soon, dev_groups should be used instead. This converts the HID bus code to use the correct field. Acked-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 36668d1aca8..b8f1c77f2f7 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1917,11 +1917,13 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *a, return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; } +static DEVICE_ATTR_RO(modalias); -static struct device_attribute hid_dev_attrs[] = { - __ATTR_RO(modalias), - __ATTR_NULL, +static struct attribute *hid_dev_attrs[] = { + &dev_attr_modalias.attr, + NULL, }; +ATTRIBUTE_GROUPS(hid_dev); static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) { @@ -1949,7 +1951,7 @@ static int hid_uevent(struct device *dev, struct kobj_uevent_env *env) static struct bus_type hid_bus_type = { .name = "hid", - .dev_attrs = hid_dev_attrs, + .dev_groups = hid_dev_groups, .match = hid_bus_match, .probe = hid_device_probe, .remove = hid_device_remove, -- cgit v1.2.3-70-g09d2 From 63967685605b3c73c078807cd498c4fbf62847c1 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 27 Aug 2013 10:24:15 -0700 Subject: driver core: add #include to core files. This is needed to fix the build on sh systems. Reported-by: kbuild test robot Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 1 + drivers/base/core.c | 1 + drivers/base/driver.c | 1 + 3 files changed, 3 insertions(+) (limited to 'drivers') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 7fc2a13e84a..4c289ab9135 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" diff --git a/drivers/base/core.c b/drivers/base/core.c index 921b94184dc..c7b0925f627 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "base.h" #include "power/power.h" diff --git a/drivers/base/driver.c b/drivers/base/driver.c index c7efccb6f3b..9e29943e56c 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "base.h" static struct device *next_device(struct klist_iter *i) -- cgit v1.2.3-70-g09d2 From 4c33dea7816a115a9bbcd7d9001674c7c3ba71ea Mon Sep 17 00:00:00 2001 From: Greg KH Date: Tue, 20 Aug 2013 17:17:57 -0700 Subject: firmware: dcdbas: use binary attribute groups The dcdbas code was "hand rolling" a binary attribute group, which the driver core now supports automatically. So remove the "create the files by hand" logic, and just set the proper field in the attribute group structure, saving lots of code and headache. Cc: Doug Warzecha Signed-off-by: Greg Kroah-Hartman -- Doug, I can take this through my driver-core tree if you don't object. drivers/firmware/dcdbas.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) --- drivers/firmware/dcdbas.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'drivers') diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c index 8e77c02edb2..ff080ee2019 100644 --- a/drivers/firmware/dcdbas.c +++ b/drivers/firmware/dcdbas.c @@ -535,11 +535,12 @@ static struct attribute *dcdbas_dev_attrs[] = { static struct attribute_group dcdbas_attr_group = { .attrs = dcdbas_dev_attrs, + .bin_attrs = dcdbas_bin_attrs, }; static int dcdbas_probe(struct platform_device *dev) { - int i, error; + int error; host_control_action = HC_ACTION_NONE; host_control_smi_type = HC_SMITYPE_NONE; @@ -555,18 +556,6 @@ static int dcdbas_probe(struct platform_device *dev) if (error) return error; - for (i = 0; dcdbas_bin_attrs[i]; i++) { - error = sysfs_create_bin_file(&dev->dev.kobj, - dcdbas_bin_attrs[i]); - if (error) { - while (--i >= 0) - sysfs_remove_bin_file(&dev->dev.kobj, - dcdbas_bin_attrs[i]); - sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group); - return error; - } - } - register_reboot_notifier(&dcdbas_reboot_nb); dev_info(&dev->dev, "%s (version %s)\n", @@ -577,11 +566,7 @@ static int dcdbas_probe(struct platform_device *dev) static int dcdbas_remove(struct platform_device *dev) { - int i; - unregister_reboot_notifier(&dcdbas_reboot_nb); - for (i = 0; dcdbas_bin_attrs[i]; i++) - sysfs_remove_bin_file(&dev->dev.kobj, dcdbas_bin_attrs[i]); sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group); return 0; -- cgit v1.2.3-70-g09d2 From b15a21dddad552f7e42ae8a7da84de334f6acdcf Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 23 Aug 2013 14:24:28 -0700 Subject: rbd: convert bus code to use bus_groups The bus_attrs field of struct bus_type is going away soon, dev_groups should be used instead. This converts the RBD bus code to use the correct field. Cc: Yehuda Sadeh Cc: Sage Weil Acked-by: Alex Elder Cc: Signed-off-by: Greg Kroah-Hartman --- drivers/block/rbd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 4ad2ad9a5bb..191cd177fef 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -397,15 +397,19 @@ static ssize_t rbd_remove(struct bus_type *bus, const char *buf, static int rbd_dev_image_probe(struct rbd_device *rbd_dev, bool mapping); static void rbd_spec_put(struct rbd_spec *spec); -static struct bus_attribute rbd_bus_attrs[] = { - __ATTR(add, S_IWUSR, NULL, rbd_add), - __ATTR(remove, S_IWUSR, NULL, rbd_remove), - __ATTR_NULL +static BUS_ATTR(add, S_IWUSR, NULL, rbd_add); +static BUS_ATTR(remove, S_IWUSR, NULL, rbd_remove); + +static struct attribute *rbd_bus_attrs[] = { + &bus_attr_add.attr, + &bus_attr_remove.attr, + NULL, }; +ATTRIBUTE_GROUPS(rbd_bus); static struct bus_type rbd_bus_type = { .name = "rbd", - .bus_attrs = rbd_bus_attrs, + .bus_groups = rbd_bus_groups, }; static void rbd_root_dev_release(struct device *dev) -- cgit v1.2.3-70-g09d2 From 7315f0ccfc283ae998ca4d8102de83bba21936fa Mon Sep 17 00:00:00 2001 From: Gu Zheng Date: Wed, 28 Aug 2013 14:38:27 +0800 Subject: drivers/base/memory.c: introduce help macro to_memory_block Introduce help macro to_memory_block to hide the conversion(device-->memory_block), just clean up. Reviewed-by: Yasuaki Ishimatsu Signed-off-by: Gu Zheng Signed-off-by: Greg Kroah-Hartman --- drivers/base/memory.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'drivers') diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 2a38cd2da2e..69e09a1b62a 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c @@ -29,6 +29,8 @@ static DEFINE_MUTEX(mem_sysfs_mutex); #define MEMORY_CLASS_NAME "memory" +#define to_memory_block(dev) container_of(dev, struct memory_block, dev) + static int sections_per_block; static inline int base_memory_block_id(int section_nr) @@ -76,7 +78,7 @@ EXPORT_SYMBOL(unregister_memory_isolate_notifier); static void memory_block_release(struct device *dev) { - struct memory_block *mem = container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); kfree(mem); } @@ -109,8 +111,7 @@ static unsigned long get_memory_block_size(void) static ssize_t show_mem_start_phys_index(struct device *dev, struct device_attribute *attr, char *buf) { - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); unsigned long phys_index; phys_index = mem->start_section_nr / sections_per_block; @@ -120,8 +121,7 @@ static ssize_t show_mem_start_phys_index(struct device *dev, static ssize_t show_mem_end_phys_index(struct device *dev, struct device_attribute *attr, char *buf) { - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); unsigned long phys_index; phys_index = mem->end_section_nr / sections_per_block; @@ -136,8 +136,7 @@ static ssize_t show_mem_removable(struct device *dev, { unsigned long i, pfn; int ret = 1; - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); for (i = 0; i < sections_per_block; i++) { pfn = section_nr_to_pfn(mem->start_section_nr + i); @@ -153,8 +152,7 @@ static ssize_t show_mem_removable(struct device *dev, static ssize_t show_mem_state(struct device *dev, struct device_attribute *attr, char *buf) { - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); ssize_t len = 0; /* @@ -282,7 +280,7 @@ static int memory_block_change_state(struct memory_block *mem, /* The device lock serializes operations on memory_subsys_[online|offline] */ static int memory_subsys_online(struct device *dev) { - struct memory_block *mem = container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); int ret; if (mem->state == MEM_ONLINE) @@ -306,7 +304,7 @@ static int memory_subsys_online(struct device *dev) static int memory_subsys_offline(struct device *dev) { - struct memory_block *mem = container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); if (mem->state == MEM_OFFLINE) return 0; @@ -318,11 +316,9 @@ static ssize_t store_mem_state(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct memory_block *mem; + struct memory_block *mem = to_memory_block(dev); int ret, online_type; - mem = container_of(dev, struct memory_block, dev); - lock_device_hotplug(); if (!strncmp(buf, "online_kernel", min_t(int, count, 13))) @@ -376,8 +372,7 @@ store_mem_state(struct device *dev, static ssize_t show_phys_device(struct device *dev, struct device_attribute *attr, char *buf) { - struct memory_block *mem = - container_of(dev, struct memory_block, dev); + struct memory_block *mem = to_memory_block(dev); return sprintf(buf, "%d\n", mem->phys_device); } @@ -509,7 +504,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section, put_device(&hint->dev); if (!dev) return NULL; - return container_of(dev, struct memory_block, dev); + return to_memory_block(dev); } /* -- cgit v1.2.3-70-g09d2 From 1eeeef153c02f5856ec109fa532eb5f31c39f85c Mon Sep 17 00:00:00 2001 From: Maxime Bizon Date: Thu, 29 Aug 2013 20:28:13 +0200 Subject: firmware loader: fix pending_fw_head list corruption Got the following oops just before reboot: Unable to handle kernel NULL pointer dereference at virtual address 00000000 [<8028d300>] (__list_del_entry+0x44/0xac) [<802e3320>] (__fw_load_abort.part.13+0x1c/0x50) [<802e337c>] (fw_shutdown_notify+0x28/0x50) [<80034f80>] (notifier_call_chain.isra.1+0x5c/0x9c) [<800350ec>] (__blocking_notifier_call_chain+0x44/0x58) [<80035114>] (blocking_notifier_call_chain+0x14/0x18) [<80035d64>] (kernel_restart_prepare+0x14/0x38) [<80035d94>] (kernel_restart+0xc/0x50) The following race condition triggers here: _request_firmware_load() device_create_file(...) kobject_uevent(...) (schedule) (resume) firmware_loading_store(1) firmware_loading_store(0) list_del_init(&buf->pending_list) (schedule) (resume) list_add(&buf->pending_list, &pending_fw_head); wait_for_completion(&buf->completion); causing an oops later when walking pending_list after the firmware has been released. The proposed fix is to move the list_add() before sysfs attribute creation. Signed-off-by: Maxime Bizon Acked-by: Ming Lei Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/base/firmware_class.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index e4107d5f036..10a4467c63f 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -865,8 +865,15 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, goto err_del_dev; } + mutex_lock(&fw_lock); + list_add(&buf->pending_list, &pending_fw_head); + mutex_unlock(&fw_lock); + retval = device_create_file(f_dev, &dev_attr_loading); if (retval) { + mutex_lock(&fw_lock); + list_del_init(&buf->pending_list); + mutex_unlock(&fw_lock); dev_err(f_dev, "%s: device_create_file failed\n", __func__); goto err_del_bin_attr; } @@ -881,10 +888,6 @@ static int _request_firmware_load(struct firmware_priv *fw_priv, bool uevent, kobject_uevent(&fw_priv->dev.kobj, KOBJ_ADD); } - mutex_lock(&fw_lock); - list_add(&buf->pending_list, &pending_fw_head); - mutex_unlock(&fw_lock); - wait_for_completion(&buf->completion); cancel_delayed_work_sync(&fw_priv->timeout_work); -- cgit v1.2.3-70-g09d2