linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver
@ 2010-11-12 18:18 Stefan Achatz
  2010-11-13  0:21 ` Eric Biederman
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Achatz @ 2010-11-12 18:18 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Eric W. Biederman, Serge E. Hallyn,
	Tejun Heo, Jiri Kosina, linux-input, linux-kernel,
	Dmitry Torokhov, Benjamin Thery

hid-roccat-kone now uses new group functions for creating binary
sysfs attributes.

Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net>
---
 drivers/hid/hid-roccat-kone.c |   53 ++++++++++++----------------------------
 1 files changed, 16 insertions(+), 37 deletions(-)

diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c
index f776957..43f1693 100644
--- a/drivers/hid/hid-roccat-kone.c
+++ b/drivers/hid/hid-roccat-kone.c
@@ -710,6 +710,20 @@ static struct bin_attribute kone_profile5_attr = {
 	.write = kone_sysfs_write_profile5
 };
 
+static struct attribute *kone_bin_attributes[] = {
+	&kone_settings_attr.attr,
+	&kone_profile1_attr.attr,
+	&kone_profile2_attr.attr,
+	&kone_profile3_attr.attr,
+	&kone_profile4_attr.attr,
+	&kone_profile5_attr.attr,
+	NULL
+};
+
+static struct attribute_group kone_bin_attribute_group = {
+	.attrs = kone_bin_attributes
+};
+
 static int kone_create_sysfs_attributes(struct usb_interface *intf)
 {
 	int retval;
@@ -718,42 +732,12 @@ static int kone_create_sysfs_attributes(struct usb_interface *intf)
 	if (retval)
 		goto exit_1;
 
-	retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_settings_attr);
+	retval = sysfs_create_bin_group(&intf->dev.kobj, &kone_bin_attribute_group);
 	if (retval)
 		goto exit_2;
 
-	retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile1_attr);
-	if (retval)
-		goto exit_3;
-
-	retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile2_attr);
-	if (retval)
-		goto exit_4;
-
-	retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile3_attr);
-	if (retval)
-		goto exit_5;
-
-	retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile4_attr);
-	if (retval)
-		goto exit_6;
-
-	retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile5_attr);
-	if (retval)
-		goto exit_7;
-
 	return 0;
 
-exit_7:
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
-exit_6:
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
-exit_5:
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
-exit_4:
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
-exit_3:
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
 exit_2:
 	sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
 exit_1:
@@ -762,12 +746,7 @@ exit_1:
 
 static void kone_remove_sysfs_attributes(struct usb_interface *intf)
 {
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile5_attr);
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
-	sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
+	sysfs_remove_group(&intf->dev.kobj, &kone_bin_attribute_group);
 	sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
 }
 
-- 
1.7.2.3




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

* Re: [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver
  2010-11-12 18:18 [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver Stefan Achatz
@ 2010-11-13  0:21 ` Eric Biederman
  2010-11-13  0:52   ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Biederman @ 2010-11-13  0:21 UTC (permalink / raw)
  To: Stefan Achatz
  Cc: Greg Kroah-Hartman, Serge E. Hallyn, Tejun Heo, Jiri Kosina,
	linux-input, linux-kernel, Dmitry Torokhov, Benjamin Thery

On Fri, Nov 12, 2010 at 10:18 AM, Stefan Achatz <stefan_achatz@web.de> wrote:
> hid-roccat-kone now uses new group functions for creating binary
> sysfs attributes.

Looking at this, I have a problem with the way this works.
You are still doing this the hard and racy way.

sysfs attributes that are only added when we initialize the hardware and
are only removed when we remove the driver should use the device layer
functions to create their attributes.

This achieves two things.  The code is easier to write because there
is less of it.
The notification to user space happens after the attributes appear so
that you don't
have strange hotplug races.

If there a chance you can look at implementing this in the simpler
race free way?

Eric


