linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Bryan Wu <cooloney@gmail.com>, Richard Purdie <rpurdie@rpsys.net>
Cc: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-leds@vger.kernel.org,
	"Janne Kanniainen" <janne.kanniainen@gmail.com>,
	"Jiri Kosina" <jkosina@suse.cz>, "Bjørn Mork" <bjorn@mork.no>,
	"Johan Hovold" <johan@kernel.org>
Subject: [PATCH 07/13] leds: netxbig: fix attribute-creation race
Date: Wed, 25 Jun 2014 19:08:50 +0200	[thread overview]
Message-ID: <1403716136-32694-8-git-send-email-johan@kernel.org> (raw)
In-Reply-To: <1403716136-32694-1-git-send-email-johan@kernel.org>

Use the attribute groups of the led-class to create the sata attribute
during probe in order to avoid racing with userspace.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/leds/leds-netxbig.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
index e97f443a6e07..8ab931b8fcd3 100644
--- a/drivers/leds/leds-netxbig.c
+++ b/drivers/leds/leds-netxbig.c
@@ -293,10 +293,14 @@ static ssize_t netxbig_led_sata_show(struct device *dev,
 
 static DEVICE_ATTR(sata, 0644, netxbig_led_sata_show, netxbig_led_sata_store);
 
+static struct attribute *netxbig_led_attrs[] = {
+	&dev_attr_sata.attr,
+	NULL
+};
+ATTRIBUTE_GROUPS(netxbig_led);
+
 static void delete_netxbig_led(struct netxbig_led_data *led_dat)
 {
-	if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE)
-		device_remove_file(led_dat->cdev.dev, &dev_attr_sata);
 	led_classdev_unregister(&led_dat->cdev);
 }
 
@@ -327,6 +331,12 @@ create_netxbig_led(struct platform_device *pdev,
 	led_dat->sata = 0;
 	led_dat->cdev.brightness = LED_OFF;
 	led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
+	/*
+	 * If available, expose the SATA activity blink capability through
+	 * a "sata" sysfs attribute.
+	 */
+	if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE)
+		led_dat->cdev.groups = netxbig_led_groups;
 	led_dat->mode_addr = template->mode_addr;
 	led_dat->mode_val = template->mode_val;
 	led_dat->bright_addr = template->bright_addr;
@@ -335,18 +345,6 @@ create_netxbig_led(struct platform_device *pdev,
 	led_dat->num_timer = pdata->num_timer;
 
 	ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
-	if (ret < 0)
-		return ret;
-
-	/*
-	 * If available, expose the SATA activity blink capability through
-	 * a "sata" sysfs attribute.
-	 */
-	if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE) {
-		ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata);
-		if (ret)
-			led_classdev_unregister(&led_dat->cdev);
-	}
 
 	return ret;
 }
-- 
1.8.5.5

  parent reply	other threads:[~2014-06-25 17:08 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-25 17:08 [PATCH 00/13] leds: fix attribute-creation races Johan Hovold
2014-06-25 17:08 ` [PATCH 01/13] leds: add led-class attribute-group support Johan Hovold
2014-06-25 17:08 ` [PATCH 02/13] leds: lm3550: fix attribute-creation race Johan Hovold
2014-06-25 17:08 ` [PATCH 03/13] leds: lm3533: " Johan Hovold
2014-06-25 17:08 ` [PATCH 04/13] leds: lm355x: " Johan Hovold
2014-06-25 17:08 ` [PATCH 05/13] leds: lm3642: " Johan Hovold
2014-06-25 17:08 ` [PATCH 06/13] leds: max8997: " Johan Hovold
2014-06-25 17:08 ` Johan Hovold [this message]
2014-06-25 22:30   ` [PATCH 07/13] leds: netxbig: " Bryan Wu
2014-06-25 17:08 ` [PATCH 08/13] leds: ns2: " Johan Hovold
2014-06-25 17:08 ` [PATCH 09/13] leds: ss4200: " Johan Hovold
2014-06-25 17:08 ` [PATCH 10/13] leds: wm831x-status: " Johan Hovold
2014-06-25 17:08 ` [PATCH 11/13] input: lm8323: " Johan Hovold
2014-06-25 22:45   ` Bryan Wu
2014-06-27 18:50   ` Dmitry Torokhov
2014-06-30 23:06     ` Bryan Wu
2014-06-25 17:08 ` [PATCH 12/13] leds: lp55xx-common: fix sysfs entry leak Johan Hovold
2014-06-25 17:08 ` [PATCH 13/13] leds: lp55xx-common: fix attribute-creation race Johan Hovold
2014-06-25 22:46 ` [PATCH 00/13] leds: fix attribute-creation races Bryan Wu
2014-06-26 23:25   ` Greg Kroah-Hartman
2014-06-27 10:05     ` Jiri Kosina

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=1403716136-32694-8-git-send-email-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=bjorn@mork.no \
    --cc=cooloney@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --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=rpurdie@rpsys.net \
    /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).