linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma: dmatest: Use div64_s64
@ 2023-08-16  6:04 coolrrsh
  2023-08-16 15:16 ` Greg KH
  2023-08-17 11:25 ` David Laight
  0 siblings, 2 replies; 5+ messages in thread
From: coolrrsh @ 2023-08-16  6:04 UTC (permalink / raw)
  To: vkoul, dmaengine, linux-kernel; +Cc: linux-kernel-mentees, Rajeshwar R Shinde

From: Rajeshwar R Shinde <coolrrsh@gmail.com>

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.

Signed-off-by: Rajeshwar R Shinde <coolrrsh@gmail.com>
---
 drivers/dma/dmatest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index ffe621695e47..07042f239db8 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -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;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] dma: dmatest: Use div64_s64
  2023-08-16  6:04 [PATCH] dma: dmatest: Use div64_s64 coolrrsh
@ 2023-08-16 15:16 ` Greg KH
  2023-08-16 18:38   ` Randy Dunlap
  2023-08-17 11:25 ` David Laight
  1 sibling, 1 reply; 5+ messages in thread
From: Greg KH @ 2023-08-16 15:16 UTC (permalink / raw)
  To: coolrrsh; +Cc: vkoul, dmaengine, linux-kernel, linux-kernel-mentees

On Wed, Aug 16, 2023 at 11:34:00AM +0530, coolrrsh@gmail.com wrote:
> From: Rajeshwar R Shinde <coolrrsh@gmail.com>
> 
> 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.
> 
> Signed-off-by: Rajeshwar R Shinde <coolrrsh@gmail.com>
> ---
>  drivers/dma/dmatest.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
> index ffe621695e47..07042f239db8 100644
> --- a/drivers/dma/dmatest.c
> +++ b/drivers/dma/dmatest.c
> @@ -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);

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

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] dma: dmatest: Use div64_s64
  2023-08-16 15:16 ` Greg KH
@ 2023-08-16 18:38   ` Randy Dunlap
  0 siblings, 0 replies; 5+ messages in thread
From: Randy Dunlap @ 2023-08-16 18:38 UTC (permalink / raw)
  To: Greg KH, coolrrsh; +Cc: vkoul, dmaengine, linux-kernel, linux-kernel-mentees



On 8/16/23 08:16, Greg KH wrote:
> On Wed, Aug 16, 2023 at 11:34:00AM +0530, coolrrsh@gmail.com wrote:
>> From: Rajeshwar R Shinde <coolrrsh@gmail.com>
>>
>> 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.
>>
>> Signed-off-by: Rajeshwar R Shinde <coolrrsh@gmail.com>
>> ---
>>  drivers/dma/dmatest.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
>> index ffe621695e47..07042f239db8 100644
>> --- a/drivers/dma/dmatest.c
>> +++ b/drivers/dma/dmatest.c
>> @@ -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);
> 
> 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.

-- 
~Randy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] dma: dmatest: Use div64_s64
  2023-08-16  6:04 [PATCH] dma: dmatest: Use div64_s64 coolrrsh
  2023-08-16 15:16 ` Greg KH
@ 2023-08-17 11:25 ` David Laight
  1 sibling, 0 replies; 5+ messages in thread
From: David Laight @ 2023-08-17 11:25 UTC (permalink / raw)
  To: 'coolrrsh@gmail.com', vkoul, dmaengine, linux-kernel
  Cc: linux-kernel-mentees

From: coolrrsh@gmail.com
> Sent: Wednesday, August 16, 2023 7:04 AM
> 
> From: Rajeshwar R Shinde <coolrrsh@gmail.com>
> 
> 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.

> 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

> 
> Signed-off-by: Rajeshwar R Shinde <coolrrsh@gmail.com>
> ---
>  drivers/dma/dmatest.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
> index ffe621695e47..07042f239db8 100644
> --- a/drivers/dma/dmatest.c
> +++ b/drivers/dma/dmatest.c
> @@ -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;
>  }
> --
> 2.25.1

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] dma: dmatest: Use div64_s64
@ 2023-08-14  6:22 coolrrsh
  0 siblings, 0 replies; 5+ messages in thread
From: coolrrsh @ 2023-08-14  6:22 UTC (permalink / raw)
  To: vkoul, dmaengine, linux-kernel; +Cc: linux-kernel-mentees, Rajeshwar R Shinde

From: Rajeshwar R Shinde <coolrrsh@gmail.com>

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.

Signed-off-by: Rajeshwar R Shinde <coolrrsh@gmail.com>
---
 drivers/dma/dmatest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index ffe621695e47..07042f239db8 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -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;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-17 11:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-16  6:04 [PATCH] dma: dmatest: Use div64_s64 coolrrsh
2023-08-16 15:16 ` Greg KH
2023-08-16 18:38   ` Randy Dunlap
2023-08-17 11:25 ` David Laight
  -- strict thread matches above, loose matches on Subject: below --
2023-08-14  6:22 coolrrsh

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).