Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1017495ybe; Wed, 4 Sep 2019 11:12:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHSOvE4yHOx/rnmim1XrdxQ+VkUUZ8HBD65oL+tRN0fMU3oVzN6DODezPSIJMIV+qU0fml X-Received: by 2002:a63:b919:: with SMTP id z25mr35774621pge.201.1567620735440; Wed, 04 Sep 2019 11:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620735; cv=none; d=google.com; s=arc-20160816; b=Gf1CR+OgZ+Spm54BuQa0jOtu2eI+nf+TsD6iGslmGz4M4tm7B2+7PlKbz8ULCLOrVh 9zo9GDUw+KuBFJxJ/Y/fRkkNaEtJdLdoOc6l4syaU7Fa+DYDU+RsbgY3cDuyrrM3Bblb 2PH7zHh5f/9xUYlHnrBjGBMedr1h5Qd19v8oVrZgTDHQqNVPnbhZQ47dueaiv3BldDBE 0H+Kc3lhGEZzCJopsWlpMUgmY6lBU9IGcNcSydAI36efP2m8VwW5g4Z72OjR4qDUa0zt 1fkJLEY6ZS2ZAL3TsDtKEgVP/QlseHqmBqWYcaLQeCkiOHRv7qNWg7nJcyMHqS6zOt23 jqwg== 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=jaNI7J85tkxnDnJkee8iUtV45lw0n7WpAUl2ADwdBzRQNJqmTSdYiAz6OpJluHPqbw NARu+hAA/9P6i5V4M0FWjUz49mk6nJkPHgpZu/H3YG53hBJw5crz0IrYZdULuf+b6TvU e5eX4Q/8Oq/3m4Gmyt7Qbg0vaNSEJTrDcYjolBU1cEaowg2iSdAUqyMn24C5N5EKykz0 9dT62ThuFez/kXMVpCTjhgbji0Ha1447uSwlVGuP0mwMI0FPyQsLig0SoMR1FS/p8/tO /BqgIdFioAxRS7UWk3dQgrg8H0u9OjodfvUmyhIQeqr42XJtpHGPz0NVllfFnb0GBOOO hgSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KP0tfksl; 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 d13si21225387pfo.33.2019.09.04.11.11.59; Wed, 04 Sep 2019 11:12:15 -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=KP0tfksl; 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 S2389793AbfIDSKf (ORCPT + 99 others); Wed, 4 Sep 2019 14:10:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:54222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390085AbfIDSKe (ORCPT ); Wed, 4 Sep 2019 14:10:34 -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 E5CEB206BA; Wed, 4 Sep 2019 18:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620633; bh=nWGqu5LvfO5GpMioG9+wuNyHYM4Bt3PWimoGc8ZaEzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KP0tfkslv1eRztfuAl4VEbGQZqrxme9iSnD/3obP5QBz7c9t4ULDnVd2HL0zVH+pk mDYg4P+vi57f8+Rw6mN0bVCweTgTl4zP1Iyl1VFiL3Kep7HOGcHjJo9O9zkDIW/y8m 1M6K1jATvubNXTAvsQ9UzT7XAxge60ZSZAQKzyaI= 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 037/143] i2c: emev2: avoid race when unregistering slave client Date: Wed, 4 Sep 2019 19:53:00 +0200 Message-Id: <20190904175315.498967852@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 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