From patchwork Wed Nov 27 20:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 180327 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp6638370ilf; Wed, 27 Nov 2019 12:51:57 -0800 (PST) X-Google-Smtp-Source: APXvYqykCX7nL+drvTPaMP7BhDpQZZSLN6uWmSgBTZeEaxEy8R1BqUdYzY6uoSp45JH7Pq4gGFQh X-Received: by 2002:a17:906:f245:: with SMTP id gy5mr7631201ejb.225.1574887917588; Wed, 27 Nov 2019 12:51:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887917; cv=none; d=google.com; s=arc-20160816; b=XuMEfopJJSskfwq74Yg+/JUXWYI6S2ZBAQ7nPaZCrUL+LY2p6gpyJbhDLYy/Q9uTah Qm3D84WR+qlf17VAnRl0ngmTZyiutOJoaMv1o/wyQMCl/iVaYGOMjzCTPkyLw/10hai0 o8bY21mML0+xhUFJU7NH4vUxUmh+NWU33w/Ti4r4KHHkh91GUWZgzVvFBBIdO6ODOG07 F/0q288+y2XIa4FYA/UGh5RtX5Cx7Vp6sMflXC3Cx6UtfrWLXl77r3e2nQJJb7jry0+L sMTtbiOTW+smKQpRXIonkTe3o7nOWHRuJvOTA+wHorGvH6MOlf9SLPFAvCiGE/HqT0j2 xAjg== 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=J5fOk6W7MLHoVg0NQxyE8LwfX9TsPmKwoRbEWwUQF9JNKcTj0ptmNihWRIF49ZoCty 3ibMu22DuEqE6BmeG7lKJrJbCbJEEFi8gdzjwdaTY+PObRYSHjNc6ahDQUCkPNEYKbuW OSV6aDQs/HXtk6VWSOZVy6MO5vzLsOIfBCVmcYSFZnWH6ElfsQeKhJKzZ92FpKKsHO3r krgdW/5vaDPAUfNsBNBXU3BLQrjvn5LakToF9Me8O5XJUQlANH7D7/lZ2n0l4p/hUYik py21C5ZhQsD29erWMfN/OzEMtvd+5DEq5g/+RJfQTqHFLa9KNl5LVR0EfRdgf39ASb4y nP7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=U0XxXbDe; 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 u25si12479645edt.225.2019.11.27.12.51.57; Wed, 27 Nov 2019 12:51:57 -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=U0XxXbDe; 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 S1730540AbfK0Uvx (ORCPT + 26 others); Wed, 27 Nov 2019 15:51:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:38858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728358AbfK0Uvt (ORCPT ); Wed, 27 Nov 2019 15:51:49 -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 3988B21871; Wed, 27 Nov 2019 20:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887908; bh=by66fafWIkFfkatStvHYRKlIhFEru2T56686wGJEHj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0XxXbDeFnHpQm3Yr1y3JgWSudMY/vRnkB+ZQ/s+DLDoq4TFiPM/SbDLD9bRGQyLj rW6cch3B1Ptp1zsCKY86DtQliSNM1C3l5p6h2hLPy2R8KO9Y0g22yDSw+SZO3Ty5n+ BNbBlIjLuCFxxzNyFWyodOBzKNOvwCvfsI9zXKKY= 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.14 100/211] i2c: uniphier-f: fix race condition when IRQ is cleared Date: Wed, 27 Nov 2019 21:30:33 +0100 Message-Id: <20191127203103.134044152@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203049.431810767@linuxfoundation.org> References: <20191127203049.431810767@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 */