mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 1/1] i2c: mpc: Fix timeout calculations
@ 2026-06-18 14:49 Andy Shevchenko
  2026-06-18 21:26 ` Chris Packham
  2026-06-23 15:37 ` Andi Shyti
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2026-06-18 14:49 UTC (permalink / raw)
  To: Andy Shevchenko, linux-i2c, linux-kernel
  Cc: Chris Packham, Andi Shyti, stable

ON the first glance the harmless cleanup of the driver does nothing bad.
However, as the operator precedence list states the '*' (multiplication)
and '/' division operators have order 5 with left-to-right associativity
the *= has order 17 and associativity right-to-left. It wouldn't not be
a problem to replace

	foo = foo * HZ / 1000000;

with

	foo *= HZ / 1000000;

if HZ constant is in Hertz. The problem is that in the Linux kernel HZ is
defined in jiffy units, which is order of magnitude smaller than a million.
That's why operator precedence has a crucial role here. Fix the regression
by reverting pre-optimized calculations.

Fixes: be40a3ae719f ("i2c: mpc: Use of_property_read_u32 instead of of_get_property")
Cc: stable@vger.kernel.org
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-mpc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 28c5c5c1fb7a..a21fa45bd64c 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -844,7 +844,7 @@ static int fsl_i2c_probe(struct platform_device *op)
 					      "fsl,timeout", &mpc_ops.timeout);
 
 	if (!result) {
-		mpc_ops.timeout *= HZ / 1000000;
+		mpc_ops.timeout = mpc_ops.timeout * HZ / 1000000;
 		if (mpc_ops.timeout < 5)
 			mpc_ops.timeout = 5;
 	} else {
-- 
2.50.1


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

* Re: [PATCH v1 1/1] i2c: mpc: Fix timeout calculations
  2026-06-18 14:49 [PATCH v1 1/1] i2c: mpc: Fix timeout calculations Andy Shevchenko
@ 2026-06-18 21:26 ` Chris Packham
  2026-06-23 15:37 ` Andi Shyti
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Packham @ 2026-06-18 21:26 UTC (permalink / raw)
  To: Andy Shevchenko, linux-i2c, linux-kernel; +Cc: Andi Shyti, stable

Hi Andy,

On 19/06/2026 02:49, Andy Shevchenko wrote:
> ON the first glance the harmless cleanup of the driver does nothing bad.
> However, as the operator precedence list states the '*' (multiplication)
> and '/' division operators have order 5 with left-to-right associativity
> the *= has order 17 and associativity right-to-left. It wouldn't not be
> a problem to replace
>
> 	foo = foo * HZ / 1000000;
>
> with
>
> 	foo *= HZ / 1000000;
>
> if HZ constant is in Hertz. The problem is that in the Linux kernel HZ is
> defined in jiffy units, which is order of magnitude smaller than a million.
> That's why operator precedence has a crucial role here. Fix the regression
> by reverting pre-optimized calculations.
>
> Fixes: be40a3ae719f ("i2c: mpc: Use of_property_read_u32 instead of of_get_property")
> Cc: stable@vger.kernel.org
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>

Thanks.

> ---
>   drivers/i2c/busses/i2c-mpc.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
> index 28c5c5c1fb7a..a21fa45bd64c 100644
> --- a/drivers/i2c/busses/i2c-mpc.c
> +++ b/drivers/i2c/busses/i2c-mpc.c
> @@ -844,7 +844,7 @@ static int fsl_i2c_probe(struct platform_device *op)
>   					      "fsl,timeout", &mpc_ops.timeout);
>   
>   	if (!result) {
> -		mpc_ops.timeout *= HZ / 1000000;
> +		mpc_ops.timeout = mpc_ops.timeout * HZ / 1000000;
>   		if (mpc_ops.timeout < 5)
>   			mpc_ops.timeout = 5;
>   	} else {

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

* Re: [PATCH v1 1/1] i2c: mpc: Fix timeout calculations
  2026-06-18 14:49 [PATCH v1 1/1] i2c: mpc: Fix timeout calculations Andy Shevchenko
  2026-06-18 21:26 ` Chris Packham
@ 2026-06-23 15:37 ` Andi Shyti
  1 sibling, 0 replies; 3+ messages in thread
From: Andi Shyti @ 2026-06-23 15:37 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-i2c, linux-kernel, Chris Packham, stable

Hi Andy,

On Thu, Jun 18, 2026 at 04:49:34PM +0200, Andy Shevchenko wrote:
> ON the first glance the harmless cleanup of the driver does nothing bad.
> However, as the operator precedence list states the '*' (multiplication)
> and '/' division operators have order 5 with left-to-right associativity
> the *= has order 17 and associativity right-to-left. It wouldn't not be
> a problem to replace
> 
> 	foo = foo * HZ / 1000000;
> 
> with
> 
> 	foo *= HZ / 1000000;
> 
> if HZ constant is in Hertz. The problem is that in the Linux kernel HZ is
> defined in jiffy units, which is order of magnitude smaller than a million.
> That's why operator precedence has a crucial role here. Fix the regression
> by reverting pre-optimized calculations.
> 
> Fixes: be40a3ae719f ("i2c: mpc: Use of_property_read_u32 instead of of_get_property")
> Cc: stable@vger.kernel.org
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

merged to i2c/i2c-fixes.

Thanks,
Andi

> ---
>  drivers/i2c/busses/i2c-mpc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
> index 28c5c5c1fb7a..a21fa45bd64c 100644
> --- a/drivers/i2c/busses/i2c-mpc.c
> +++ b/drivers/i2c/busses/i2c-mpc.c
> @@ -844,7 +844,7 @@ static int fsl_i2c_probe(struct platform_device *op)
>  					      "fsl,timeout", &mpc_ops.timeout);
>  
>  	if (!result) {
> -		mpc_ops.timeout *= HZ / 1000000;
> +		mpc_ops.timeout = mpc_ops.timeout * HZ / 1000000;
>  		if (mpc_ops.timeout < 5)
>  			mpc_ops.timeout = 5;
>  	} else {
> -- 
> 2.50.1
> 

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

end of thread, other threads:[~2026-06-23 15:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-18 14:49 [PATCH v1 1/1] i2c: mpc: Fix timeout calculations Andy Shevchenko
2026-06-18 21:26 ` Chris Packham
2026-06-23 15:37 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox