From patchwork Tue Apr 21 15:42:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 463380 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 1B99C140213 for ; Wed, 22 Apr 2015 01:52:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=ZbPaq6vc; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755272AbbDUPtB (ORCPT ); Tue, 21 Apr 2015 11:49:01 -0400 Received: from mail-lb0-f179.google.com ([209.85.217.179]:33055 "EHLO mail-lb0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755705AbbDUPnN (ORCPT ); Tue, 21 Apr 2015 11:43:13 -0400 Received: by lbbzk7 with SMTP id zk7so158981575lbb.0; Tue, 21 Apr 2015 08:43:11 -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=rx47Iu1rxRMRhfbgLtT1+qpHN+N6AGvnzgPVlh4fNpo=; b=ZbPaq6vctaTxh7XYR174anSKdCBClA/O4fR0IYqc8kaE1eA22goHP092afpDUdp9Cb 3IHLlesW5TPMoS5sOJ9WrEEkWR3fKh9Az92aZtUAzsKxZadXsAWoruglgbxjKQJU0p2d MMWNwhMkvlcWb+rjlZarfA/4fXPeNOWY6NmIH6A4j5jr2RsEbcYjl5ZN/vDkODk/OM5l j++bTiVHocdit8+TUw9RKlisnP3plnhIGH7O3QtafqRLEEgSqMcPhLcniqo6tHk/0MuL 0sgvh3+T5J2mHfdqfJc/9dgR5I9MLF5wonLfmtsfDLtKAytcos4ISxhqGYTqMiUkqanV en4A== X-Received: by 10.153.8.167 with SMTP id dl7mr131523lad.86.1429630991192; Tue, 21 Apr 2015 08:43:11 -0700 (PDT) Received: from xi.terra (c193-14-96-226.cust.tele2.se. [193.14.96.226]) by mx.google.com with ESMTPSA id m8sm486180lbs.17.2015.04.21.08.43.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Apr 2015 08:43:10 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.84) (envelope-from ) id 1YkaKL-00074A-QT; Tue, 21 Apr 2015 17:43:09 +0200 From: Johan Hovold To: Linus Walleij Cc: Alexandre Courbot , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 05/23] gpio: sysfs: reduce gpiochip-export locking scope Date: Tue, 21 Apr 2015 17:42:13 +0200 Message-Id: <1429630951-27082-6-git-send-email-johan@kernel.org> X-Mailer: git-send-email 2.0.5 In-Reply-To: <1429630951-27082-1-git-send-email-johan@kernel.org> References: <1429630951-27082-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 da0300224b4a..c433f075f349 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -764,7 +764,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); @@ -772,6 +771,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); @@ -788,17 +789,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);