Skip to contentSkip to conversation

dma: dmatest: Use div64_s64

PATCH In review [email protected] 4 participants 4 messages Aug 16, 2023 – Aug 17, 2023 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma: dmatest: Use div64_s64

From: Rajeshwar R Shinde <[email protected]>

In the function do_div, the dividend is evaluated multiple times so it can cause side effects. Therefore replace it with div64_s64.

This fixes warning such as:
drivers/dma/dmatest.c:496:1-7:
WARNING: do_div() does a 64-by-32 division,
please consider using div64_s64 instead.

---
 drivers/dma/dmatest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/dmatest.c +2 -1
index ffe621695e47..07042f239db8 100644
@@ -9,6 +9,7 @@
 
 #include <linux/err.h>
 #include <linux/delay.h>
+#include <linux/math64.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
 #include <linux/freezer.h>
@@ -493,7 +494,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);
+	per_sec=div64_s64(per_sec, runtime);
 
 	return per_sec;
 }
Signature · 6 lines
2.25.1

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw
Quoted 28 lines · On Wed, Aug 16, 2023 at 11:34:00AM +0530, [email protected] wrote:

From: Rajeshwar R Shinde <[email protected]>

In the function do_div, the dividend is evaluated multiple times so it can cause side effects. Therefore replace it with div64_s64.

This fixes warning such as:
drivers/dma/dmatest.c:496:1-7:
WARNING: do_div() does a 64-by-32 division,
please consider using div64_s64 instead.

---
 drivers/dma/dmatest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/dmatest.c +1 -0
index ffe621695e47..07042f239db8 100644
@@ -9,6 +9,7 @@
 
 #include <linux/err.h>
 #include <linux/delay.h>
+#include <linux/math64.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
 #include <linux/freezer.h>

drivers/dma/dmatest.c static unsigned long long dmatest_persec(s64 runtime, unsigned int val) · line 497

Quoted 5 lines
drivers/dma/dmatest.c +1 -1
@@ -493,7 +494,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);
+	per_sec=div64_s64(per_sec, runtime);

Please always run checkpatch.pl on your changes before submitting them for others to review.

thanks,

greg k-h
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#2 lore raw
Quoted 30 lines · Greg KH
Quoted 29 lines · On Wed, Aug 16, 2023 at 11:34:00AM +0530, [email protected] wrote:

From: Rajeshwar R Shinde <[email protected]>

In the function do_div, the dividend is evaluated multiple times so it can cause side effects. Therefore replace it with div64_s64.

This fixes warning such as:
drivers/dma/dmatest.c:496:1-7:
WARNING: do_div() does a 64-by-32 division,
please consider using div64_s64 instead.

---
 drivers/dma/dmatest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/dmatest.c +1 -0
index ffe621695e47..07042f239db8 100644
@@ -9,6 +9,7 @@
 
 #include <linux/err.h>
 #include <linux/delay.h>
+#include <linux/math64.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
 #include <linux/freezer.h>
@@ -493,7 +494,7 @@ static unsigned long long dmatest_persec(s64 runtime, unsigned int val)
 
Quoted 7 lines

drivers/dma/dmatest.c static unsigned long long dmatest_persec(s64 runtime, unsigned int val) · line 497

Quoted 4 lines
drivers/dma/dmatest.c +1 -1
 	per_sec *= val;
 	per_sec = INT_TO_FIXPT(per_sec);
-	do_div(per_sec, runtime);
+	per_sec=div64_s64(per_sec, runtime);

Please always run checkpatch.pl on your changes before submitting them for others to review.

Also please tell us what tool produced that warning message. Thanks.

Signature · 5 lines
~Randy
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#3 lore raw
In reply to [email protected]

From: [email protected]

Quoted 6 lines

Sent: Wednesday, August 16, 2023 7:04 AM

From: Rajeshwar R Shinde <[email protected]>

In the function do_div, the dividend is evaluated multiple times so it can cause side effects. Therefore replace it with div64_s64.

Nope, and even if it did it wouldn't matter here.

Quoted 4 lines

This fixes warning such as:
drivers/dma/dmatest.c:496:1-7:
WARNING: do_div() does a 64-by-32 division,
please consider using div64_s64 instead.

What you should really do is look carefully at the domain of the input values to see if the division can actually overflow.

That message is basically incorrect.

The full 64x64 divide is horribly slow on all 32bit archs. It is even about twice as slow as the 64x32 divide on Intel x86 cpu in 64bit mode (regardless of the values).

David

Quoted 28 lines
---
 drivers/dma/dmatest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/dmatest.c +2 -2
index ffe621695e47..07042f239db8 100644
@@ -9,6 +9,7 @@
 
 #include <linux/err.h>
 #include <linux/delay.h>
+#include <linux/math64.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmaengine.h>
 #include <linux/freezer.h>
@@ -493,7 +494,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);
+	per_sec=div64_s64(per_sec, runtime);
 
 	return per_sec;
 }
--
Quoted 1 line

2.25.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)