From patchwork Mon May 4 15:10:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 467647 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 648541402AB for ; Tue, 5 May 2015 01:14:02 +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=SljMi4VQ; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752095AbbEDPNz (ORCPT ); Mon, 4 May 2015 11:13:55 -0400 Received: from mail-lb0-f175.google.com ([209.85.217.175]:36824 "EHLO mail-lb0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751740AbbEDPNn (ORCPT ); Mon, 4 May 2015 11:13:43 -0400 Received: by lbbqq2 with SMTP id qq2so107047806lbb.3; Mon, 04 May 2015 08:13:41 -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=kg40Z9C1JTf0mta/5gQ/ED7DXS1i3ysBdjeTQJIAtnE=; b=SljMi4VQsZF/AX1Laidb7n78IHmJTl7tpoBFLyY6DvdBIeRB51pynXaLKTSzqrofxg 5SJdgqf8OZCqYJGj6mbXovoiw0gn6lYmnJLbvkVBr9sby+Mjw28Ec/eoKzdZqxGCN8v5 aWypTmzz5rjr5KrJb4Dz26WEALySobm5oap+SYZMunfnDtHOwZ/yXBPP8LolvEHyxA9U ROkaUmyLRiYdl+vdlc1QqVFCBobJszM4Y0AuIqt8BDnIJRpiB4Au7ctxgj4xcO6dY0EJ WNMkGUSXoUj5VEs33Re5USKQhVvw9EpogzFXsmNXzjlfLXsT1YClM5go3OJ5ewh8PUSZ U7/g== X-Received: by 10.152.26.130 with SMTP id l2mr20161169lag.20.1430752421271; Mon, 04 May 2015 08:13:41 -0700 (PDT) Received: from xi.terra (c193-14-96-226.cust.tele2.se. [193.14.96.226]) by mx.google.com with ESMTPSA id si3sm3409373lbb.32.2015.05.04.08.13.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 May 2015 08:13:39 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.84) (envelope-from ) id 1YpI3x-00041u-TT; Mon, 04 May 2015 17:13:41 +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 03/23] gpio: sysfs: fix redundant lock-as-irq handling Date: Mon, 4 May 2015 17:10:28 +0200 Message-Id: <1430752248-15401-4-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 Drivers should call gpiochip_lock_as_irq (which prevents the pin direction from being changed) in their irq_request_resources callbacks but some drivers currently fail to do so. Instead a second, explicit and often redundant call to lock-as-irq is made by the sysfs-interface implementation after an irq has been requested. Move the explicit call before the irq-request to match the unlock done after the irq is later released. Note that this also fixes an irq leak, should the explicit call ever have failed. Also add a comment about removing the redundant call once the broken drivers have been fixed. Signed-off-by: Johan Hovold --- drivers/gpio/gpiolib-sysfs.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index af3bc7a8033b..b2b62cc6f9e1 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -195,20 +195,28 @@ static int gpio_setup_irq(struct gpio_desc *desc, struct device *dev, } } - ret = request_any_context_irq(irq, gpio_sysfs_irq, irq_flags, - "gpiolib", value_sd); + /* + * FIXME: This should be done in the irq_request_resources callback + * when the irq is requested, but a few drivers currently fail + * to do so. + * + * Remove this redundant call (along with the corresponding + * unlock) when those drivers have been fixed. + */ + ret = gpiochip_lock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); if (ret < 0) goto free_id; - ret = gpiochip_lock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); - if (ret < 0) { - gpiod_warn(desc, "failed to flag the GPIO for IRQ\n"); - goto free_id; - } + ret = request_any_context_irq(irq, gpio_sysfs_irq, irq_flags, + "gpiolib", value_sd); + if (ret < 0) + goto err_unlock; desc->flags |= gpio_flags; return 0; +err_unlock: + gpiochip_unlock_as_irq(desc->chip, gpio_chip_hwgpio(desc)); free_id: idr_remove(&dirent_idr, id); desc->flags &= GPIO_FLAGS_MASK;