From: Oleksij Rempel <o.rempel@pengutronix.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Oleksij Rempel <linux@rempel-privat.de>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
NXP Linux Team <linux-imx@nxp.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH] i2c: imx: Make sure to unregister adapter on remove()
Date: Fri, 29 Jul 2022 06:29:22 +0200 [thread overview]
Message-ID: <20220729042922.GD30201@pengutronix.de> (raw)
In-Reply-To: <20220720150933.239956-1-u.kleine-koenig@pengutronix.de>
Hi Uwe,
thank you for your work.
On Wed, Jul 20, 2022 at 05:09:33PM +0200, Uwe Kleine-König wrote:
> If for whatever reasons pm_runtime_resume_and_get() fails and .remove() is
> exited early, the i2c adapter stays around and the irq still calls its
> handler, while the driver data and the register mapping go away. So if
> later the i2c adapter is accessed or the irq triggers this results in
> havoc accessing freed memory and unmapped registers.
>
> So unregister the software resources even if resume failed, and only skip
> the hardware access in that case.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Can you please add Fixes tag. I assume this patch can got to stable
kernel version too.
Otherwise:
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> drivers/i2c/busses/i2c-imx.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index e9e2db68b9fb..7395560c13d0 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1572,9 +1572,7 @@ static int i2c_imx_remove(struct platform_device *pdev)
> struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
> int irq, ret;
>
> - ret = pm_runtime_resume_and_get(&pdev->dev);
> - if (ret < 0)
> - return ret;
> + ret = pm_runtime_get_sync(&pdev->dev);
>
> hrtimer_cancel(&i2c_imx->slave_timer);
>
> @@ -1585,17 +1583,21 @@ static int i2c_imx_remove(struct platform_device *pdev)
> if (i2c_imx->dma)
> i2c_imx_dma_free(i2c_imx);
>
> - /* setup chip registers to defaults */
> - imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR);
> - imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IFDR);
> - imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
> - imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
> + if (ret == 0) {
> + /* setup chip registers to defaults */
> + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR);
> + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IFDR);
> + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
> + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
> + clk_disable(i2c_imx->clk);
> + }
>
> 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);
> +
> + clk_unprepare(i2c_imx->clk);
>
> pm_runtime_put_noidle(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
>
> base-commit: 6014cfa5bf32cf8c5c58b3cfd5ee0e1542c8a825
> --
> 2.36.1
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
WARNING: multiple messages have this Message-ID (diff)
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: Oleksij Rempel <linux@rempel-privat.de>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
NXP Linux Team <linux-imx@nxp.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org
Subject: Re: [PATCH] i2c: imx: Make sure to unregister adapter on remove()
Date: Fri, 29 Jul 2022 06:29:22 +0200 [thread overview]
Message-ID: <20220729042922.GD30201@pengutronix.de> (raw)
In-Reply-To: <20220720150933.239956-1-u.kleine-koenig@pengutronix.de>
Hi Uwe,
thank you for your work.
On Wed, Jul 20, 2022 at 05:09:33PM +0200, Uwe Kleine-König wrote:
> If for whatever reasons pm_runtime_resume_and_get() fails and .remove() is
> exited early, the i2c adapter stays around and the irq still calls its
> handler, while the driver data and the register mapping go away. So if
> later the i2c adapter is accessed or the irq triggers this results in
> havoc accessing freed memory and unmapped registers.
>
> So unregister the software resources even if resume failed, and only skip
> the hardware access in that case.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Can you please add Fixes tag. I assume this patch can got to stable
kernel version too.
Otherwise:
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
> drivers/i2c/busses/i2c-imx.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index e9e2db68b9fb..7395560c13d0 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1572,9 +1572,7 @@ static int i2c_imx_remove(struct platform_device *pdev)
> struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev);
> int irq, ret;
>
> - ret = pm_runtime_resume_and_get(&pdev->dev);
> - if (ret < 0)
> - return ret;
> + ret = pm_runtime_get_sync(&pdev->dev);
>
> hrtimer_cancel(&i2c_imx->slave_timer);
>
> @@ -1585,17 +1583,21 @@ static int i2c_imx_remove(struct platform_device *pdev)
> if (i2c_imx->dma)
> i2c_imx_dma_free(i2c_imx);
>
> - /* setup chip registers to defaults */
> - imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR);
> - imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IFDR);
> - imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
> - imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
> + if (ret == 0) {
> + /* setup chip registers to defaults */
> + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR);
> + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IFDR);
> + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
> + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
> + clk_disable(i2c_imx->clk);
> + }
>
> 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);
> +
> + clk_unprepare(i2c_imx->clk);
>
> pm_runtime_put_noidle(&pdev->dev);
> pm_runtime_disable(&pdev->dev);
>
> base-commit: 6014cfa5bf32cf8c5c58b3cfd5ee0e1542c8a825
> --
> 2.36.1
>
>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-07-29 4:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-20 15:09 [PATCH] i2c: imx: Make sure to unregister adapter on remove() Uwe Kleine-König
2022-07-20 15:09 ` Uwe Kleine-König
2022-07-29 4:29 ` Oleksij Rempel [this message]
2022-07-29 4:29 ` Oleksij Rempel
2022-07-30 23:13 ` Uwe Kleine-König
2022-07-30 23:13 ` Uwe Kleine-König
2022-08-21 8:41 ` Wolfram Sang
2022-08-21 8:41 ` Wolfram Sang
2022-08-20 6:47 ` Wolfram Sang
2022-08-20 6:47 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220729042922.GD30201@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=festevam@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux@rempel-privat.de \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.