Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp770157ybc; Sat, 16 Nov 2019 08:23:03 -0800 (PST) X-Google-Smtp-Source: APXvYqzSnOTtXe2dfucomZ/M16LrPkBnO4+lBggBVYZcHL+jjxAVz5vowUEiNBGRz+vzNIJ4xPU8 X-Received: by 2002:a17:906:970a:: with SMTP id k10mr10571829ejx.314.1573921383475; Sat, 16 Nov 2019 08:23:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921383; cv=none; d=google.com; s=arc-20160816; b=DuNOzmpYBzlgimQ3cg+g5VFeCXp1p1Dhchdhh0IwO/7yoSpbCfaEcU0mvHFrMf8DQx 5CU23b3CVx88J57L3FkM0QFW5esP1q9kNEsQIrwI9/spV1Oqp+FGOqgagem7No2aoh3X mPHPKMetzQW0z4cwYmq3XMxnvgCvONsAno6asaZ33xyU8rbD5I0p11NO0SuwyuYnmX5L zNFAs0MHxkL2qqAlx4ulZiUaCZXg5i5J8NW6HpWn8qDzBFQZ0uWTf+iI6MS5gR+DBkpP 8k7HaqvQtGTCgqgwMtBf8TsACif5cvEmua2ugf0K5dXbZL6g2CGSWNxHGNfZDHNLh/Hx TUGg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Yv/x3n3oH1IlsHslfuGw9kEP/V8UNUAWY6fS4jVFbLY=; b=H42NRUAAkjwl7j5kd8VbfMwIF91eDQpUYNxiAacoCPSrl3aSFdT3sPClM0NyXf+/aZ L8efu4s+ljtF7Y3m4S/2h/aCTbJHXeQkS7HA2EYOQl5mFmtog/HfcuTyTBRC0fp3l0Rc Hap5/0H14eAsXY1ZkJKTBk8QHD79bwqJ7kd3EPb4MSSuLcNPMuVdU6EhiJD497x3vlIP gdJ6lrD3aDY5oG6KnFVDn5b0GBRrPLT0j5iQb9CL9yrtDMe2zEz87q+cdyLSklXxN1r9 CcntqFuZFmqWmz1XYoCE9wjk6rPtYKpSBbYb8k2E1uoj8TMpKdY6AYTbaOHjmw0xtBNe T8/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="M732/L/I"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i13si7592582ejj.367.2019.11.16.08.22.38; Sat, 16 Nov 2019 08:23:03 -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="M732/L/I"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729018AbfKPPoe (ORCPT + 99 others); Sat, 16 Nov 2019 10:44:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:49264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728968AbfKPPo1 (ORCPT ); Sat, 16 Nov 2019 10:44:27 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 30A5C2072D; Sat, 16 Nov 2019 15:44:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573919066; bh=by66fafWIkFfkatStvHYRKlIhFEru2T56686wGJEHj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M732/L/InWX7ylwULntQBASo+DgSH3XomiCAHcmyr97R9JNQEdk7qD6Me17SY+jV0 r9cCzuogJeDc9NGJlQL2l3jrYCzheWRV8CxTnuBxzithYgUFZnCym8KGaJ6/H1AoEs SYvVsANqyWreL6WckIA9RMwrVtYzD9cBb//coQ0I= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Masahiro Yamada , Wolfram Sang , Sasha Levin , linux-i2c@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 139/237] i2c: uniphier-f: fix race condition when IRQ is cleared Date: Sat, 16 Nov 2019 10:39:34 -0500 Message-Id: <20191116154113.7417-139-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Masahiro Yamada [ Upstream commit eaba68785c2d24ebf1f0d46c24e11b79cc2f94c7 ] The current IRQ handler clears all the IRQ status bits when it bails out. This is dangerous because it might clear away the status bits that have just been set while processing the current handler. If this happens, the IRQ event for the latest transfer is lost forever. The IRQ status bits must be cleared *before* the next transfer is kicked. Fixes: 6a62974b667f ("i2c: uniphier_f: add UniPhier FIFO-builtin I2C driver") Signed-off-by: Masahiro Yamada Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-uniphier-f.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index bbd5b137aa216..928ea9930d17e 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -143,9 +143,10 @@ static void uniphier_fi2c_set_irqs(struct uniphier_fi2c_priv *priv) writel(priv->enabled_irqs, priv->membase + UNIPHIER_FI2C_IE); } -static void uniphier_fi2c_clear_irqs(struct uniphier_fi2c_priv *priv) +static void uniphier_fi2c_clear_irqs(struct uniphier_fi2c_priv *priv, + u32 mask) { - writel(-1, priv->membase + UNIPHIER_FI2C_IC); + writel(mask, priv->membase + UNIPHIER_FI2C_IC); } static void uniphier_fi2c_stop(struct uniphier_fi2c_priv *priv) @@ -172,6 +173,8 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) "interrupt: enabled_irqs=%04x, irq_status=%04x\n", priv->enabled_irqs, irq_status); + uniphier_fi2c_clear_irqs(priv, irq_status); + if (irq_status & UNIPHIER_FI2C_INT_STOP) goto complete; @@ -250,8 +253,6 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) } handled: - uniphier_fi2c_clear_irqs(priv); - spin_unlock(&priv->lock); return IRQ_HANDLED; @@ -340,7 +341,7 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap, priv->flags |= UNIPHIER_FI2C_STOP; reinit_completion(&priv->comp); - uniphier_fi2c_clear_irqs(priv); + uniphier_fi2c_clear_irqs(priv, U32_MAX); writel(UNIPHIER_FI2C_RST_TBRST | UNIPHIER_FI2C_RST_RBRST, priv->membase + UNIPHIER_FI2C_RST); /* reset TX/RX FIFO */ -- 2.20.1