Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1027444ybe; Wed, 4 Sep 2019 11:21:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqycQZKUcb2s9V2I2OZRXn1bt2leaaF3dyAap0vKPYHYEPFFRhLgqBPyrqrbyAiw8GChSpXb X-Received: by 2002:a17:90a:c38d:: with SMTP id h13mr6593516pjt.115.1567621310531; Wed, 04 Sep 2019 11:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621310; cv=none; d=google.com; s=arc-20160816; b=wH8JRUCMdcyajjPivi0/kGBqK4sPjOgCbILLGbumngZ9ArFndxbPjsvJ0UMy8ppFif hKiveDnsMMR/Us/+tmXbDFSstk+7+nGfPhNlxGZghjaN80Zs972vx8MVK59b2rVW+veW kGmwTvIkusMQ+l03y3CIhN6TuRC9YQjxJadJF/RBb2xPl4zVMGCz6Izw0v0uFMFxaGaf JObZnWTCHom7v0GYaq+LV3Y9Q3EgjL63/l/ZMDh1NVKBuES2J58Pxe1J9hAECrWnGd62 rwkI4PKxy4aNTGNY/0ltt4kKLz9Vx7jED4C56jUtDzuyQbYvzs0aK1gJyxTVzLGIgtWw GWOQ== 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=rRLEry+2v10wirdQcTXrkUGE6/Kal6OcFLiQTAWWHls=; b=MLA6Mi9C6O89Pm4e/lJNMqykNkGPrWxrZX3fs5SYgdMYjkC5O48dbYtK5P8CDCkQAg XKMhyd8e0RqZVZB+K2qCvaH7AOMWZEhlukcynZMzzZoUyGFOt9wiTfoCIaBGyyHzzI9V vkPsCqDtT4haAhlie3PWS3LcVCE+3yqIeaw52BENQiz+VTf+VC61Fm5IADS1bdSsWUqa 7aURgqyP+Xoe5Tyf55xIdsTf28SDJOch0FX51lhKSqMV6MPROiU3Rzn5LNzjndr20W42 5QBwhiGA1sMvy6zyX3kvGP2gwwpf+HmVdJrWBIbJ83iRDbCoqCt5y5wJnCwsot8KsCmu pZ4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=off4VN96; 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 f1si17806903plj.153.2019.09.04.11.21.35; Wed, 04 Sep 2019 11:21:50 -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=off4VN96; 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 S2389686AbfIDSSw (ORCPT + 99 others); Wed, 4 Sep 2019 14:18:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:54150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389398AbfIDSKb (ORCPT ); Wed, 4 Sep 2019 14:10:31 -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 315B123402; Wed, 4 Sep 2019 18:10:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620630; bh=QrPGqFjmN3VWaRhYMWu04bxZKL55/V7mCxBsqYP8BXM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=off4VN96pARTsLpbj5ZG1CB6HBk+3IlckShiLkN+2IhgnS7Sf925ttmkTqA5/RskY PCT5msAxQS81/Ds7oLtThFxvYOeZeDag624A2cFmn9XodNAdh5mKPsZbgEpE4A16WD sFWepMCcu66x5vxkz5PK9dMIl4RSfJllwIDUlZK0= 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 5.2 036/143] i2c: rcar: avoid race when unregistering slave client Date: Wed, 4 Sep 2019 19:52:59 +0200 Message-Id: <20190904175315.460634723@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@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 d39a4606f72d3..531c01100b560 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -139,6 +139,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) @@ -861,9 +862,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)); @@ -918,7 +921,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; /* Otherwise logic will break because some bytes must always use PIO */ BUILD_BUG_ON_MSG(RCAR_MIN_DMA_LEN < 3, "Invalid min DMA length"); @@ -984,10 +987,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