Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6016925ybc; Wed, 27 Nov 2019 13:28:17 -0800 (PST) X-Google-Smtp-Source: APXvYqwe5cQe0PLGqscP/kmKcJ/QjywvFV/fEHUYnReTP0hYANrLXiYJdF/mHLxLIAwlCnq+pONx X-Received: by 2002:a17:906:76cf:: with SMTP id q15mr33908061ejn.247.1574890096899; Wed, 27 Nov 2019 13:28:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890096; cv=none; d=google.com; s=arc-20160816; b=0A5zP1DGp+yiJOc8qduxwQ1jyTgcRagOYW92yDemWZIz5UWSTgq6g1EvjcppeN1CoK kLeFiudcn/jYBAzBBDW+lSfKcvMSh4HmU3sJ8vCCZ5u4JOXAvtqM4duTp6OFbzr/7jPN nN8CWQvQJhdiLcxuxX5eucPAUbyKbRXG3fR3z9LxUWkpnNI1NsakO+fPvDhG87GBXd+W 1ouQElhA3m6gTqozH6xupZqCUEUPVTLLvANWMmi4wRB9um9RwZRina7w1zUJ6+B03Lqo MG27EVWZrXTg1ja6b/YD/nRnlIkrYbBTNF6ac+Lg23JonuW2DiDK+nn7rmQb4AC8ufHS jgmA== 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=Yv/x3n3oH1IlsHslfuGw9kEP/V8UNUAWY6fS4jVFbLY=; b=dy9jeJ+fvPCojDZg2oOirsIWHccK1J6d51O3FgzQfsItMhNq5ZrS4qfQGjETytkq+g GD/6aNFcEy7LX+sLwiNH3jY0I4c89yQQbcXHl2MFefTTrlrYlay3DDCu/DxeuGCDG96J +wWk+8w7DS1GBN326/N3Nd2Q4Os2M/axy6YHP+8gM6GQrSnul7kCkQ3XdDez2AJwj2sE FA8onkKfOwM4hyG/Ov6BfaikQ1Iouze74FE+9m7DSPwIDcR/OZfGVMKR4veqaJMvBopb QtAdQiwTsQBadLFJ7NvHx0TPr158SWh3pXJZEyehLljKLBcPv/HYxtceKI07rAJZvGZI JQ+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sYgAxl0I; 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 j38si14899671eda.384.2019.11.27.13.27.53; Wed, 27 Nov 2019 13:28:16 -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=sYgAxl0I; 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 S1731322AbfK0VBf (ORCPT + 99 others); Wed, 27 Nov 2019 16:01:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:53864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731741AbfK0VBc (ORCPT ); Wed, 27 Nov 2019 16:01:32 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 0215E2086A; Wed, 27 Nov 2019 21:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888491; bh=by66fafWIkFfkatStvHYRKlIhFEru2T56686wGJEHj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sYgAxl0Io5qISfuhwSbxXlIDwF0tOnz1ZMuQ6xFX5YAiUBJA/51dCWngDsIRn7LRI M8OpiJ8un+pgljsOUUXVcaDe+F4txJNitqwMf2MJvT774cPrEcXWHKw9+93h4CmVnc lQQetkVPjTGrKD7XpbSY9b112B6BooJA2K78nH2g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada , Wolfram Sang , Sasha Levin Subject: [PATCH 4.19 156/306] i2c: uniphier-f: fix race condition when IRQ is cleared Date: Wed, 27 Nov 2019 21:30:06 +0100 Message-Id: <20191127203126.999886239@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 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 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