From patchwork Mon May 4 15:10:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 467643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E153814031F for ; Tue, 5 May 2015 01:13:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=eoSbJxDF; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751832AbbEDPNo (ORCPT ); Mon, 4 May 2015 11:13:44 -0400 Received: from mail-la0-f41.google.com ([209.85.215.41]:36718 "EHLO mail-la0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751504AbbEDPNm (ORCPT ); Mon, 4 May 2015 11:13:42 -0400 Received: by lagv1 with SMTP id v1so106307244lag.3; Mon, 04 May 2015 08:13:40 -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=TUugu+g4IIG7UL3mtou0GIlshBUmRI+dXWXLjJJA9BE=; b=eoSbJxDF6gUXUNCpk1uGvNCxYbRpmB31iD1q3RV31I8Ht4+IGute1WgG8zFQHYijT4 Vvm9xpliqv6nWKeHTPjjY929egraCZ/GnfulMqj1idLVe60GrdQnMGg2Gl7NqFG/Mh7P Zx0F2v3pApDZ17qz139twk0l4eoOULef86nNavksUzIWLkh9QxondpURtZkY3O8dpUYQ l5hXn+G+nG8TV3GnHsWl4uOV+88bVIiFvgug6ak3B/u7lATROtW5CtKfx5SHQIa2yJWp kJQeJp/R5qdwvgwrytKnheVGm1itEis6/px7dm4FSYvP9JNlsOsLlacOYWgXXFg/Iagf wwUA== X-Received: by 10.112.180.201 with SMTP id dq9mr20390329lbc.78.1430752420539; Mon, 04 May 2015 08:13:40 -0700 (PDT) Received: from xi.terra (c193-14-96-226.cust.tele2.se. [193.14.96.226]) by mx.google.com with ESMTPSA id h3sm3416637laf.24.2015.05.04.08.13.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 May 2015 08:13:40 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.84) (envelope-from ) id 1YpI3y-000424-3w; Mon, 04 May 2015 17:13:42 +0200 From: Johan Hovold To: Linus Walleij Cc: Alexandre Courbot , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v2 05/23] gpio: sysfs: reduce gpiochip-export locking scope Date: Mon, 4 May 2015 17:10:30 +0200 Message-Id: <1430752248-15401-6-git-send-email-johan@kernel.org> X-Mailer: git-send-email 2.0.5 In-Reply-To: <1430752248-15401-1-git-send-email-johan@kernel.org> References: <1430752248-15401-1-git-send-email-johan@kernel.org> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Reduce scope of sysfs_lock protection during chip export and unexport, which is only needed to prevent gpiod (re-)exports during chip removal. Signed-off-by: Johan Hovold --- drivers/gpio/gpiolib-sysfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 658ed28e6d7d..d19bf234e878 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -779,7 +779,6 @@ int gpiochip_export(struct gpio_chip *chip) return 0; /* use chip->base for the ID; it's already known to be unique */ - mutex_lock(&sysfs_lock); dev = device_create_with_groups(&gpio_class, chip->dev, MKDEV(0, 0), chip, gpiochip_groups, "gpiochip%d", chip->base); @@ -787,6 +786,8 @@ int gpiochip_export(struct gpio_chip *chip) status = PTR_ERR(dev); else status = 0; + + mutex_lock(&sysfs_lock); chip->exported = (status == 0); mutex_unlock(&sysfs_lock); @@ -803,17 +804,17 @@ void gpiochip_unexport(struct gpio_chip *chip) struct gpio_desc *desc; unsigned int i; - mutex_lock(&sysfs_lock); dev = class_find_device(&gpio_class, NULL, chip, match_export); if (dev) { put_device(dev); device_unregister(dev); /* prevent further gpiod exports */ + mutex_lock(&sysfs_lock); chip->exported = false; + mutex_unlock(&sysfs_lock); status = 0; } else status = -ENODEV; - mutex_unlock(&sysfs_lock); if (status) chip_dbg(chip, "%s: status %d\n", __func__, status);