From patchwork Wed Jun 25 17:08:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 4422321 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F178A9F1D6 for ; Wed, 25 Jun 2014 17:14:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 38F5020394 for ; Wed, 25 Jun 2014 17:14:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DB882038D for ; Wed, 25 Jun 2014 17:14:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932460AbaFYRN4 (ORCPT ); Wed, 25 Jun 2014 13:13:56 -0400 Received: from mail-lb0-f170.google.com ([209.85.217.170]:50110 "EHLO mail-lb0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757816AbaFYRJy (ORCPT ); Wed, 25 Jun 2014 13:09:54 -0400 Received: by mail-lb0-f170.google.com with SMTP id 10so2079572lbg.1 for ; Wed, 25 Jun 2014 10:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6lOEP4OxmaetpkqQcWL7lmbq7kFODy7WvddNleU0ULw=; b=ug/xYLlDUkrPZS1bve/WWc6G5kY9k71GvUQigGBOCM054qiQJZ6pnjsWeXXhWiPEQh ajsenjrw1tdroYnfPzy3DQLyeUcponAhTHlVr796zzoH7gI0kG8Osr10xjk6FPZVHkKg OVtXVybn2LNwPSF1ftabCqdeTYzxbbQ2w2VQXls5o15YTUa/5RnbfBB1tMzdLNpuPuit ruuqMg19EgrGW5uBASHZ24uRfehfzb0B0E2/1Vzvhr++1N5lrXRcXz+Ne6ZhlAxyE98S szt3kKqDFByOhGjX5Xu0jE0GhBRAFjjaaNqNd4irykEPWV4sUlicPEIaEPmq1aoxweIn 0Klg== X-Received: by 10.152.23.6 with SMTP id i6mr6878207laf.24.1403716193134; Wed, 25 Jun 2014 10:09:53 -0700 (PDT) Received: from xi.terra (c193-14-141-227.cust.tele2.se. [193.14.141.227]) by mx.google.com with ESMTPSA id si9sm1798982lac.42.2014.06.25.10.09.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jun 2014 10:09:52 -0700 (PDT) X-Google-Original-Sender: Received: from johan by xi.terra with local (Exim 4.80.1) (envelope-from ) id 1WzqhF-00005Z-LM; Wed, 25 Jun 2014 19:09:21 +0200 From: Johan Hovold To: Bryan Wu , Richard Purdie Cc: Dmitry Torokhov , Greg Kroah-Hartman , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Janne Kanniainen , Jiri Kosina , =?UTF-8?q?Bj=C3=B8rn=20Mork?= , Johan Hovold Subject: [PATCH 08/13] leds: ns2: fix attribute-creation race Date: Wed, 25 Jun 2014 19:08:51 +0200 Message-Id: <1403716136-32694-9-git-send-email-johan@kernel.org> X-Mailer: git-send-email 1.8.5.5 In-Reply-To: <1403716136-32694-1-git-send-email-johan@kernel.org> References: <1403716136-32694-1-git-send-email-johan@kernel.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/leds/leds-ns2.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c index efa625883c83..231993d1fe21 100644 --- a/drivers/leds/leds-ns2.c +++ b/drivers/leds/leds-ns2.c @@ -185,6 +185,12 @@ static ssize_t ns2_led_sata_show(struct device *dev, static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store); +static struct attribute *ns2_led_attrs[] = { + &dev_attr_sata.attr, + NULL +}; +ATTRIBUTE_GROUPS(ns2_led); + static int create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, const struct ns2_led *template) @@ -219,6 +225,7 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, led_dat->cdev.blink_set = NULL; led_dat->cdev.brightness_set = ns2_led_set; led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME; + led_dat->cdev.groups = ns2_led_groups; led_dat->cmd = template->cmd; led_dat->slow = template->slow; @@ -235,20 +242,11 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat, if (ret < 0) return ret; - ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata); - if (ret < 0) - goto err_free_cdev; - return 0; - -err_free_cdev: - led_classdev_unregister(&led_dat->cdev); - return ret; } static void delete_ns2_led(struct ns2_led_data *led_dat) { - device_remove_file(led_dat->cdev.dev, &dev_attr_sata); led_classdev_unregister(&led_dat->cdev); }