From patchwork Wed Nov 27 20:30:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 180325 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp6638263ilf; Wed, 27 Nov 2019 12:51:49 -0800 (PST) X-Google-Smtp-Source: APXvYqwQhJNvRd+zc5FyD3eeH1SEED6d03U++xaq4qdBUrZx/KFEOqLnmxgHfxXZV8WMPi2/HzpB X-Received: by 2002:a50:b626:: with SMTP id b35mr34403752ede.183.1574887909149; Wed, 27 Nov 2019 12:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887909; cv=none; d=google.com; s=arc-20160816; b=qsTDwYvdMzzajnigU8t6GEptgWnlTdzLN07LyT8lS/2M4/GLEAQqK+TMFvCnsNy3lh TCLBcLJlrjfdAnhZDdvX/ZtoRwdk1cyDhPHpY+VuwIuAE/CaUi7TNSyc/2Okvnf70Rf/ uZdIL/YcCYvNbdsVH0x9SUWlwR/eOxERLyVcbDckxYZ0oefhtMqx4XoWtNF7X6lQrhso wQ3hM/HriHLvFVM+zeWELM8m7uw3uvaLqtNmoU9mk3k9y7BucpLtUJZ2euo2/mjwkGOZ ZsanPgndHsfbbPpTGc+Tevga90nRZvyoR7e3JG7Vzp3EErRRIRKb8rPd4FVPBFND/iXB Fksw== 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=jz//2/zmF1uLNex+dP9eVNW00/XTGI0+qNVcAIq846Y=; b=i6wasobmremXfP867bcmpSpe9hrEt1I+dhDhZYVlmXsb467RIbiuJbxNP8oOP8nk+v Qr5KLk6pDq7u7No5nEBnM3MAil1RMXLpsX6m9Si3oNrjPawpJi3XmZg5NeXcZdR+Zm30 zltp6HtleS7WbCVQORlReBbw2+BpU/ecY8wqgzWuF95HrUjWbShN4km38fcN36OJE3Lj g+Xq8MEOvnEQlHe9wVzB57EbeABY/zH/1Pn69/zbe3RcY4Sb2i1RY48h+Qs24PiIeVgl aUYDavMSrtgzkNYmZ5n9VTqBKsvqp8SIDMtwzVxP/oA/lomn+nF+PtIZyGjlLFJlIrtP 9Kmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qJ9feTuZ; 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 r8si3932684edp.343.2019.11.27.12.51.48; Wed, 27 Nov 2019 12:51:49 -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=qJ9feTuZ; 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 S1730535AbfK0Uvr (ORCPT + 26 others); Wed, 27 Nov 2019 15:51:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:38632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730519AbfK0Uvo (ORCPT ); Wed, 27 Nov 2019 15:51:44 -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 2832B21850; Wed, 27 Nov 2019 20:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887903; bh=NjWy5znEkoWXqsJzxRB5cmvhQBP3xr8ifrgF/0d3lR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qJ9feTuZMp0dR3VBrbKEQOMG6SYWXAliVWa0ovxYus+yj96FH8T8N+NrAf77SxLC0 JKCjV6SEENcciUcIpJDRhvi0NbHzLRPmmRSV87P3VGnXqD8D4//swaOIVgNLyJ8c6G kHzZz6PBbeQX43rZhpj7qFtxTuh7qepbqJzda6xk= 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 098/211] i2c: uniphier-f: make driver robust against concurrency Date: Wed, 27 Nov 2019 21:30:31 +0100 Message-Id: <20191127203102.959083592@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 f1fdcbbdf45d9609f3d4063b67e9ea941ba3a58f ] This is unlikely to happen, but it is possible for a CPU to enter the interrupt handler just after wait_for_completion_timeout() has expired. If this happens, the hardware is accessed from multiple contexts concurrently. Disable the IRQ after wait_for_completion_timeout(), and do nothing from the handler when the IRQ is disabled. 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 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) -- 2.20.1 diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index bc26ec822e268..b9a0690b4fd73 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -98,6 +98,7 @@ struct uniphier_fi2c_priv { unsigned int flags; unsigned int busy_cnt; unsigned int clk_cycle; + spinlock_t lock; /* IRQ synchronization */ }; static void uniphier_fi2c_fill_txfifo(struct uniphier_fi2c_priv *priv, @@ -162,7 +163,10 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) struct uniphier_fi2c_priv *priv = dev_id; u32 irq_status; + spin_lock(&priv->lock); + irq_status = readl(priv->membase + UNIPHIER_FI2C_INT); + irq_status &= priv->enabled_irqs; dev_dbg(&priv->adap.dev, "interrupt: enabled_irqs=%04x, irq_status=%04x\n", @@ -230,6 +234,8 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) goto handled; } + spin_unlock(&priv->lock); + return IRQ_NONE; data_done: @@ -246,6 +252,8 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) handled: uniphier_fi2c_clear_irqs(priv); + spin_unlock(&priv->lock); + return IRQ_HANDLED; } @@ -311,7 +319,7 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap, { struct uniphier_fi2c_priv *priv = i2c_get_adapdata(adap); bool is_read = msg->flags & I2C_M_RD; - unsigned long time_left; + unsigned long time_left, flags; dev_dbg(&adap->dev, "%s: addr=0x%02x, len=%d, stop=%d\n", is_read ? "receive" : "transmit", msg->addr, msg->len, stop); @@ -342,6 +350,12 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap, priv->membase + UNIPHIER_FI2C_CR); time_left = wait_for_completion_timeout(&priv->comp, adap->timeout); + + spin_lock_irqsave(&priv->lock, flags); + priv->enabled_irqs = 0; + uniphier_fi2c_set_irqs(priv); + spin_unlock_irqrestore(&priv->lock, flags); + if (!time_left) { dev_err(&adap->dev, "transaction timeout.\n"); uniphier_fi2c_recover(priv); @@ -546,6 +560,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev) priv->clk_cycle = clk_rate / bus_speed; init_completion(&priv->comp); + spin_lock_init(&priv->lock); priv->adap.owner = THIS_MODULE; priv->adap.algo = &uniphier_fi2c_algo; priv->adap.dev.parent = dev;