mmc: mtk-sd: use div64_u64() instead of do_div()
Subsystems (3)
PATCH 1/1 mmc: mtk-sd: use div64_u64() instead of do_div()
From: Wang Qing <[email protected]>
do_div() does a 64-by-32 division.
When the divisor is u64, do_div() truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.
fix do_div.cocci warning:do_div() does a 64-by-32 division, please consider using div64_u64 instead.
--- drivers/mmc/host/mtk-sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/mtk-sd.c +1 -1
@@ -766,7 +766,7 @@ static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks) clk_ns =1000000000ULL ;do_div (clk_ns, mmc->actual_clock); timeout = ns + clk_ns -1 ; -do_div (timeout, clk_ns); +div64_u64 (timeout, clk_ns); timeout += clks;/* in 1048576 sclk cycle unit */ timeout =DIV_ROUND_UP (timeout,BIT (20 ));
Signature · 7 lines
2.7.4 _______________________________________________ Linux-mediatek mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-mediatek
Quoted 11 lines · Qing Wang
From: Wang Qing <[email protected]>
do_div()does a 64-by-32 division.
When the divisor is u64,do_div()truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.fix
do_div.cocciwarning:do_div()does a 64-by-32 division, please consider usingdiv64_u64instead.Signed-off-by Wang Qing <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 20 lines
--- drivers/mmc/host/mtk-sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mmc/host/mtk-sd.c +1
-2@@ -766,7 +766,7 @@ static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks) clk_ns =1000000000ULL ;do_div (clk_ns, mmc->actual_clock); timeout = ns + clk_ns -1 ; -do_div (timeout, clk_ns); +div64_u64 (timeout, clk_ns); timeout += clks;/* in 1048576 sclk cycle unit */ timeout =DIV_ROUND_UP (timeout,BIT (20 )); --2.7.4
Le 17/02/2022 à 16:39, Ulf Hansson a écrit :
Quoted 8 lines · Qing Wang
Quoted 7 lines
From: Wang Qing <[email protected]>
do_div()does a 64-by-32 division.
When the divisor is u64,do_div()truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.
Quoted 6 lines
Quoted 4 lines
fix
do_div.cocciwarning:do_div()does a 64-by-32 division, please consider usingdiv64_u64instead.Signed-off-by Wang Qing <[email protected]>Applied for next, thanks!
This is wrong.
See [1].
Wang Qing, you should really warn all the people you have sent such patches.
CJ
[1]: https://lore.kernel.org/linux-kernel/[email protected]/
Quoted 26 lines
Kind regards
UffeQuoted 20 lines
--- drivers/mmc/host/mtk-sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/mmc/host/mtk-sd.c +1
-2@@ -766,7 +766,7 @@ static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks) clk_ns =1000000000ULL ;do_div (clk_ns, mmc->actual_clock); timeout = ns + clk_ns -1 ; -do_div (timeout, clk_ns); +div64_u64 (timeout, clk_ns); timeout += clks;/* in 1048576 sclk cycle unit */ timeout =DIV_ROUND_UP (timeout,BIT (20 )); --2.7.4
Quoted 13 lines · Christophe JAILLET
Quoted 11 lines · Ulf Hansson
Quoted 10 lines · Qing Wang
From: Wang Qing <[email protected]>
do_div()does a 64-by-32 division.
When the divisor is u64,do_div()truncates it to 32 bits, this means it can test non-zero and be truncated to zero for division.fix
do_div.cocciwarning:do_div()does a 64-by-32 division, please consider usingdiv64_u64instead.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Wang Qing <[email protected]>Applied for next, thanks!
This is wrong.
See [1].
Thanks for reporting this, I am dropping the patch from my next branch!
See more comments below.
Quoted 19 lines
Wang Qing, you should really warn all the people you have sent such patches.
CJ
[1]:
https://lore.kernel.org/linux-kernel/[email protected]/Quoted 9 lines
Kind regards
UffeQuoted 4 lines
--- drivers/mmc/host/mtk-sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines
Quoted 10 lines
drivers/mmc/host/mtk-sd.c static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks) · line 769
Quoted 10 lines
drivers/mmc/host/mtk-sd.c +1
-1@@ -766,7 +766,7 @@ static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks) clk_ns =1000000000ULL ;do_div (clk_ns, mmc->actual_clock); timeout = ns + clk_ns -1 ; -do_div (timeout, clk_ns); +div64_u64 (timeout, clk_ns);
I guess a proper patch would be to convert clk_ns into an u32 instead!?
Quoted 4 lines
Quoted 4 lines
drivers/mmc/host/mtk-sd.c static u64 msdc_timeout_cal(struct msdc_host *host, u64 ns, u64 clks)
Quoted 4 lines
drivers/mmc/host/mtk-sd.c +0
-1timeout += clks;/* in 1048576 sclk cycle unit */ timeout =DIV_ROUND_UP (timeout,BIT (20 )); --
Kind regards
Uffe