Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1029446ybe; Wed, 4 Sep 2019 11:23:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9RMlsBWfscqI2AYOt8Gfm1332nuYdX6tpR1jk2cpYeeADBZRUYclr2oSkwac8eFXi6C7b X-Received: by 2002:a17:902:b082:: with SMTP id p2mr20617896plr.334.1567621424365; Wed, 04 Sep 2019 11:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621424; cv=none; d=google.com; s=arc-20160816; b=BBz5/T/EnY0cfZ3EyE4SPgSLCcZs7yooe1VatUHiQERjoPfNjOEG77JJh7PRrCw4/J nxB4dfNPy53fLN+fjVFuy2NnJTXnyQEAE2ShGXF73bA/APBdrNmwUk1SAt882Ko6pmJm BWIR0Z+OzqGXhkrhHSTr1276RaPdTIg3ym1URsxpOFhPZ432d6QhrGhYpR7hwwqCCfxp 5YmcdYvO3ziE83RglyTvCfndOA9CV5cVRicfYUqNMRsVV1D9xwbgR7AMgIQ8zQWJbWk2 8aVZliddzsJIHrtfaKXnyzSlwoVyWZ1EWNzfgF/e9r3CIrAY3O/fc1OBtclZd8n9T5lB cTJw== 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=+Y6rsIzInctuCsa96p3AfPIxxHAm8n4TjzDNqpQzlwQ=; b=vQP987EUZQLRJBF2mS1wyqqjQsrnWIbSzj8l39ZDlkgLQwyj1eye+y0I02kOzikQxi lrajmIW1i5Hu7oS2rHrOifmfTERE8NVuVHymmMCVkxRFzPUllYBobBOuxN0/vc/1zO5C COZQdJ7eTi0kJYdlLm4IJK7FFICn8+uk4AeYlCnRcI4CAdc01FyaS4SWDbh4bnqBiKE9 Xwvrq1u7CXuzioI2ghnop7DF1mWei+mLBo3iLv4/o6HT3+lUOCTVccCRj6R8NZ3LLsaj ycljHXdqJWk2yp/FClZzbouY38Cpd2zQpmPvMC5kb2e/lw3PcW0gKpsuhONQheaKilk1 NtQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EVyLrUNa; 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 m184si21890077pfb.127.2019.09.04.11.23.28; Wed, 04 Sep 2019 11:23:44 -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=EVyLrUNa; 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 S2388002AbfIDSFm (ORCPT + 99 others); Wed, 4 Sep 2019 14:05:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:47246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389297AbfIDSFk (ORCPT ); Wed, 4 Sep 2019 14:05:40 -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 421E723404; Wed, 4 Sep 2019 18:05:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620339; bh=nWGqu5LvfO5GpMioG9+wuNyHYM4Bt3PWimoGc8ZaEzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EVyLrUNaogrtJVa5TiSUfiuNh78a/oIbih4lRHanVwuhEBsSe8dSthp9+Lq4Ks5+W 15RxuZdzXZleVkkhwbIAX02ymZaqOZENDvMzHdAAT1zQt3OV7B7ZO2UMrtJSbnGpXR k8Jhqa3TlrzzeJuCqghinZu4fk7uW2rf+LMC3P9s= 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.19 21/93] i2c: emev2: avoid race when unregistering slave client Date: Wed, 4 Sep 2019 19:53:23 +0200 Message-Id: <20190904175305.131987137@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@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 d7437fc0d8291181debe032671a289b6bd93f46f ] After we disabled interrupts, there might still be an active one running. Sync before clearing the pointer to the slave device. Fixes: c31d0a00021d ("i2c: emev2: 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-emev2.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-emev2.c b/drivers/i2c/busses/i2c-emev2.c index 35b302d983e0d..959d4912ec0d5 100644 --- a/drivers/i2c/busses/i2c-emev2.c +++ b/drivers/i2c/busses/i2c-emev2.c @@ -69,6 +69,7 @@ struct em_i2c_device { struct completion msg_done; struct clk *sclk; struct i2c_client *slave; + int irq; }; static inline void em_clear_set_bit(struct em_i2c_device *priv, u8 clear, u8 set, u8 reg) @@ -339,6 +340,12 @@ static int em_i2c_unreg_slave(struct i2c_client *slave) writeb(0, priv->base + I2C_OFS_SVA0); + /* + * Wait for interrupt to finish. New slave irqs cannot happen because we + * cleared the slave address and, thus, only extension codes will be + * detected which do not use the slave ptr. + */ + synchronize_irq(priv->irq); priv->slave = NULL; return 0; @@ -355,7 +362,7 @@ static int em_i2c_probe(struct platform_device *pdev) { struct em_i2c_device *priv; struct resource *r; - int irq, ret; + int ret; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -390,8 +397,8 @@ static int em_i2c_probe(struct platform_device *pdev) em_i2c_reset(&priv->adap); - irq = platform_get_irq(pdev, 0); - ret = devm_request_irq(&pdev->dev, irq, em_i2c_irq_handler, 0, + priv->irq = platform_get_irq(pdev, 0); + ret = devm_request_irq(&pdev->dev, priv->irq, em_i2c_irq_handler, 0, "em_i2c", priv); if (ret) goto err_clk; @@ -401,7 +408,8 @@ static int em_i2c_probe(struct platform_device *pdev) if (ret) goto err_clk; - dev_info(&pdev->dev, "Added i2c controller %d, irq %d\n", priv->adap.nr, irq); + dev_info(&pdev->dev, "Added i2c controller %d, irq %d\n", priv->adap.nr, + priv->irq); return 0; -- 2.20.1