>
> Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net>
> ---
>  drivers/hid/hid-roccat-kone.c |   53 ++++++++++++----------------------------
>  1 files changed, 16 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c
> index f776957..43f1693 100644
> --- a/drivers/hid/hid-roccat-kone.c
> +++ b/drivers/hid/hid-roccat-kone.c
> @@ -710,6 +710,20 @@ static struct bin_attribute kone_profile5_attr = {
>        .write = kone_sysfs_write_profile5
>  };
>
> +static struct attribute *kone_bin_attributes[] = {
> +       &kone_settings_attr.attr,
> +       &kone_profile1_attr.attr,
> +       &kone_profile2_attr.attr,
> +       &kone_profile3_attr.attr,
> +       &kone_profile4_attr.attr,
> +       &kone_profile5_attr.attr,
> +       NULL
> +};
> +
> +static struct attribute_group kone_bin_attribute_group = {
> +       .attrs = kone_bin_attributes
> +};
> +
>  static int kone_create_sysfs_attributes(struct usb_interface *intf)
>  {
>        int retval;
> @@ -718,42 +732,12 @@ static int kone_create_sysfs_attributes(struct usb_interface *intf)
>        if (retval)
>                goto exit_1;
>
> -       retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_settings_attr);
> +       retval = sysfs_create_bin_group(&intf->dev.kobj, &kone_bin_attribute_group);
>        if (retval)
>                goto exit_2;
>
> -       retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile1_attr);
> -       if (retval)
> -               goto exit_3;
> -
> -       retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile2_attr);
> -       if (retval)
> -               goto exit_4;
> -
> -       retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile3_attr);
> -       if (retval)
> -               goto exit_5;
> -
> -       retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile4_attr);
> -       if (retval)
> -               goto exit_6;
> -
> -       retval = sysfs_create_bin_file(&intf->dev.kobj, &kone_profile5_attr);
> -       if (retval)
> -               goto exit_7;
> -
>        return 0;
>
> -exit_7:
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
> -exit_6:
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
> -exit_5:
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
> -exit_4:
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
> -exit_3:
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
>  exit_2:
>        sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
>  exit_1:
> @@ -762,12 +746,7 @@ exit_1:
>
>  static void kone_remove_sysfs_attributes(struct usb_interface *intf)
>  {
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile5_attr);
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile4_attr);
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile3_attr);
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile2_attr);
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_profile1_attr);
> -       sysfs_remove_bin_file(&intf->dev.kobj, &kone_settings_attr);
> +       sysfs_remove_group(&intf->dev.kobj, &kone_bin_attribute_group);
>        sysfs_remove_group(&intf->dev.kobj, &kone_attribute_group);
>  }
>
> --
> 1.7.2.3
>
>
>
>

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

