Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2976927imu; Mon, 19 Nov 2018 08:53:11 -0800 (PST) X-Google-Smtp-Source: AJdET5dKLIjGkPvVdYFJ/YvmTFNCVVV7klsbxPWYQoRKL+q2EG56DR/+d5l35sqZmv2qMPxa9vxa X-Received: by 2002:a17:902:6946:: with SMTP id k6mr20128559plt.101.1542646391125; Mon, 19 Nov 2018 08:53:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542646391; cv=none; d=google.com; s=arc-20160816; b=f4K9slECDWrEvGsmDvJbqnSd5mSOMIBX0ZaTWywPEwE85GbSO/SJVFLB52Bu3PapZz UzcIHtF4lfi2IHeqr8HDmHczIVLEDvVG5RM7rh/qXtBmzjUW0POE7yxr2yfQ74eyT5PU jPYjm3HFhW02mZmbR14hRoU7lYbEHNGYTA4eN/bRRk95ApRDfEmgDxV7g+/M1aHYwGVf h7mR4F8ga1EXafxqJKz4/iqte99kVbGZ3TbPblwHE3/gPHpJlswURPuKtqfNpDCekgJ1 scrbzsQH/trQsxk3zqgDJ//ty8EfgvO0zISv9UMJsOOyf3Yg/+1LoKj0cJTCfzP1zUdv GSNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/6B9CkJrq9OT69sIx0aw7xjyuLXHvrF5PGz9kYR/B4Q=; b=q6kejKq5EjEli9uOYTzZ9S83dA/Tcy+q+6Al94hdDmZ3dvjcd3Zjg2/O7MgVKzT97P UI0auV7MRNwZPi/W34/U35TIk15Qk9AMDcDk502k1NoLGUe5Qg/UGp8nX2I7r1mF8UBP OArLrZ8ZryNZfV6fCwNdsuWgauQNaA9nbIPlfPwvWWvPzCiaoXKUzjDfc7Rk/5b+2wte BcFQRjW7QCmVxJDv4h7dKTfEW3+5lDOa6qu0BSvhgkg6hQdF+xChGdN1I23AIbmof/A6 u/IXFSm70UIgSVFW7vSYu/0n4STGxaDXNQxTGA9f2lbbufjvdsGyYFDnYympkEV3p6iO Nwsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mIzbAVaK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c191si24276248pfg.72.2018.11.19.08.52.56; Mon, 19 Nov 2018 08:53:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mIzbAVaK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390497AbeKTDQU (ORCPT + 99 others); Mon, 19 Nov 2018 22:16:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:54232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389669AbeKTDQT (ORCPT ); Mon, 19 Nov 2018 22:16:19 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 97B5421104; Mon, 19 Nov 2018 16:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646326; bh=yENuWU7l34XokPTkoWu3Epd4w5mXTBRiBofPacUqWQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mIzbAVaK+DF8HD8xJUMbaU+7L4EZcpyJ8ZnOgAhgW72H/TApjmnmntNSDKv4kaJBv dFk6UfAUF684ZEuHsMweidsRib6kL8qP7EWR96Csn0EVMehkX/uGvt5DtY0/TIdf35 dUr1en/K6HKWGm2rngV2kQEp07lfkZmn+AECVhic= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Doug Berger , Florian Fainelli , Gregory Fong , Linus Walleij , Sudip Mukherjee Subject: [PATCH 4.14 124/124] gpio: brcmstb: release the bgpio lock during irq handlers Date: Mon, 19 Nov 2018 17:29:38 +0100 Message-Id: <20181119162634.317442434@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162612.951907286@linuxfoundation.org> References: <20181119162612.951907286@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Doug Berger commit 142c168e0e50164e67c9399c28dedd65a307cfe5 upstream. The basic memory-mapped GPIO controller lock must be released before calling the registered GPIO interrupt handlers to allow the interrupt handlers to access the hardware. Examples of why a GPIO interrupt handler might want to access the GPIO hardware include an interrupt that is configured to trigger on rising and falling edges that needs to read the current level of the input to know how to respond, or an interrupt that causes a change in a GPIO output in the same bank. If the lock is not released before enterring the handler the hardware accesses will deadlock when they attempt to grab the lock. Since the lock is only needed to protect the calculation of unmasked pending interrupts create a dedicated function to perform this and hide the complexity. Fixes: 19a7b6940b78 ("gpio: brcmstb: Add interrupt and wakeup source support") Signed-off-by: Doug Berger Reviewed-by: Florian Fainelli Acked-by: Gregory Fong Signed-off-by: Linus Walleij Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/gpio/gpio-brcmstb.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) --- a/drivers/gpio/gpio-brcmstb.c +++ b/drivers/gpio/gpio-brcmstb.c @@ -63,6 +63,21 @@ brcmstb_gpio_gc_to_priv(struct gpio_chip return bank->parent_priv; } +static unsigned long +brcmstb_gpio_get_active_irqs(struct brcmstb_gpio_bank *bank) +{ + void __iomem *reg_base = bank->parent_priv->reg_base; + unsigned long status; + unsigned long flags; + + spin_lock_irqsave(&bank->gc.bgpio_lock, flags); + status = bank->gc.read_reg(reg_base + GIO_STAT(bank->id)) & + bank->gc.read_reg(reg_base + GIO_MASK(bank->id)); + spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); + + return status; +} + static void brcmstb_gpio_set_imask(struct brcmstb_gpio_bank *bank, unsigned int offset, bool enable) { @@ -205,11 +220,8 @@ static void brcmstb_gpio_irq_bank_handle struct irq_domain *irq_domain = bank->gc.irqdomain; void __iomem *reg_base = priv->reg_base; unsigned long status; - unsigned long flags; - spin_lock_irqsave(&bank->gc.bgpio_lock, flags); - while ((status = bank->gc.read_reg(reg_base + GIO_STAT(bank->id)) & - bank->gc.read_reg(reg_base + GIO_MASK(bank->id)))) { + while ((status = brcmstb_gpio_get_active_irqs(bank))) { int bit; for_each_set_bit(bit, &status, 32) { @@ -224,7 +236,6 @@ static void brcmstb_gpio_irq_bank_handle generic_handle_irq(irq_find_mapping(irq_domain, bit)); } } - spin_unlock_irqrestore(&bank->gc.bgpio_lock, flags); } /* Each UPG GIO block has one IRQ for all banks */