Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp638199pxv; Thu, 15 Jul 2021 12:09:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZUVoOL/hYqRAXVA+Ha8n+UydxOMIFRCX11lR+gEN+CP/h3AOeWnXTv3p/WkAY875iyfss X-Received: by 2002:a17:906:fb15:: with SMTP id lz21mr7048966ejb.521.1626376165969; Thu, 15 Jul 2021 12:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626376165; cv=none; d=google.com; s=arc-20160816; b=JyN7yHhzu/mqR+iDsAl0/Wyu0PC6eHFz7usZe23+rfd7PzrlgvLTpGcRDeWu3mApQN g+qvPtbGXy5xS57rUxUxh5xpFn3LgZ1uQB12Wv3nyTlneZmQiq6CgPsLvReAQGw5x2MR L8fwSZv4gekUCG9KLwpCb3m0hAKqEQrTR9rZc98AoP1hGpOPIleUqKOoy29QdDCbh7Kp ehBVaHw6ctwYZwWf2dGQhsdYSyfBp3fspKDW6uFjXbzqExVV4cGAQ8Fhd6SxplxA3QWr asRa6LVe0NbKjSA8bZ4bTsawtV++WenAwOpKwzJLxEeaFcZPmrmuaes/wZMxSzx38QgI uKag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=00uuY0i6MwTApYEXCg9x3GWsDLwpRD8nNum0nqSHeC0=; b=NdtNr75EqdOIUiQm7WPLkiXA4/r+61kR9052k6oxEBQp1fzNfo/yqllyvf3iycKQDz B3hZSTXpkLMJ5UbP3SBHFgw4BRIhTXqZS6gBGwgFn43A82YBP+mnkYL6APBw7FpZqRyW 2mH6moCrh58Osz/SoGVudlC1DwypVDDwIfnVX/3V7McTMgsh618TTcfYT/lIEaoRDCn2 GFSWCrw6RAGJbuWV5K6pk/z5ShoZ3hif/9m9ZsDVp7grQTAiBokUm1IWhNZ7qUmMVE/N Tip5O/WNpV9F60r8FX0C7RullE9TJot8J8qVQ4HmrJVYPPpSDFIFOrvWOc1eyRubtRPP 99xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ymZiBQLD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f24si8139824edw.224.2021.07.15.12.09.03; Thu, 15 Jul 2021 12:09:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ymZiBQLD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243682AbhGOTKA (ORCPT + 99 others); Thu, 15 Jul 2021 15:10:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:34948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242334AbhGOS7h (ORCPT ); Thu, 15 Jul 2021 14:59:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D6CD5613EE; Thu, 15 Jul 2021 18:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375382; bh=+DqxFN9ITQT8/uYsw9hTN5wttBWimqS6cfsrA3DFqjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ymZiBQLD0g+tKfTkEvTtG5qqadED7kVCspexPDNJtr6JIW7D9x4/KA7c9+2tzbChf yXx0c3j7ukwwUao54STzAvpHg0xjddkYF7khyDjEkl0RsOIA45hDivl7UrCsumEipv nejBw7//3UcP+BLUnSI+Q4RPCGFmUpG8MEMtRm1E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Radim Pavlik , Linus Walleij , Sasha Levin Subject: [PATCH 5.12 061/242] pinctrl: mcp23s08: fix race condition in irq handler Date: Thu, 15 Jul 2021 20:37:03 +0200 Message-Id: <20210715182603.193204547@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Radim Pavlik [ Upstream commit 897120d41e7afd9da435cb00041a142aeeb53c07 ] Checking value of MCP_INTF in mcp23s08_irq suggests that the handler may be called even when there is no interrupt pending. But the actual interrupt could happened between reading MCP_INTF and MCP_GPIO. In this situation we got nothing from MCP_INTF, but the event gets acknowledged on the expander by reading MCP_GPIO. This leads to losing events. Fix the problem by not reading any register until we see something in MCP_INTF. The error was reproduced and fix tested on MCP23017. Signed-off-by: Radim Pavlik Link: https://lore.kernel.org/r/AM7PR06MB6769E1183F68DEBB252F665ABA3E9@AM7PR06MB6769.eurprd06.prod.outlook.com Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/pinctrl-mcp23s08.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c index ce2d8014b7e0..799d596a1a4b 100644 --- a/drivers/pinctrl/pinctrl-mcp23s08.c +++ b/drivers/pinctrl/pinctrl-mcp23s08.c @@ -351,6 +351,11 @@ static irqreturn_t mcp23s08_irq(int irq, void *data) if (mcp_read(mcp, MCP_INTF, &intf)) goto unlock; + if (intf == 0) { + /* There is no interrupt pending */ + return IRQ_HANDLED; + } + if (mcp_read(mcp, MCP_INTCAP, &intcap)) goto unlock; @@ -368,11 +373,6 @@ static irqreturn_t mcp23s08_irq(int irq, void *data) mcp->cached_gpio = gpio; mutex_unlock(&mcp->lock); - if (intf == 0) { - /* There is no interrupt pending */ - return IRQ_HANDLED; - } - dev_dbg(mcp->chip.parent, "intcap 0x%04X intf 0x%04X gpio_orig 0x%04X gpio 0x%04X\n", intcap, intf, gpio_orig, gpio); -- 2.30.2