linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: comedi: register sysfs device attributes with driver core
@ 2012-05-11  1:05 H Hartley Sweeten
  2012-05-11  6:16 ` Dan Carpenter
  2012-05-14 20:00 ` Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: H Hartley Sweeten @ 2012-05-11  1:05 UTC (permalink / raw)
  To: Linux Kernel; +Cc: devel, abbotti, fmhess, gregkh

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: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---

diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 44ca1fe..7677657 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -227,9 +227,6 @@ static ssize_t store_max_read_buffer_kb(struct device *dev,
 	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,
 				   struct device_attribute *attr, char *buf)
 {
@@ -287,9 +284,6 @@ static ssize_t store_read_buffer_kb(struct device *dev,
 	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,
 					struct device_attribute *attr,
 					char *buf)
@@ -344,9 +338,6 @@ static ssize_t store_max_write_buffer_kb(struct device *dev,
 	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,
 				    struct device_attribute *attr, char *buf)
 {
@@ -404,19 +395,16 @@ static ssize_t store_write_buffer_kb(struct device *dev,
 	return count;
 }
 
-static DEVICE_ATTR(write_buffer_kb, S_IRUGO | S_IWUSR | S_IWGRP,
-		show_write_buffer_kb, store_write_buffer_kb);
-
-static struct attribute *comedi_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
-};
-
-static const struct attribute_group comedi_sysfs_files = {
-	.attrs	= comedi_attrs,
+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 long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
@@ -2355,6 +2343,8 @@ static int __init comedi_init(void)
 		return PTR_ERR(comedi_class);
 	}
 
+	comedi_class->dev_attrs = comedi_dev_attrs;
+
 	/* XXX requires /proc interface */
 	comedi_proc_init();
 
@@ -2496,7 +2486,6 @@ int comedi_alloc_board_minor(struct device *hardware_device)
 	struct comedi_device_file_info *info;
 	struct device *csdev;
 	unsigned i;
-	int retval;
 
 	info = kzalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL);
 	if (info == NULL)
@@ -2532,14 +2521,6 @@ int comedi_alloc_board_minor(struct device *hardware_device)
 		info->device->class_dev = csdev;
 	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;
 }
 
@@ -2590,7 +2571,6 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
 	struct comedi_device_file_info *info;
 	struct device *csdev;
 	unsigned i;
-	int retval;
 
 	info = kmalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL);
 	if (info == NULL)
@@ -2621,14 +2601,6 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
 		s->class_dev = csdev;
 	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;
 }
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] staging: comedi: register sysfs device attributes with driver core
  2012-05-11  1:05 [PATCH] staging: comedi: register sysfs device attributes with driver core H Hartley Sweeten
@ 2012-05-11  6:16 ` Dan Carpenter
  2012-05-11 13:14   ` Ian Abbott
  2012-05-14 20:00 ` Greg KH
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2012-05-11  6:16 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, devel, fmhess, abbotti, gregkh

On Thu, May 10, 2012 at 06:05:28PM -0700, H Hartley Sweeten wrote:
> -static const struct attribute_group comedi_sysfs_files = {
> -	.attrs	= comedi_attrs,
> +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

Some of these are group writable and some are only user writable so
it's not consistent.  Probably just make them user writeable.

I guess this was in the original code too, but it's just more
obvious now that they're grouped together.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] staging: comedi: register sysfs device attributes with driver core
  2012-05-11  6:16 ` Dan Carpenter
@ 2012-05-11 13:14   ` Ian Abbott
  2012-05-11 18:18     ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Abbott @ 2012-05-11 13:14 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: H Hartley Sweeten, Linux Kernel, devel@driverdev.osuosl.org,
	fmhess@users.sourceforge.net, Ian Abbott,
	gregkh@linuxfoundation.org

On 2012-05-11 07:16, Dan Carpenter wrote:
> On Thu, May 10, 2012 at 06:05:28PM -0700, H Hartley Sweeten wrote:
>> -static const struct attribute_group comedi_sysfs_files = {
>> -	.attrs	= comedi_attrs,
>> +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
>
> Some of these are group writable and some are only user writable so
> it's not consistent.  Probably just make them user writeable.
>
> I guess this was in the original code too, but it's just more
> obvious now that they're grouped together.

Is it possible to change (group) ownership of these attribute files 
using udev rules?  Ideally, users in the group that has group ownership 
on the /dev/comedi* files should be able to modify the read_buffer_kb 
and write_buffer_kb attribute files as well, but only super-users should 
be able to modify the max_read_buffer_kb and max_write_buffer_kb files.

-- 
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@mev.co.uk>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] staging: comedi: register sysfs device attributes with driver core
  2012-05-11 13:14   ` Ian Abbott
@ 2012-05-11 18:18     ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2012-05-11 18:18 UTC (permalink / raw)
  To: Ian Abbott
  Cc: devel@driverdev.osuosl.org, fmhess@users.sourceforge.net,
	Ian Abbott, gregkh@linuxfoundation.org, Linux Kernel,
	H Hartley Sweeten

On Fri, May 11, 2012 at 02:14:02PM +0100, Ian Abbott wrote:
> On 2012-05-11 07:16, Dan Carpenter wrote:
> >On Thu, May 10, 2012 at 06:05:28PM -0700, H Hartley Sweeten wrote:
> >>-static const struct attribute_group comedi_sysfs_files = {
> >>-	.attrs	= comedi_attrs,
> >>+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
> >
> >Some of these are group writable and some are only user writable so
> >it's not consistent.  Probably just make them user writeable.
> >
> >I guess this was in the original code too, but it's just more
> >obvious now that they're grouped together.
> 
> Is it possible to change (group) ownership of these attribute files
> using udev rules?  Ideally, users in the group that has group
> ownership on the /dev/comedi* files should be able to modify the
> read_buffer_kb and write_buffer_kb attribute files as well, but only
> super-users should be able to modify the max_read_buffer_kb and
> max_write_buffer_kb files.
> 

Oh.  Ok that's fine then.  I didn't understand what was going on.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] staging: comedi: register sysfs device attributes with driver core
  2012-05-11  1:05 [PATCH] staging: comedi: register sysfs device attributes with driver core H Hartley Sweeten
  2012-05-11  6:16 ` Dan Carpenter
@ 2012-05-14 20:00 ` Greg KH
  1 sibling, 0 replies; 5+ messages in thread
From: Greg KH @ 2012-05-14 20:00 UTC (permalink / raw)
  To: H Hartley Sweeten; +Cc: Linux Kernel, devel, abbotti, fmhess

On Thu, May 10, 2012 at 06:05:28PM -0700, H Hartley Sweeten wrote:
> 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.

Nice job, thanks for making this change.

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-05-14 20:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-11  1:05 [PATCH] staging: comedi: register sysfs device attributes with driver core H Hartley Sweeten
2012-05-11  6:16 ` Dan Carpenter
2012-05-11 13:14   ` Ian Abbott
2012-05-11 18:18     ` Dan Carpenter
2012-05-14 20:00 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).