Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp821991pxb; Tue, 3 Nov 2020 13:31:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRK9yR4uahFufp219Mh87UnA2HUQOpqHMqCkpiwktQq8R71CCK6dw+JMxbgrTMughqqxrr X-Received: by 2002:a17:906:5d9:: with SMTP id t25mr21659858ejt.443.1604439086250; Tue, 03 Nov 2020 13:31:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439086; cv=none; d=google.com; s=arc-20160816; b=dKHwjWDRNW3npIJFkF667tnc+eIIG2i8g3dtxr3kCPIAV9Oq61iDzaCGucFFv9z+jA MBcCEfW1FgEK9iDif/cTSCaS9VxLXYsNaneoEUq6ggeimx8z/f/Eiowaz/e0s3qp8JH1 fSdE/7WWIl3e7WfN/b81n2Xja5vq6Ze6D+aUvHlYQPlTBpKhfIWRcXn77GisTJxck/sx NTB5S4WIVjBIKnwcqthYuIqaWYpOIWbnSrlmahOaG490bP/BiQYXXfJOzo/tag76rZ1O OCM+7St8pFuiZOz5t/MyiqTah1JBDVzt3RDoakZRhWGNYL9IHyWxHi+hCqNDfVGametu xufQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6nUuiHsir0WbIoEmkPX08CwLl1s7xMqMu1n+nBIqqko=; b=j0ca0VXCkTmjfHumS33M1v9DTOxZFEdf7b08Xicg/Zh/0qNkYZe6RyW0DWIS8m3mVK xidbFtotsreT1RtKZxmpYhEfd5vdLk0RRxT1zZXQ2g28meXUfkKeVEvXgjN3h9qr2Ein D3C5Ss2yQNjqe9CgZq6iu4yJB8zgSlFhv9cl3l/LjQF4MKJCRQldrHGKOrgT+z6pbxY0 H88OAtHvBfGy17aXU+WcifTHwLZSTAfcm4pxivNflfj1v5Ge6acn4pDgDPcbfTOwv0r/ Fp5/GM9c89NmcvtZvMiO3oMHnqtmeJpUREqQ6pNlr79/vp48W/frOtQMdA8L/Q3ouA9c g+5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qxXbr3gy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g20si13845305edh.74.2020.11.03.13.31.03; Tue, 03 Nov 2020 13:31:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qxXbr3gy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733130AbgKCU7h (ORCPT + 99 others); Tue, 3 Nov 2020 15:59:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:34818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733127AbgKCU7f (ORCPT ); Tue, 3 Nov 2020 15:59:35 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 3DE92223BF; Tue, 3 Nov 2020 20:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437174; bh=e3pIQklkuXClRWrEvopYDzeRgS2OVox/GzU7rsgoGyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qxXbr3gy4dMuzCCC9VKGNc2zmVEkRTQyR/2FsyM/LmpWfxhKvsDq9QdyBkmGxBZpN HCqFZIUpbe8Y8hnbyVoyDmDorDDRNcorYRIgSobcEiDlcfiN7CfNVKD1kmrtRwmbxf t5M8EAqXHDUhgDmmDS9XCBSy934hBUSID2OV3biw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Krzysztof Kozlowski , Oleksij Rempel , Wolfram Sang Subject: [PATCH 5.4 178/214] i2c: imx: Fix external abort on interrupt in exit paths Date: Tue, 3 Nov 2020 21:37:06 +0100 Message-Id: <20201103203307.402769742@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Krzysztof Kozlowski commit e50e4f0b85be308a01b830c5fbdffc657e1a6dd0 upstream. If interrupt comes late, during probe error path or device remove (could be triggered with CONFIG_DEBUG_SHIRQ), the interrupt handler i2c_imx_isr() will access registers with the clock being disabled. This leads to external abort on non-linefetch on Toradex Colibri VF50 module (with Vybrid VF5xx): Unhandled fault: external abort on non-linefetch (0x1008) at 0x8882d003 Internal error: : 1008 [#1] ARM Modules linked in: CPU: 0 PID: 1 Comm: swapper Not tainted 5.7.0 #607 Hardware name: Freescale Vybrid VF5xx/VF6xx (Device Tree) (i2c_imx_isr) from [<8017009c>] (free_irq+0x25c/0x3b0) (free_irq) from [<805844ec>] (release_nodes+0x178/0x284) (release_nodes) from [<80580030>] (really_probe+0x10c/0x348) (really_probe) from [<80580380>] (driver_probe_device+0x60/0x170) (driver_probe_device) from [<80580630>] (device_driver_attach+0x58/0x60) (device_driver_attach) from [<805806bc>] (__driver_attach+0x84/0xc0) (__driver_attach) from [<8057e228>] (bus_for_each_dev+0x68/0xb4) (bus_for_each_dev) from [<8057f3ec>] (bus_add_driver+0x144/0x1ec) (bus_add_driver) from [<80581320>] (driver_register+0x78/0x110) (driver_register) from [<8010213c>] (do_one_initcall+0xa8/0x2f4) (do_one_initcall) from [<80c0100c>] (kernel_init_freeable+0x178/0x1dc) (kernel_init_freeable) from [<80807048>] (kernel_init+0x8/0x110) (kernel_init) from [<80100114>] (ret_from_fork+0x14/0x20) Additionally, the i2c_imx_isr() could wake up the wait queue (imx_i2c_struct->queue) before its initialization happens. The resource-managed framework should not be used for interrupt handling, because the resource will be released too late - after disabling clocks. The interrupt handler is not prepared for such case. Fixes: 1c4b6c3bcf30 ("i2c: imx: implement bus recovery") Cc: Signed-off-by: Krzysztof Kozlowski Acked-by: Oleksij Rempel Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-imx.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -1112,14 +1112,6 @@ static int i2c_imx_probe(struct platform return ret; } - /* Request IRQ */ - ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, IRQF_SHARED, - pdev->name, i2c_imx); - if (ret) { - dev_err(&pdev->dev, "can't claim irq %d\n", irq); - goto clk_disable; - } - /* Init queue */ init_waitqueue_head(&i2c_imx->queue); @@ -1138,6 +1130,14 @@ static int i2c_imx_probe(struct platform if (ret < 0) goto rpm_disable; + /* Request IRQ */ + ret = request_threaded_irq(irq, i2c_imx_isr, NULL, IRQF_SHARED, + pdev->name, i2c_imx); + if (ret) { + dev_err(&pdev->dev, "can't claim irq %d\n", irq); + goto rpm_disable; + } + /* Set up clock divider */ i2c_imx->bitrate = IMX_I2C_BIT_RATE; ret = of_property_read_u32(pdev->dev.of_node, @@ -1180,13 +1180,12 @@ static int i2c_imx_probe(struct platform clk_notifier_unregister: clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); + free_irq(irq, i2c_imx); rpm_disable: pm_runtime_put_noidle(&pdev->dev); pm_runtime_disable(&pdev->dev); pm_runtime_set_suspended(&pdev->dev); pm_runtime_dont_use_autosuspend(&pdev->dev); - -clk_disable: clk_disable_unprepare(i2c_imx->clk); return ret; } @@ -1194,7 +1193,7 @@ clk_disable: static int i2c_imx_remove(struct platform_device *pdev) { struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); - int ret; + int irq, ret; ret = pm_runtime_get_sync(&pdev->dev); if (ret < 0) @@ -1214,6 +1213,9 @@ static int i2c_imx_remove(struct platfor imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR); clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); + irq = platform_get_irq(pdev, 0); + if (irq >= 0) + free_irq(irq, i2c_imx); clk_disable_unprepare(i2c_imx->clk); pm_runtime_put_noidle(&pdev->dev);