* Re: [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver
  2010-11-13  0:21 ` Eric Biederman
@ 2010-11-13  0:52   ` Greg KH
  2010-11-13  6:06     ` Dmitry Torokhov
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2010-11-13  0:52 UTC (permalink / raw)
  To: Eric Biederman
  Cc: Stefan Achatz, Serge E. Hallyn, Tejun Heo, Jiri Kosina,
	linux-input, linux-kernel, Dmitry Torokhov, Benjamin Thery

On Fri, Nov 12, 2010 at 04:21:45PM -0800, Eric Biederman wrote:
> On Fri, Nov 12, 2010 at 10:18 AM, Stefan Achatz <stefan_achatz@web.de> wrote:
> > hid-roccat-kone now uses new group functions for creating binary
> > sysfs attributes.
> 
> Looking at this, I have a problem with the way this works.
> You are still doing this the hard and racy way.
> 
> sysfs attributes that are only added when we initialize the hardware and
> are only removed when we remove the driver should use the device layer
> functions to create their attributes.
> 
> This achieves two things.  The code is easier to write because there
> is less of it.
> The notification to user space happens after the attributes appear so
> that you don't
> have strange hotplug races.
> 
> If there a chance you can look at implementing this in the simpler
> race free way?

Good point, just attach this attribute group to the device and the
driver core will automatically create the files for you.

thanks,

greg k-h

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

* Re: [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver
  2010-11-13  0:52   ` Greg KH
@ 2010-11-13  6:06     ` Dmitry Torokhov
  2010-11-13 14:39       ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitry Torokhov @ 2010-11-13  6:06 UTC (permalink / raw)
  To: Greg KH
  Cc: Eric Biederman, Stefan Achatz, Serge E. Hallyn, Tejun Heo,
	Jiri Kosina, linux-input, linux-kernel, Benjamin Thery

On Fri, Nov 12, 2010 at 04:52:32PM -0800, Greg KH wrote:
> On Fri, Nov 12, 2010 at 04:21:45PM -0800, Eric Biederman wrote:
> > On Fri, Nov 12, 2010 at 10:18 AM, Stefan Achatz <stefan_achatz@web.de> wrote:
> > > hid-roccat-kone now uses new group functions for creating binary
> > > sysfs attributes.
> > 
> > Looking at this, I have a problem with the way this works.
> > You are still doing this the hard and racy way.
> > 
> > sysfs attributes that are only added when we initialize the hardware and
> > are only removed when we remove the driver should use the device layer
> > functions to create their attributes.
> > 
> > This achieves two things.  The code is easier to write because there
> > is less of it.
> > The notification to user space happens after the attributes appear so
> > that you don't
> > have strange hotplug races.
> > 
> > If there a chance you can look at implementing this in the simpler
> > race free way?
> 
> Good point, just attach this attribute group to the device and the
> driver core will automatically create the files for you.
> 

Attribute group in device structure is normally owned and managed by
subsystem core; without additional plumbing drivers should not be
touching it, at least not normally.

Plus we do not have binary attribute group in device structure [yet].

-- 
Dmitry

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

* Re: [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver
  2010-11-13  6:06     ` Dmitry Torokhov
@ 2010-11-13 14:39       ` Greg KH
  2010-11-13 16:34         ` Stefan Achatz
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2010-11-13 14:39 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Eric Biederman, Stefan Achatz, Serge E. Hallyn, Tejun Heo,
	Jiri Kosina, linux-input, linux-kernel, Benjamin Thery

On Fri, Nov 12, 2010 at 10:06:34PM -0800, Dmitry Torokhov wrote:
> On Fri, Nov 12, 2010 at 04:52:32PM -0800, Greg KH wrote:
> > On Fri, Nov 12, 2010 at 04:21:45PM -0800, Eric Biederman wrote:
> > > On Fri, Nov 12, 2010 at 10:18 AM, Stefan Achatz <stefan_achatz@web.de> wrote:
> > > > hid-roccat-kone now uses new group functions for creating binary
> > > > sysfs attributes.
> > > 
> > > Looking at this, I have a problem with the way this works.
> > > You are still doing this the hard and racy way.
> > > 
> > > sysfs attributes that are only added when we initialize the hardware and
> > > are only removed when we remove the driver should use the device layer
> > > functions to create their attributes.
> > > 
> > > This achieves two things.  The code is easier to write because there
> > > is less of it.
> > > The notification to user space happens after the attributes appear so
> > > that you don't
> > > have strange hotplug races.
> > > 
> > > If there a chance you can look at implementing this in the simpler
> > > race free way?
> > 
> > Good point, just attach this attribute group to the device and the
> > driver core will automatically create the files for you.
> > 
> 
> Attribute group in device structure is normally owned and managed by
> subsystem core; without additional plumbing drivers should not be
> touching it, at least not normally.
> 
> Plus we do not have binary attribute group in device structure [yet].

In thinking about it a bit more, why do you have so many binary
attributes for this driver?  binary sysfs files are rare, so adding a
binary attribute group pointer to the device or driver would just waste
a lot of space that no one else uses.

What are these binary files for?  Who uses them?  I don't seem to be
able to find them in the Documentation/ABI directory, or am I missing
something here?

thanks,

greg k-h

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

* Re: [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver
  2010-11-13 14:39       ` Greg KH
@ 2010-11-13 16:34         ` Stefan Achatz
  2010-11-14  0:03           ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Achatz @ 2010-11-13 16:34 UTC (permalink / raw)
  To: Greg KH
  Cc: Dmitry Torokhov, Eric Biederman, Serge E. Hallyn, Tejun Heo,
	Jiri Kosina, linux-input, linux-kernel, Benjamin Thery

Am Samstag, den 13.11.2010, 06:39 -0800 schrieb Greg KH:
> On Fri, Nov 12, 2010 at 10:06:34PM -0800, Dmitry Torokhov wrote:
> > On Fri, Nov 12, 2010 at 04:52:32PM -0800, Greg KH wrote:
> > > On Fri, Nov 12, 2010 at 04:21:45PM -0800, Eric Biederman wrote:
> > > > On Fri, Nov 12, 2010 at 10:18 AM, Stefan Achatz <stefan_achatz@web.de> wrote:
> > > > > hid-roccat-kone now uses new group functions for creating binary
> > > > > sysfs attributes.
> > > > 
> > > > Looking at this, I have a problem with the way this works.
> > > > You are still doing this the hard and racy way.
> > > > 
> > > > sysfs attributes that are only added when we initialize the hardware and
> > > > are only removed when we remove the driver should use the device layer
> > > > functions to create their attributes.
> > > > 
> > > > This achieves two things.  The code is easier to write because there
> > > > is less of it.
> > > > The notification to user space happens after the attributes appear so
> > > > that you don't
> > > > have strange hotplug races.
> > > > 
> > > > If there a chance you can look at implementing this in the simpler
> > > > race free way?
> > > 
> > > Good point, just attach this attribute group to the device and the
> > > driver core will automatically create the files for you.
> > > 
> > 
> > Attribute group in device structure is normally owned and managed by
> > subsystem core; without additional plumbing drivers should not be
> > touching it, at least not normally.
> > 
> > Plus we do not have binary attribute group in device structure [yet].
> 
> In thinking about it a bit more, why do you have so many binary
> attributes for this driver?  binary sysfs files are rare, so adding a
> binary attribute group pointer to the device or driver would just waste
> a lot of space that no one else uses.
> 
> What are these binary files for?  Who uses them?  I don't seem to be
> able to find them in the Documentation/ABI directory, or am I missing
> something here?

Documentation/ABI/testing/sysfs-driver-hid-roccat-kone

Stefan


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

* Re: [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver
  2010-11-13 16:34         ` Stefan Achatz
@ 2010-11-14  0:03           ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2010-11-14  0:03 UTC (permalink / raw)
  To: Stefan Achatz
  Cc: Dmitry Torokhov, Eric Biederman, Serge E. Hallyn, Tejun Heo,
	Jiri Kosina, linux-input, linux-kernel, Benjamin Thery

On Sat, Nov 13, 2010 at 05:34:15PM +0100, Stefan Achatz wrote:
> Am Samstag, den 13.11.2010, 06:39 -0800 schrieb Greg KH:
> > On Fri, Nov 12, 2010 at 10:06:34PM -0800, Dmitry Torokhov wrote:
> > > On Fri, Nov 12, 2010 at 04:52:32PM -0800, Greg KH wrote:
> > > > On Fri, Nov 12, 2010 at 04:21:45PM -0800, Eric Biederman wrote:
> > > > > On Fri, Nov 12, 2010 at 10:18 AM, Stefan Achatz <stefan_achatz@web.de> wrote:
> > > > > > hid-roccat-kone now uses new group functions for creating binary
> > > > > > sysfs attributes.
> > > > > 
> > > > > Looking at this, I have a problem with the way this works.
> > > > > You are still doing this the hard and racy way.
> > > > > 
> > > > > sysfs attributes that are only added when we initialize the hardware and
> > > > > are only removed when we remove the driver should use the device layer
> > > > > functions to create their attributes.
> > > > > 
> > > > > This achieves two things.  The code is easier to write because there
> > > > > is less of it.
> > > > > The notification to user space happens after the attributes appear so
> > > > > that you don't
> > > > > have strange hotplug races.
> > > > > 
> > > > > If there a chance you can look at implementing this in the simpler
> > > > > race free way?
> > > > 
> > > > Good point, just attach this attribute group to the device and the
> > > > driver core will automatically create the files for you.
> > > > 
> > > 
> > > Attribute group in device structure is normally owned and managed by
> > > subsystem core; without additional plumbing drivers should not be
> > > touching it, at least not normally.
> > > 
> > > Plus we do not have binary attribute group in device structure [yet].
> > 
> > In thinking about it a bit more, why do you have so many binary
> > attributes for this driver?  binary sysfs files are rare, so adding a
> > binary attribute group pointer to the device or driver would just waste
> > a lot of space that no one else uses.
> > 
> > What are these binary files for?  Who uses them?  I don't seem to be
> > able to find them in the Documentation/ABI directory, or am I missing
> > something here?
> 
> Documentation/ABI/testing/sysfs-driver-hid-roccat-kone

My apologies, that does look correct, thanks for doing it.

Yeah, odds are udev wants to see these files when the device shows up so
we need a way to get them created before the device event is sent out to
userspace.  So we need to get them assigned to the device or driver
somehow like the default attribute groups we have today.  Any ideas are
appreciated.

thanks,

greg k-h

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

end of thread, other threads:[~2010-11-14  0:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-12 18:18 [PATCH 2/2] HID: roccat: using new sysfs_create_bin_group() in kone driver Stefan Achatz
2010-11-13  0:21 ` Eric Biederman
2010-11-13  0:52   ` Greg KH
2010-11-13  6:06     ` Dmitry Torokhov
2010-11-13 14:39       ` Greg KH
2010-11-13 16:34         ` Stefan Achatz
2010-11-14  0:03           ` 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).