linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call().
@ 2018-12-03 11:13 Krzysztof Hałasa
  2018-12-03 11:21 ` Fabio Estevam
  0 siblings, 1 reply; 6+ messages in thread
From: Krzysztof Hałasa @ 2018-12-03 11:13 UTC (permalink / raw)
  To: lkml, linux-arm-kernel, linux-i2c, Lucas Stach

Signed-off-by: Krzysztof Halasa <khalasa@piap.pl>

--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -510,9 +510,9 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
 				     unsigned long action, void *data)
 {
 	struct clk_notifier_data *ndata = data;
-	struct imx_i2c_struct *i2c_imx = container_of(&ndata->clk,
+	struct imx_i2c_struct *i2c_imx = container_of(nb,
 						      struct imx_i2c_struct,
-						      clk);
+						      clk_change_nb);
 
 	if (action & POST_RATE_CHANGE)
 		i2c_imx_set_clk(i2c_imx, ndata->new_rate);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call().
  2018-12-03 11:13 [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call() Krzysztof Hałasa
@ 2018-12-03 11:21 ` Fabio Estevam
  2018-12-03 13:28   ` Krzysztof Hałasa
  2018-12-17  9:12   ` Krzysztof Hałasa
  0 siblings, 2 replies; 6+ messages in thread
From: Fabio Estevam @ 2018-12-03 11:21 UTC (permalink / raw)
  To: Krzysztof Hałasa
  Cc: linux-kernel,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-i2c, Lucas Stach

Hi Krzysztof,

On Mon, Dec 3, 2018 at 9:13 AM Krzysztof Hałasa <khalasa@piap.pl> wrote:
>
> Signed-off-by: Krzysztof Halasa <khalasa@piap.pl>

Please provide a commit log, giving some context to your fix.

Is this a regression?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call().
  2018-12-03 11:21 ` Fabio Estevam
@ 2018-12-03 13:28   ` Krzysztof Hałasa
  2018-12-17  9:12   ` Krzysztof Hałasa
  1 sibling, 0 replies; 6+ messages in thread
From: Krzysztof Hałasa @ 2018-12-03 13:28 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: linux-kernel,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-i2c, Lucas Stach

Hi Fabio,

Fabio Estevam <festevam@gmail.com> writes:

> Please provide a commit log, giving some context to your fix.

Well, I hope Lucas could add something here. I am uncertain how it was
supposed to work, the ndata->clk (the pointer, not the clk pointed by
it) can't be at the same time a member of imx_i2c_struct, and I believe
the macro only does simple arithmetics to get to the outer struct.

@@ -510,9 +510,9 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
 				     unsigned long action, void *data)
 {
 	struct clk_notifier_data *ndata = data;
-	struct imx_i2c_struct *i2c_imx = container_of(&ndata->clk,
+	struct imx_i2c_struct *i2c_imx = container_of(nb,
 						      struct imx_i2c_struct,
-						      clk);
+						      clk_change_nb);

> Is this a regression?

Probably (it went in between 4.16 and 4.17, commit id is
90ad2cbe88c22d0215225ab9594eeead0eb24fde). However this part may be
unused on many boards (apparently it only fires up if the "IPG" clock
rate changes), so it may not manifest itself. I only hit it when I added
a custom driver (using/requesting a special clock derived from IPG).
-- 
Krzysztof Halasa

Industrial Research Institute for Automation and Measurements PIAP
Al. Jerozolimskie 202, 02-486 Warsaw, Poland

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call().
  2018-12-03 11:21 ` Fabio Estevam
  2018-12-03 13:28   ` Krzysztof Hałasa
@ 2018-12-17  9:12   ` Krzysztof Hałasa
  2018-12-17  9:26     ` Uwe Kleine-König
  2018-12-17 23:02     ` Peter Rosin
  1 sibling, 2 replies; 6+ messages in thread
From: Krzysztof Hałasa @ 2018-12-17  9:12 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: linux-kernel,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-i2c, Lucas Stach

90ad2cbe88c22d0215225ab9594eeead0eb24fde changed the i.MX I2C bus driver
to use a notifier whenever the base clock ("ipg" - 66 MHz peripheral
clock) rate changes.

Unfortunately one can't use the container_of() macro this way - the
first argument has to point to a member of the bigger struct (last
argument). Merely pointing to the same value isn't enough (the clk
variable which has its address passed to the macro is the clk in
notifier_block, not the one in imx_i2c_struct, even though both pointers
point to the same clk struct).

This bug causes kernel panic when the IPG clock rate changes (e.g. if
any clock derived from IPG changes).

