From patchwork Tue Apr 21 15:42:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 463382 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 32613140213 for ; Wed, 22 Apr 2015 01:54:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="verification failed; unprotected key" header.d=gmail.com header.i=@gmail.com header.b=YFsywGdJ; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932949AbbDUPyZ (ORCPT ); Tue, 21 Apr 2015 11:54:25 -0400 Received: from mail-lb0-f171.google.com ([209.85.217.171]:36599 "EHLO mail-lb0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755702AbbDUPnN (ORCPT ); Tue, 21 Apr 2015 11:43:13 -0400 Received: by lbbqq2 with SMTP id qq2so158796505lbb.3; Tue, 21 Apr 2015 08:43:10 -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=4eBXwelSIJlG3Hqaga4Hx4vjvVguqqAqRvqHmy/wvt4=; b=YFsywGdJzoQluVBU3zWqIrYm5E8XuJj0y/LmOlVYPO9taoY3csJq1+y+azqxAmKYs1 lgHKp0YJJWHuRoFcwZkg9AfcM+Ru242mmdcms32vxRa8h/La0GDXJ20+TnUQkAANGAr8 HoyPjhu39Jebc3CXMsu8wgQ+1goShdNwf7Qe0HIt0JuP8xsQNs6y2dvhPCiKW2HTNVUA 82wnIPfhBa1f/NNedSYhiw+//ok3m8vH41rQ4VMiOfUTv2VOg9rgwfhwIisZxNEkGvC0 WEGZCw3argCcxtpudSoXI1tAQDw+9Pt4FMUKMxnCeqTQWbxK8D1ee/qkPr3IUEU5lCdN pSMg== X-Received: by 10.112.122.33 with SMTP id lp1mr20742663lbb.110.1429630990475; Tue, 21 Apr 2015 08:43:10 -0700 (PDT) Received: from xi.terra (c193-14-96-226.cust.tele2.se. [193.14.96.226]) by mx.google.com with ESMTPSA id ml10sm483462lbc.29.2015.04.21.08.43.09 (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 1YkaKN-00075D-4s; Tue, 21 Apr 2015 17:43:11 +0200 From: Johan Hovold To: Linus Walleij Cc: Alexandre Courbot , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 18/23] gpio: sysfs: clean up gpiod_export_link locking Date: Tue, 21 Apr 2015 17:42:26 +0200 Message-Id: <1429630951-27082-19-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 Drop unnecessary locking from gpiod_export_link. If the class device has not already been unregistered, class_find_device returns the ref-counted class device so there's no need for locking. Signed-off-by: Johan Hovold --- drivers/gpio/gpiolib-sysfs.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 761e1644cff1..d9265b4609a3 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -616,34 +616,22 @@ static int match_export(struct device *dev, const void *desc) int gpiod_export_link(struct device *dev, const char *name, struct gpio_desc *desc) { - int status = -EINVAL; + struct device *cdev; + int ret; if (!desc) { pr_warn("%s: invalid GPIO\n", __func__); return -EINVAL; } - mutex_lock(&sysfs_lock); - - if (test_bit(FLAG_EXPORT, &desc->flags)) { - struct device *tdev; - - tdev = class_find_device(&gpio_class, NULL, desc, match_export); - if (tdev != NULL) { - status = sysfs_create_link(&dev->kobj, &tdev->kobj, - name); - put_device(tdev); - } else { - status = -ENODEV; - } - } - - mutex_unlock(&sysfs_lock); + cdev = class_find_device(&gpio_class, NULL, desc, match_export); + if (!cdev) + return -ENODEV; - if (status) - gpiod_dbg(desc, "%s: status %d\n", __func__, status); + ret = sysfs_create_link(&dev->kobj, &cdev->kobj, name); + put_device(cdev); - return status; + return ret; } EXPORT_SYMBOL_GPL(gpiod_export_link);