From patchwork Wed Jun 25 17:08:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 4422221 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 9471E9F1D6 for ; Wed, 25 Jun 2014 17:12:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C0EDE2038D for ; Wed, 25 Jun 2014 17:12:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E462320394 for ; Wed, 25 Jun 2014 17:12:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757852AbaFYRJ4 (ORCPT ); Wed, 25 Jun 2014 13:09:56 -0400 Received: from mail-la0-f45.google.com ([209.85.215.45]:37858 "EHLO mail-la0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757813AbaFYRJy (ORCPT ); Wed, 25 Jun 2014 13:09:54 -0400 Received: by mail-la0-f45.google.com with SMTP id hr17so987803lab.18 for ; Wed, 25 Jun 2014 10:09:52 -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=5YnPYb1qybquGy3V+cZDa8F6Rdxm6FwSEHkiquk2V0A=; b=RpMZHjLzLpIdHA+S2M7U75wgVO2C/pxmncgBsz3o4z3wNx6qDGlws7MBKqs3FyowRP CzZW7YtebokovmIudz13Rmf1FrEG27JuKfws2al7YQyOlUSwI1sVOzxB2PwnaDRO1rBu adGVFO97p8rjNYXHm7WcnNkjg/oTboT57s8EfwVkBFH5F0/y0X35wPLqQ8g+q0m1tgtr 7OHT0eyhUBb0RWiT2wwt4DKfDqc+kn5EJeHlKPsO7yMVmavnc38Lippa3AX9JI1U/U+l 8y7tuLANVIWUV3/3qz19x3K5V6vidyKGKQmpY9Kfv4CNrWlX/zwjsEiCvl5caRIQEZDs 8xFw== X-Received: by 10.152.87.80 with SMTP id v16mr2572576laz.77.1403716192699; Wed, 25 Jun 2014 10:09:52 -0700 (PDT) Received: from xi.terra (c193-14-141-227.cust.tele2.se. [193.14.141.227]) by mx.google.com with ESMTPSA id d8sm1807323lah.12.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-000054-1Z; 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 02/13] leds: lm3550: fix attribute-creation race Date: Wed, 25 Jun 2014 19:08:45 +0200 Message-Id: <1403716136-32694-3-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=unavailable 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 mode attribute during probe in order to avoid racing with userspace. Signed-off-by: Johan Hovold --- drivers/leds/leds-lm3530.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/leds/leds-lm3530.c b/drivers/leds/leds-lm3530.c index 652368c2ea9a..91325de3cd33 100644 --- a/drivers/leds/leds-lm3530.c +++ b/drivers/leds/leds-lm3530.c @@ -400,6 +400,12 @@ static ssize_t lm3530_mode_set(struct device *dev, struct device_attribute } static DEVICE_ATTR(mode, 0644, lm3530_mode_get, lm3530_mode_set); +static struct attribute *lm3530_attrs[] = { + &dev_attr_mode.attr, + NULL +}; +ATTRIBUTE_GROUPS(lm3530); + static int lm3530_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -436,6 +442,7 @@ static int lm3530_probe(struct i2c_client *client, drvdata->led_dev.name = LM3530_LED_DEV; drvdata->led_dev.brightness_set = lm3530_brightness_set; drvdata->led_dev.max_brightness = MAX_BRIGHTNESS; + drvdata->led_dev.groups = lm3530_groups; i2c_set_clientdata(client, drvdata); @@ -461,26 +468,13 @@ static int lm3530_probe(struct i2c_client *client, return err; } - err = device_create_file(drvdata->led_dev.dev, &dev_attr_mode); - if (err < 0) { - dev_err(&client->dev, "File device creation failed: %d\n", err); - err = -ENODEV; - goto err_create_file; - } - return 0; - -err_create_file: - led_classdev_unregister(&drvdata->led_dev); - return err; } static int lm3530_remove(struct i2c_client *client) { struct lm3530_data *drvdata = i2c_get_clientdata(client); - device_remove_file(drvdata->led_dev.dev, &dev_attr_mode); - lm3530_led_disable(drvdata); led_classdev_unregister(&drvdata->led_dev); return 0;