Signed-off-by: Krzysztof Halasa <khalasa@piap.pl>

--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -510,9 +510,9 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
 				     unsigned long action, void *data)
 {
 	struct clk_notifier_data *ndata = data;
-	struct imx_i2c_struct *i2c_imx = container_of(&ndata->clk,
+	struct imx_i2c_struct *i2c_imx = container_of(nb,
 						      struct imx_i2c_struct,
-						      clk);
+						      clk_change_nb);
 
 	if (action & POST_RATE_CHANGE)
 		i2c_imx_set_clk(i2c_imx, ndata->new_rate);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call().
  2018-12-17  9:12   ` Krzysztof Hałasa
@ 2018-12-17  9:26     ` Uwe Kleine-König
  2018-12-17 23:02     ` Peter Rosin
  1 sibling, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2018-12-17  9:26 UTC (permalink / raw)
  To: Krzysztof Hałasa
  Cc: Fabio Estevam, linux-kernel,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-i2c, Lucas Stach

On Mon, Dec 17, 2018 at 10:12:14AM +0100, Krzysztof Hałasa wrote:
> 90ad2cbe88c22d0215225ab9594eeead0eb24fde changed the i.MX I2C bus driver
> to use a notifier whenever the base clock ("ipg" - 66 MHz peripheral
> clock) rate changes.
> 
> Unfortunately one can't use the container_of() macro this way - the
> first argument has to point to a member of the bigger struct (last
> argument). Merely pointing to the same value isn't enough (the clk
> variable which has its address passed to the macro is the clk in
> notifier_block, not the one in imx_i2c_struct, even though both pointers
> point to the same clk struct).
> 
> This bug causes kernel panic when the IPG clock rate changes (e.g. if
> any clock derived from IPG changes).
> 
> Signed-off-by: Krzysztof Halasa <khalasa@piap.pl>

I didn't look at the patch, but I suggest a Fixes: line here à la:

Fixes: 90ad2cbe88c2 ("i2c: imx: use clk notifier for rate changes")

Best regards
Uwe
 
-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call().
  2018-12-17  9:12   ` Krzysztof Hałasa
  2018-12-17  9:26     ` Uwe Kleine-König
@ 2018-12-17 23:02     ` Peter Rosin
  1 sibling, 0 replies; 6+ messages in thread
From: Peter Rosin @ 2018-12-17 23:02 UTC (permalink / raw)
  To: Krzysztof Hałasa, Fabio Estevam
  Cc: linux-kernel,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-i2c, Lucas Stach

On 2018-12-17 10:12, Krzysztof Hałasa wrote:
> 90ad2cbe88c22d0215225ab9594eeead0eb24fde changed the i.MX I2C bus driver

This reference should ideally be in a fixes-tag, below...

> to use a notifier whenever the base clock ("ipg" - 66 MHz peripheral
> clock) rate changes.
> 
> Unfortunately one can't use the container_of() macro this way - the
> first argument has to point to a member of the bigger struct (last
> argument). Merely pointing to the same value isn't enough (the clk
> variable which has its address passed to the macro is the clk in
> notifier_block, not the one in imx_i2c_struct, even though both pointers
> point to the same clk struct).
> 
> This bug causes kernel panic when the IPG clock rate changes (e.g. if
> any clock derived from IPG changes).
> 

...right here.

Fixes: 90ad2cbe88c2 ("i2c: imx: use clk notifier for rate changes")
> Signed-off-by: Krzysztof Halasa <khalasa@piap.pl>
> 
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -510,9 +510,9 @@ static int i2c_imx_clk_notifier_call(struct notifier_block *nb,
>  				     unsigned long action, void *data)
>  {
>  	struct clk_notifier_data *ndata = data;
> -	struct imx_i2c_struct *i2c_imx = container_of(&ndata->clk,
> +	struct imx_i2c_struct *i2c_imx = container_of(nb,
>  						      struct imx_i2c_struct,
> -						      clk);
> +						      clk_change_nb);
>  
>  	if (action & POST_RATE_CHANGE)
>  		i2c_imx_set_clk(i2c_imx, ndata->new_rate);
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-12-17 23:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03 11:13 [PATCH] ARM i.MX: Fix a kernel panic in i2c_imx_clk_notifier_call() Krzysztof Hałasa
2018-12-03 11:21 ` Fabio Estevam
2018-12-03 13:28   ` Krzysztof Hałasa
2018-12-17  9:12   ` Krzysztof Hałasa
2018-12-17  9:26     ` Uwe Kleine-König
2018-12-17 23:02     ` Peter Rosin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).