Commit fb60367d authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: register sysfs device attributes with driver core

Currently the sysfs device attributes are created by the comedi
core after each comedi device is created. This can lead to a race
condition where userspace gets an add event before the files are
created.

Register the device attributes with the comedi class so that the
driver core handles creating them and we avoid the race.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d3b48769
...@@ -227,9 +227,6 @@ static ssize_t store_max_read_buffer_kb(struct device *dev, ...@@ -227,9 +227,6 @@ static ssize_t store_max_read_buffer_kb(struct device *dev,
return count; return count;
} }
static DEVICE_ATTR(max_read_buffer_kb, S_IRUGO | S_IWUSR,
show_max_read_buffer_kb, store_max_read_buffer_kb);
static ssize_t show_read_buffer_kb(struct device *dev, static ssize_t show_read_buffer_kb(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
...@@ -287,9 +284,6 @@ static ssize_t store_read_buffer_kb(struct device *dev, ...@@ -287,9 +284,6 @@ static ssize_t store_read_buffer_kb(struct device *dev,
return count; return count;
} }
static DEVICE_ATTR(read_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP,
show_read_buffer_kb, store_read_buffer_kb);
static ssize_t show_max_write_buffer_kb(struct device *dev, static ssize_t show_max_write_buffer_kb(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
char *buf) char *buf)
...@@ -344,9 +338,6 @@ static ssize_t store_max_write_buffer_kb(struct device *dev, ...@@ -344,9 +338,6 @@ static ssize_t store_max_write_buffer_kb(struct device *dev,
return count; return count;
} }
static DEVICE_ATTR(max_write_buffer_kb, S_IRUGO | S_IWUSR,
show_max_write_buffer_kb, store_max_write_buffer_kb);
static ssize_t show_write_buffer_kb(struct device *dev, static ssize_t show_write_buffer_kb(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
...@@ -404,19 +395,16 @@ static ssize_t store_write_buffer_kb(struct device *dev, ...@@ -404,19 +395,16 @@ static ssize_t store_write_buffer_kb(struct device *dev,
return count; return count;
} }
static DEVICE_ATTR(write_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP, static struct device_attribute comedi_dev_attrs[] = {
show_write_buffer_kb, store_write_buffer_kb); __ATTR(max_read_buffer_kb, S_IRUGO | S_IWUSR,
show_max_read_buffer_kb, store_max_read_buffer_kb),
static struct attribute *comedi_attrs[] = { __ATTR(read_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP,
&dev_attr_max_read_buffer_kb.attr, show_read_buffer_kb, store_read_buffer_kb),
&dev_attr_read_buffer_kb.attr, __ATTR(max_write_buffer_kb, S_IRUGO | S_IWUSR,
&dev_attr_max_write_buffer_kb.attr, show_max_write_buffer_kb, store_max_write_buffer_kb),
&dev_attr_write_buffer_kb.attr, __ATTR(write_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP,
NULL show_write_buffer_kb, store_write_buffer_kb),
}; __ATTR_NULL
static const struct attribute_group comedi_sysfs_files = {
.attrs = comedi_attrs,
}; };
static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd, static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
...@@ -2355,6 +2343,8 @@ static int __init comedi_init(void) ...@@ -2355,6 +2343,8 @@ static int __init comedi_init(void)
return PTR_ERR(comedi_class); return PTR_ERR(comedi_class);
} }
comedi_class->dev_attrs = comedi_dev_attrs;
/* XXX requires /proc interface */ /* XXX requires /proc interface */
comedi_proc_init(); comedi_proc_init();
...@@ -2496,7 +2486,6 @@ int comedi_alloc_board_minor(struct device *hardware_device) ...@@ -2496,7 +2486,6 @@ int comedi_alloc_board_minor(struct device *hardware_device)
struct comedi_device_file_info *info; struct comedi_device_file_info *info;
struct device *csdev; struct device *csdev;
unsigned i; unsigned i;
int retval;
info = kzalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL); info = kzalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL);
if (info == NULL) if (info == NULL)
...@@ -2532,14 +2521,6 @@ int comedi_alloc_board_minor(struct device *hardware_device) ...@@ -2532,14 +2521,6 @@ int comedi_alloc_board_minor(struct device *hardware_device)
info->device->class_dev = csdev; info->device->class_dev = csdev;
dev_set_drvdata(csdev, info); dev_set_drvdata(csdev, info);
retval = sysfs_create_group(&csdev->kobj, &comedi_sysfs_files);
if (retval) {
printk(KERN_ERR
"comedi: failed to create sysfs attribute files\n");
comedi_free_board_minor(i);
return retval;
}
return i; return i;
} }
...@@ -2590,7 +2571,6 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev, ...@@ -2590,7 +2571,6 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
struct comedi_device_file_info *info; struct comedi_device_file_info *info;
struct device *csdev; struct device *csdev;
unsigned i; unsigned i;
int retval;
info = kmalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL); info = kmalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL);
if (info == NULL) if (info == NULL)
...@@ -2621,14 +2601,6 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev, ...@@ -2621,14 +2601,6 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
s->class_dev = csdev; s->class_dev = csdev;
dev_set_drvdata(csdev, info); dev_set_drvdata(csdev, info);
retval = sysfs_create_group(&csdev->kobj, &comedi_sysfs_files);
if (retval) {
printk(KERN_ERR
"comedi: failed to create sysfs attribute files\n");
comedi_free_subdevice_minor(s);
return retval;
}
return i; return i;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment