Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp630019pxv; Thu, 15 Jul 2021 11:58:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLs4FJoKrwZOM33YgmX1mKMJUC6yBm0Ri7YP0YMFcgNSX6DNDQsk2l81m8q+7lM92waY8l X-Received: by 2002:a17:906:f751:: with SMTP id jp17mr7150616ejb.105.1626375521010; Thu, 15 Jul 2021 11:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375521; cv=none; d=google.com; s=arc-20160816; b=bjWbsj8j853y6yD7ew1Ka9FIZknYqAD/fW7dr2Jk6KeQorTVpeISKSSamowwq42T0N mPq9IZQoyEK/FI9zMAiWdH8sVnTHwNzHrSB6auCaY+t6WqradPq8VKhtsCjGG/Sz9woR kdgTxj2Y1ofxdAQHZPJ9uC5qU9okvuyOgNZev8IptkAyhehBgDdjwC5aeygOehUfds9C G8T2WrGvuvbpSvQZYGOllXORuaJSC67QSBYq/pDaO8aalY1r4x0YX3G6uSAP1+8nEa1i 1diWUGTsqAVNjwne9MzhsEVObXVZ2P0yR6L72Zb7Uioqt8iEIkCOaJCwJa7XGWJRHTxk scNg== 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=VUVNtSP6UITvfyJlwORXUcJ6x89AlG/Donh6dMIIbrzjL1rpAyTR/4OTFOs+MmU0xL ps+3WYeptbZx24jkpLmRVGrrNvd4Vx+NVtM0ZQ4AmmjCOT+6KGSLcKFAw7UhSSozVV9j mjijcNoS6hqIaJ/kuRv2tU4u3uKONAUsdGF2sufbKAoUa+n8Eh6Gnny28DQcWHsukX+u 7H6+jr/2sQd7XL+PYW8SGhiwvYpkZrHi6/YrIvIIHt/ovfsegMyDbiioTu0PUyGtmcP8 RpyUY+R9s+w9jAkF+LZH7u12BWm0OU6hHZ6WZ3bFDhRda2QCmtsmQW0TPyQB3Q8a0zKm ++oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hg8WMorw; 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 ce5si8118833ejb.237.2021.07.15.11.58.17; Thu, 15 Jul 2021 11:58:40 -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=hg8WMorw; 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 S242193AbhGOS7c (ORCPT + 99 others); Thu, 15 Jul 2021 14:59:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:56214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232870AbhGOSwc (ORCPT ); Thu, 15 Jul 2021 14:52:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D3351613CC; Thu, 15 Jul 2021 18:49:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374978; bh=+DqxFN9ITQT8/uYsw9hTN5wttBWimqS6cfsrA3DFqjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hg8WMorwf0EJfTRtWUTYuT/iVG/dIJT4gu7bU4JqG+7ijhruwdp1GCzSm9Jc2byN/ f5VDhvJNCv3YpN3W7SASLAeG5FilEwdr8D9zZ7ciRoqJwGA+5bfC5TRNPSEZ5zWJvR 9hemA32tSsWxOCVPSki8FyvuxI8XFD6BaDXvZiUU= 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.10 055/215] pinctrl: mcp23s08: fix race condition in irq handler Date: Thu, 15 Jul 2021 20:37:07 +0200 Message-Id: <20210715182609.157349779@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@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