linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Greg KH <greg@kroah.com>
Cc: Janne Kanniainen <janne.kanniainen@gmail.com>,
	johan@kernel.org, bjorn@mork.no, jkosina@suse.cz,
	cooloney@gmail.com, linux-kernel@vger.kernel.org,
	linux-leds@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-input@vger.kernel.org
Subject: Re: [PATCH 2/2] HID: leds: move led_mode attribute to led-class devices in MSI GT683R driver
Date: Wed, 25 Jun 2014 13:55:41 +0200	[thread overview]
Message-ID: <20140625115541.GA1409@localhost> (raw)
In-Reply-To: <20140624195651.GA13694@kroah.com>

On Tue, Jun 24, 2014 at 03:56:51PM -0400, Greg KH wrote:
> On Tue, Jun 24, 2014 at 10:38:38PM +0300, Janne Kanniainen wrote:

> >  static int gt683r_led_probe(struct hid_device *hdev,
> >  			const struct hid_device_id *id)
> > @@ -261,6 +272,7 @@ static int gt683r_led_probe(struct hid_device *hdev,
> >  		led->led_devs[i].name = name;
> >  		led->led_devs[i].max_brightness = 1;
> >  		led->led_devs[i].brightness_set = gt683r_brightness_set;
> > +
> >  		ret = led_classdev_register(&hdev->dev, &led->led_devs[i]);
> >  		if (ret) {
> >  			hid_err(hdev, "could not register led device\n");
> > @@ -268,17 +280,29 @@ static int gt683r_led_probe(struct hid_device *hdev,
> >  		}
> >  	}
> >  
> > -	ret = device_create_file(&led->hdev->dev, &dev_attr_leds_mode);
> > -	if (ret) {
> > -		hid_err(hdev, "could not make mode attribute file\n");
> > -		goto fail;
> > +	for (i = 0; i < GT683R_LED_COUNT; i++) {
> > +		led->dev_attr_group[i] = &gt683r_group;
> > +
> > +		ret = sysfs_create_group(&led->led_devs[i].dev->kobj,
> > +					led->dev_attr_group[i]);
> 
> why not use sysfs_create_groups()?
> 
> And why are you doing it this way, the led device should have the
> attribute group and it should be created automatically by the driver
> core, no driver should need to create it like you are doing so here.

Turns out it was easier said than done when I asked Janne to move the
attribute. And all led drivers with custom attributes currently suffer
from this race.

Janne, you'll need to apply patch below and then set the groups field of
the led_devs before registering them. You can use the ATTRIBUTE_GROUPS
macro in the following way:

	static struct attribute *gt683r_led_attrs[] = {
       		&dev_attr_msi_mode.attr,
       		NULL,
	};
	ATTRIBUTE_GROUPS(gt683r_led);

and then set .groups to gt683r_led_groups.

I have started fixing some of the other led drivers and I'll try to
submit a series (including the below patch) later today.

Thanks,
Johan


>From 226f1de5e094f2ec99f45d486652505ef915af73 Mon Sep 17 00:00:00 2001
From: Johan Hovold <johan@kernel.org>
Date: Wed, 25 Jun 2014 12:33:18 +0200
Subject: [PATCH] leds: add led-class attribute-group support

Allow led-class devices to be created with optional attribute groups.

This is needed in order to allow led drivers to create custom device
attributes in a race-free manner.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/leds/led-class.c | 5 +++--
 include/linux/leds.h     | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index f37d63cf726b..aa29198fca3e 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -210,8 +210,9 @@ static const struct dev_pm_ops leds_class_dev_pm_ops = {
  */
 int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
 {
-	led_cdev->dev = device_create(leds_class, parent, 0, led_cdev,
-				      "%s", led_cdev->name);
+	led_cdev->dev = device_create_with_groups(leds_class, parent, 0,
+					led_cdev, led_cdev->groups,
+					"%s", led_cdev->name);
 	if (IS_ERR(led_cdev->dev))
 		return PTR_ERR(led_cdev->dev);
 
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 0287ab296689..e43686472197 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -63,6 +63,8 @@ struct led_classdev {
 				     unsigned long *delay_off);
 
 	struct device		*dev;
+	const struct attribute_group	**groups;
+
 	struct list_head	 node;			/* LED Device list */
 	const char		*default_trigger;	/* Trigger to use */
 
-- 
1.8.5.5

  reply	other threads:[~2014-06-25 11:55 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1402003746-6354-1-git-send-email-janne.kanniainen@gmail.com>
2014-06-06  9:47 ` [PATCH v2] leds: USB: Add support for MSI GT683R led panels Johan Hovold
2014-06-07 10:12   ` Janne Kanniainen
2014-06-09 11:42     ` Johan Hovold
2014-06-10 21:10       ` Janne Kanniainen
2014-06-10 21:21         ` [PATCH v3] leds: USB: HID: " Janne Kanniainen
2014-06-11 11:25           ` Jiri Kosina
2014-06-11 14:06             ` Johan Hovold
     [not found]           ` <1402435299-16410-1-git-send-email-janne.kanniainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-11 14:05             ` Johan Hovold
2014-06-11 15:30               ` Johan Hovold
2014-06-11 17:34               ` Johan Hovold
2014-06-11 22:48                 ` [PATCH v4] " Janne Kanniainen
2014-06-12  9:06                   ` Johan Hovold
2014-06-12 20:34                     ` [PATCH v5] " Janne Kanniainen
2014-06-13  7:54                       ` Johan Hovold
2014-06-13 17:19                         ` Janne Kanniainen
2014-06-15 14:59                           ` Janne Kanniainen
2014-06-16  7:39                             ` Johan Hovold
2014-06-16 17:23                         ` [PATCH v6] " Janne Kanniainen
2014-06-16 22:01                           ` Janne Kanniainen
2014-06-17 13:46                             ` Johan Hovold
2014-06-17 16:41                               ` [PATCH v8] " Janne Kanniainen
     [not found]                                 ` <1403023304-7953-1-git-send-email-janne.kanniainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-18  7:39                                   ` Johan Hovold
2014-06-18 16:05                                     ` [PATCH v9] " Janne Kanniainen
     [not found]                                       ` <1403107502-14106-1-git-send-email-janne.kanniainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-18 16:11                                         ` Johan Hovold
2014-06-18 18:41                                           ` Janne Kanniainen
2014-06-18 18:46                                             ` Johan Hovold
2014-06-18 22:10                                           ` Jiri Kosina
2014-06-23 14:35                                       ` Oliver Neukum
2014-06-23 14:42                                         ` Johan Hovold
2014-06-23 16:17                                           ` Greg KH
2014-06-23 17:16                                             ` [PATCH v10] " Janne Kanniainen
2014-06-23 17:27                                               ` Johan Hovold
     [not found]                                               ` <1403543808-8228-1-git-send-email-janne.kanniainen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-23 18:23                                                 ` Greg KH
2014-06-23 18:24                                                   ` Greg KH
2014-06-23 19:31                                                     ` Johan Hovold
2014-06-23 19:40                                                       ` Greg KH
2014-06-23 19:52                                                         ` Johan Hovold
2014-06-23 20:24                                                           ` Greg KH
2014-06-23 20:44                                                             ` Johan Hovold
2014-06-24 13:10                                                               ` Bjørn Mork
2014-06-24 14:50                                                                 ` Johan Hovold
2014-06-24 19:38                                                                   ` [PATCH 1/2] HID: leds: fix race condition in MSI GT683R driver Janne Kanniainen
2014-06-24 19:38                                                                     ` [PATCH 2/2] HID: leds: move led_mode attribute to led-class devices " Janne Kanniainen
2014-06-24 19:56                                                                       ` Greg KH
2014-06-25 11:55                                                                         ` Johan Hovold [this message]
2014-06-25 15:59                                                                           ` [PATCH 2/2 v2] HID: leds: Use attribute-groups " Janne Kanniainen
2014-06-25 17:41                                                                             ` Johan Hovold
2014-06-25 18:13                                                                               ` [PATCH 2/2 v3] HID: leds: move led_mode attribute to led-class devices " Janne Kanniainen
2014-06-30 10:39                                                                                 ` Johan Hovold
2014-07-01 17:50                                                                                   ` [PATCH 2/2 v4] " Janne Kanniainen
2014-07-01 20:16                                                                                     ` Johan Hovold
2014-07-02 17:37                                                                                       ` [PATCH 2/2 v5] " Janne Kanniainen
2014-07-03  8:28                                                                                         ` Johan Hovold
2014-07-03 17:17                                                                                           ` [PATCH 1/2 v6] HID: gt683r: fix race condition Janne Kanniainen
2014-07-03 17:17                                                                                             ` [PATCH 2/2 v6] HID: gt683r: move mode attribute to led-class devices Janne Kanniainen
2014-07-03 17:40                                                                                               ` Johan Hovold
2014-07-03 18:17                                                                                                 ` Bryan Wu
2014-07-03 18:28                                                                                                   ` Janne Kanniainen
2014-07-03 17:34                                                                                             ` [PATCH 1/2 v6] HID: gt683r: fix race condition Johan Hovold
2014-07-03 18:13                                                                                               ` Bryan Wu
2014-06-25 19:09                                                                               ` [PATCH 2/2 v2] HID: leds: Use attribute-groups in MSI GT683R driver Jiri Kosina
2014-06-25 22:55                                                                                 ` Bryan Wu
2014-06-30 10:47                                                                                   ` Johan Hovold
2014-06-30 11:33                                                                                     ` Jiri Kosina
2014-06-30 23:17                                                                                       ` Bryan Wu
2014-07-01  8:48                                                                                         ` Johan Hovold
2014-07-01 15:48                                                                                           ` Bryan Wu
2014-07-01 17:53                                                                                             ` Janne Kanniainen
2014-07-02  8:56                                                                                             ` Jiri Kosina
2014-06-23 16:20                                           ` [PATCH v9] leds: USB: HID: Add support for MSI GT683R led panels Janne Kanniainen
2014-06-14 22:42                       ` [PATCH v5] " Pavel Machek
2014-06-14 23:23                         ` Janne Kanniainen
2014-06-16  7:45                           ` Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140625115541.GA1409@localhost \
    --to=johan@kernel.org \
    --cc=bjorn@mork.no \
    --cc=cooloney@gmail.com \
    --cc=greg@kroah.com \
    --cc=janne.kanniainen@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).