Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1011844ybe; Wed, 4 Sep 2019 11:07:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYPDruj2Fu0tNSuPr/wgND7noQr66h8a0TmCtFvvP8Ib/DyvTknEIP+/c+dIo4D8tpew/M X-Received: by 2002:a17:90a:bf0a:: with SMTP id c10mr6254503pjs.78.1567620449145; Wed, 04 Sep 2019 11:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620449; cv=none; d=google.com; s=arc-20160816; b=lx3ChObJZwXApM/rezK2sOMRI63uSaPTyC7t+vaEbLTvsZLt4iAkMDycTsOyfIb2dq 7UB/Alh7iIUWkx/Am8OxuTlt+qh7KHK0QC38/oIaavbkRk4AYNRn/FS5uBU6MwtWjf2b 5HuzyGRh/Ytcp20TIBVkK8DJgTQZ0tVMrPjHZPQFqu81laP9/ORCtRcEoBEhJEdwPmpi qwh9mvTDU1C8/PzUAoIQXKOQ06M+r83dnEAYgqvd5hC3dt9b0I1gv6B+7SjNYvsEOGkY BcJO2B104ahQxyfCXSZmLEsEDPS7i/zIqb4qYWLv0WNOwOv01HS6UsY8Cxe5+KhDFdl2 ptTQ== 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=kyu+v+H+cTMUoZVILWWKBIZY567Pn1GsARrumD+/5bg=; b=1Ahwkro7cOLFsQ5JqE4g9NA4Pu6N6/G+nR2jE20hzBdSxAc+9bx6ArtEugk9JiptK3 OshMluqqbcr2cIzEhsAdqr7AGvkQlr3DaocKD/aSSQtLc8LOX1KyQ3NE+VIIdt2Vw/A0 YfdqLMjjBDUx9U9QiWQSOIvmstIx2bRaAoRtGhEy6DkVWKxpo7oT0ynbGpVUj8KsuZ2h Vg1i2pa0XGbye6zN9dW6sA42j/Dqze6mtaTMSCN2SC31nrbc4ROp+wKYFr03OFWxnTuh oVIz5E9feR2MgHtp/QKJjLcSEoVNRPfzgK0iXcC+udOov+Qy0sSZ0AIuVsXBFquf5UPF lNfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uOTMg0Rx; 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 h14si2762918pjt.78.2019.09.04.11.07.11; Wed, 04 Sep 2019 11:07:29 -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=uOTMg0Rx; 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 S2388709AbfIDSEP (ORCPT + 99 others); Wed, 4 Sep 2019 14:04:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:45148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388462AbfIDSEM (ORCPT ); Wed, 4 Sep 2019 14:04:12 -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 6F96D206BA; Wed, 4 Sep 2019 18:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620251; bh=z7dm4AA2ULE5iGAB7SozRx/Ck4WKdrAiJM6pw+ys/ac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uOTMg0RxpRuf9kHGXIrsQzOkYnkE3Iqvqn4GByC7e8qRqQ/m9XOv9zKb4EWLEwP3+ 7N1zpfVPFaPXXalkbv3nT4BWHp6WEgE8VIvAOJg63mTqmsP8uaVFafp9OVlC6B5obM 7bglJFiXyPVSKQXp8eKYMVPhR+tg8EVBaicSWQvE= 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 08/57] i2c: emev2: avoid race when unregistering slave client Date: Wed, 4 Sep 2019 19:53:36 +0200 Message-Id: <20190904175302.770724586@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 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 d2e84480fbe96..dd97e5d9f49a2 100644 --- a/drivers/i2c/busses/i2c-emev2.c +++ b/drivers/i2c/busses/i2c-emev2.c @@ -72,6 +72,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) @@ -342,6 +343,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; @@ -358,7 +365,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) @@ -393,8 +400,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; @@ -404,7 +411,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