i2c: mpc: Fix timeout calculations
Subsystems (3)
PATCH 1/1 i2c: mpc: Fix timeout calculations
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.
--- drivers/i2c/busses/i2c-mpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-mpc.c +1 -1
@@ -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 {
Signature · 1 line
2.50.1
Hi Andy,
Quoted 12 lines · Andy Shevchenko
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;
Quoted 8 lines
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")Signed-off-by Andy Shevchenko <[email protected]>
Thanks.
Quoted 17 lines
--- drivers/i2c/busses/i2c-mpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/busses/i2c-mpc.c +1
-1@@ -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 {
Hi Andy,
Quoted 12 lines · Andy Shevchenko
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;
Quoted 8 lines
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")Signed-off-by Andy Shevchenko <[email protected]>
merged to i2c/i2c-fixes.
Thanks,
Andi
Quoted 20 lines
--- drivers/i2c/busses/i2c-mpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i2c/busses/i2c-mpc.c +1
-1@@ -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 {Signature · 1 line
2.50.1