* [PATCH] mmc: mtk-sd: use div64_u64() instead of do_div()
@ 2022-02-09 8:38 Qing Wang
2022-02-17 15:39 ` Ulf Hansson
0 siblings, 1 reply; 4+ messages in thread
From: Qing Wang @ 2022-02-09 8:38 UTC (permalink / raw)
To: Chaotian Jing, Ulf Hansson, Matthias Brugger, linux-mmc,
linux-arm-kernel, linux-mediatek, linux-kernel
Cc: Wang Qing
From: Wang Qing <wangqing@vivo.com>
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.
Signed-off-by: Wang Qing <wangqing@vivo.com>
---
drivers/mmc/host/mtk-sd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
index 65037e1..777c9a8
--- a/drivers/mmc/host/mtk-sd.c
+++ b/drivers/mmc/host/mtk-sd.c
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mmc: mtk-sd: use div64_u64() instead of do_div()
2022-02-09 8:38 [PATCH] mmc: mtk-sd: use div64_u64() instead of do_div() Qing Wang
@ 2022-02-17 15:39 ` Ulf Hansson
2022-02-17 20:00 ` Christophe JAILLET
0 siblings, 1 reply; 4+ messages in thread
From: Ulf Hansson @ 2022-02-17 15:39 UTC (permalink / raw)
To: Qing Wang
Cc: Chaotian Jing, Matthias Brugger, linux-mmc, linux-arm-kernel,
linux-mediatek, linux-kernel
On Wed, 9 Feb 2022 at 09:39, Qing Wang <wangqing@vivo.com> wrote:
>
> From: Wang Qing <wangqing@vivo.com>
>
> 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.
>
> Signed-off-by: Wang Qing <wangqing@vivo.com>
Applied for next, thanks!
Kind regards
Uffe
> ---
> drivers/mmc/host/mtk-sd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
> index 65037e1..777c9a8
> --- a/drivers/mmc/host/mtk-sd.c
> +++ b/drivers/mmc/host/mtk-sd.c
> @@ -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
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mmc: mtk-sd: use div64_u64() instead of do_div()
2022-02-17 15:39 ` Ulf Hansson
@ 2022-02-17 20:00 ` Christophe JAILLET
2022-02-28 12:03 ` Ulf Hansson
0 siblings, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2022-02-17 20:00 UTC (permalink / raw)
To: Ulf Hansson, Qing Wang
Cc: Chaotian Jing, Matthias Brugger, linux-mmc, linux-arm-kernel,
linux-mediatek, linux-kernel
Le 17/02/2022 à 16:39, Ulf Hansson a écrit :
> On Wed, 9 Feb 2022 at 09:39, Qing Wang <wangqing@vivo.com> wrote:
>>
>> From: Wang Qing <wangqing@vivo.com>
>>
>> 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.
>>
>> Signed-off-by: Wang Qing <wangqing@vivo.com>
>
> 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/19b96972-cee7-937f-21ce-c78982ed2048@linaro.org/
>
> Kind regards
> Uffe
>
>
>> ---
>> drivers/mmc/host/mtk-sd.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
>> index 65037e1..777c9a8
>> --- a/drivers/mmc/host/mtk-sd.c
>> +++ b/drivers/mmc/host/mtk-sd.c
>> @@ -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
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mmc: mtk-sd: use div64_u64() instead of do_div()
2022-02-17 20:00 ` Christophe JAILLET
@ 2022-02-28 12:03 ` Ulf Hansson
0 siblings, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2022-02-28 12:03 UTC (permalink / raw)
To: Qing Wang, Christophe JAILLET
Cc: Chaotian Jing, Matthias Brugger, linux-mmc, linux-arm-kernel,
linux-mediatek, linux-kernel
On Thu, 17 Feb 2022 at 21:00, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> Le 17/02/2022 à 16:39, Ulf Hansson a écrit :
> > On Wed, 9 Feb 2022 at 09:39, Qing Wang <wangqing@vivo.com> wrote:
> >>
> >> From: Wang Qing <wangqing@vivo.com>
> >>
> >> 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.
> >>
> >> Signed-off-by: Wang Qing <wangqing@vivo.com>
> >
> > 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.
>
>
> Wang Qing, you should really warn all the people you have sent such patches.
>
> CJ
>
> [1]:
> https://lore.kernel.org/linux-kernel/19b96972-cee7-937f-21ce-c78982ed2048@linaro.org/
>
>
> >
> > Kind regards
> > Uffe
> >
> >
> >> ---
> >> drivers/mmc/host/mtk-sd.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
> >> index 65037e1..777c9a8
> >> --- a/drivers/mmc/host/mtk-sd.c
> >> +++ b/drivers/mmc/host/mtk-sd.c
> >> @@ -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!?
> >> timeout += clks;
> >> /* in 1048576 sclk cycle unit */
> >> timeout = DIV_ROUND_UP(timeout, BIT(20));
> >> --
Kind regards
Uffe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-28 12:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 8:38 [PATCH] mmc: mtk-sd: use div64_u64() instead of do_div() Qing Wang
2022-02-17 15:39 ` Ulf Hansson
2022-02-17 20:00 ` Christophe JAILLET
2022-02-28 12:03 ` Ulf Hansson
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).