From patchwork Wed Nov 27 20:30:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 180347 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp6673538ilf; Wed, 27 Nov 2019 13:25:41 -0800 (PST) X-Google-Smtp-Source: APXvYqz29x57vVfZFb71SFWpvz1kovuJ/+SRDrXN+xG4I/s3OsdRZPzVeOD3r0pAxE42n+8cEzY8 X-Received: by 2002:aa7:c990:: with SMTP id c16mr34667298edt.91.1574889941559; Wed, 27 Nov 2019 13:25:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574889941; cv=none; d=google.com; s=arc-20160816; b=fds28mvTeEcBhMpG0GU7zk7hHCEoA6Gi4mfUC8Kstldsts3pyGlAaLS/4mX2UER+/H RSZVJzxBjbXzULQQQdPcifLgPXJLv4zHOIarkpOh+UrnsyH4J9y4C4b5FmnpTfM1B44F HiG+7nB52N7S7fs4mI82eO7330LK7uFuAC5qIbVEDdHgeQhroI0daUufNq0/ObZWWqtE myASYK7L76F8kNR/12QWelvxMVq4alaWho/tLQ48wHUeYf+EdiOUHdiJ8uE200s3qWOi XqrQP7SBhCMC8mkd5Zi3lVo1IUukueaxHqN0sY5FRI2Oaxn0i+Jc+Mq+SuVYROZqeN6P 2xyw== 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 f7si12036572edy.92.2019.11.27.13.25.41; Wed, 27 Nov 2019 13:25:41 -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 S1731755AbfK0VBh (ORCPT + 26 others); Wed, 27 Nov 2019 16:01:37 -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 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(-) -- 2.20.1 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 */