Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1031214ybe; Wed, 4 Sep 2019 11:25:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqysZMr9JzQ8eiZk/OE3WQ6zw08Ag36apO9yLwRjXVowwMVm95I2fVS++mkZzt0cCzE80oQF X-Received: by 2002:a17:90a:3d03:: with SMTP id h3mr6470039pjc.49.1567621546378; Wed, 04 Sep 2019 11:25:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621546; cv=none; d=google.com; s=arc-20160816; b=fZyhBf+eyAIYW5T9VjAzKyMoBlM/s8UHvBaH+x1rTjWsvFsuMyMfZFrY6xtE/JWzGT T3LyMRRHsKK0yVMMHvXm2i3YChftFjenKnVXWWdillyCxgzpAmRH71W5zN4i0lr0uaDG ZTamq7ec9GC2cdXNyEDOL/p3PyTR9i9RUPnCdrOqAszYhmTy+Q9OaY7CMRAPMMu+ellc V2WcygWeiQRGbiJseSqen1TpzDdn50K7aAmE5Ur99lg5z1d92GYlpDAQtGHqeQYcxz+E onBjV11kuSvUrRDtf4kNpyjL4ejCnO4hntktGT7wgziKBrx/RSO01SyYKYo6fN595lUB Jrow== 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=4jTB2CJdLsZTseGA1CpXWisXhnlvwPlyt87IhAUZ9tw=; b=rW1JsWj5XfXbS+oR6dCi4wtFc0flCUaGXo3hUqAPL7MriNlBHoTdslWeOEuO5DvWBY PseFGyzBQtDTuBG15GXW86GKWqHVm0aDNYTeJr8biVDRYFALAPcFlKaHqlhZaONR89fT OD+g+vDqdGS8s/Ga02aJXPVtlDyNaXqxnomKvMpZDjSJOzn0VQcTMlkoI4dByliZXy++ oTYr6KWIo9kXT7rklPTtEM7X2je49g9VGb4+QnQy/bMCd0ymEDCzmP27lOU8Xk3cjRFz DwQTgbK6+EQjJxKsIuqStu59Zx4A3jhUjMsOJ5qEV7nB9/vINsem4YakhJSiaBzvZXdL ivlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TjyhN9xZ; 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 g92si8487393plg.49.2019.09.04.11.25.30; Wed, 04 Sep 2019 11:25:46 -0700 (PDT) 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=TjyhN9xZ; 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 S2389329AbfIDSWp (ORCPT + 99 others); Wed, 4 Sep 2019 14:22:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:45102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388346AbfIDSEJ (ORCPT ); Wed, 4 Sep 2019 14:04:09 -0400 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 C581E208E4; Wed, 4 Sep 2019 18:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620249; bh=bDqaOAqZaQ/yWjCQx8MNS98le6D4MfuFmZmP7M9nAeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TjyhN9xZs3JAu+cJ7EA1oNbck3zEd28jp1+YUgNjEBvbtKjecV0Y7LvzT+BKtR9sO LeMkiqqhNpxUbv6n/q+aCv9Me7/NJ3Y/ypkgyLwhvd9xQTL3jPcIKE3+whaBZMxDK1 +5OwIe2pf2ejJtURlr9mgMn/0J9+xqLwx6vtSJeQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Krzysztof Adamski , Wolfram Sang , Wolfram Sang , Sasha Levin Subject: [PATCH 4.14 07/57] i2c: rcar: avoid race when unregistering slave client Date: Wed, 4 Sep 2019 19:53:35 +0200 Message-Id: <20190904175302.625496869@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175301.777414715@linuxfoundation.org> References: <20190904175301.777414715@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 [ Upstream commit 7b814d852af6944657c2961039f404c4490771c0 ] After we disabled interrupts, there might still be an active one running. Sync before clearing the pointer to the slave device. Fixes: de20d1857dd6 ("i2c: rcar: add slave support") Reported-by: Krzysztof Adamski Signed-off-by: Wolfram Sang Reviewed-by: Krzysztof Adamski Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-rcar.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 3415733a93645..132c4a405bf83 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -144,6 +144,7 @@ struct rcar_i2c_priv { enum dma_data_direction dma_direction; struct reset_control *rstc; + int irq; }; #define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent) @@ -813,9 +814,11 @@ static int rcar_unreg_slave(struct i2c_client *slave) WARN_ON(!priv->slave); + /* disable irqs and ensure none is running before clearing ptr */ rcar_i2c_write(priv, ICSIER, 0); rcar_i2c_write(priv, ICSCR, 0); + synchronize_irq(priv->irq); priv->slave = NULL; pm_runtime_put(rcar_i2c_priv_to_dev(priv)); @@ -866,7 +869,7 @@ static int rcar_i2c_probe(struct platform_device *pdev) struct i2c_adapter *adap; struct device *dev = &pdev->dev; struct i2c_timings i2c_t; - int irq, ret; + int ret; priv = devm_kzalloc(dev, sizeof(struct rcar_i2c_priv), GFP_KERNEL); if (!priv) @@ -927,10 +930,10 @@ static int rcar_i2c_probe(struct platform_device *pdev) pm_runtime_put(dev); - irq = platform_get_irq(pdev, 0); - ret = devm_request_irq(dev, irq, rcar_i2c_irq, 0, dev_name(dev), priv); + priv->irq = platform_get_irq(pdev, 0); + ret = devm_request_irq(dev, priv->irq, rcar_i2c_irq, 0, dev_name(dev), priv); if (ret < 0) { - dev_err(dev, "cannot get irq %d\n", irq); + dev_err(dev, "cannot get irq %d\n", priv->irq); goto out_pm_disable; } -- 2.20.1