[PATCH] dmaengine: dmatest: Explicitly cast divisor to u32

Thorsten Blum posted 1 patch 1 year, 5 months ago
drivers/dma/dmatest.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] dmaengine: dmatest: Explicitly cast divisor to u32
Posted by Thorsten Blum 1 year, 5 months ago
As the comment explains, the while loop ensures that runtime fits into
32 bits. Since do_div() casts the divisor to u32 anyway, explicitly cast
runtime to u32 to remove the following Coccinelle/coccicheck warning
reported by do_div.cocci:

  WARNING: do_div() does a 64-by-32 division, please consider using div64_s64 instead

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 drivers/dma/dmatest.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index 1f201a542b37..91b2fbc0b864 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -500,7 +500,7 @@ static unsigned long long dmatest_persec(s64 runtime, unsigned int val)
 
 	per_sec *= val;
 	per_sec = INT_TO_FIXPT(per_sec);
-	do_div(per_sec, runtime);
+	do_div(per_sec, (u32)runtime);
 
 	return per_sec;
 }
-- 
2.39.2
Re: [PATCH] dmaengine: dmatest: Explicitly cast divisor to u32
Posted by Vinod Koul 1 year, 4 months ago
On Thu, 11 Jul 2024 15:20:01 +0200, Thorsten Blum wrote:
> As the comment explains, the while loop ensures that runtime fits into
> 32 bits. Since do_div() casts the divisor to u32 anyway, explicitly cast
> runtime to u32 to remove the following Coccinelle/coccicheck warning
> reported by do_div.cocci:
> 
>   WARNING: do_div() does a 64-by-32 division, please consider using div64_s64 instead
> 
> [...]

Applied, thanks!

[1/1] dmaengine: dmatest: Explicitly cast divisor to u32
      commit: da080d987e20a8b20b368c75826226834c9660a3

Best regards,
-- 
Vinod Koul <vkoul@kernel.org>