public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] staging: pi433: Use div64_u64 instead of do_div
@ 2022-10-19  9:40 Kang Minchul
  2022-10-19 10:31 ` David Laight
  0 siblings, 1 reply; 3+ messages in thread
From: Kang Minchul @ 2022-10-19  9:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Paulo Miguel Almeida
  Cc: Dan Carpenter, Sidong Yang, linux-staging, linux-kernel,
	Kang Minchul

This commit removes warning generated by cocci as follows:

do_div() does a 64-by-32 division, please consider using div64_u64 instead.

Using div64_u64 instead of do_div can avoid potential truncation.

Signed-off-by: Kang Minchul <tegongkang@gmail.com>
---
 drivers/staging/pi433/rf69.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/pi433/rf69.c b/drivers/staging/pi433/rf69.c
index 8c7fab6a46bb..683dd94489f9 100644
--- a/drivers/staging/pi433/rf69.c
+++ b/drivers/staging/pi433/rf69.c
@@ -252,11 +252,11 @@ int rf69_set_deviation(struct spi_device *spi, u32 deviation)
 
 	// calculat f step
 	f_step = F_OSC * factor;
-	do_div(f_step, 524288); //  524288 = 2^19
+	div64_u64(f_step, 524288); //  524288 = 2^19
 
 	// calculate register settings
 	f_reg = deviation * factor;
-	do_div(f_reg, f_step);
+	div64_u64(f_reg, f_step);
 
 	msb = (f_reg & 0xff00) >> 8;
 	lsb = (f_reg & 0xff);
@@ -291,7 +291,7 @@ int rf69_set_frequency(struct spi_device *spi, u32 frequency)
 
 	// calculat f step
 	f_step = F_OSC * factor;
-	do_div(f_step, 524288); //  524288 = 2^19
+	div64_u64(f_step, 524288); //  524288 = 2^19
 
 	// check input value
 	f_max = div_u64(f_step * 8388608, factor);
@@ -302,7 +302,7 @@ int rf69_set_frequency(struct spi_device *spi, u32 frequency)
 
 	// calculate reg settings
 	f_reg = frequency * factor;
-	do_div(f_reg, f_step);
+	div64_u64(f_reg, f_step);
 
 	msb = (f_reg & 0xff0000) >> 16;
 	mid = (f_reg & 0xff00)   >>  8;
-- 
2.34.1


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

* RE: [PATCH] staging: pi433: Use div64_u64 instead of do_div
  2022-10-19  9:40 [PATCH] staging: pi433: Use div64_u64 instead of do_div Kang Minchul
@ 2022-10-19 10:31 ` David Laight
  2022-10-19 14:20   ` Kang Minchul
  0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2022-10-19 10:31 UTC (permalink / raw)
  To: 'Kang Minchul', Greg Kroah-Hartman, Paulo Miguel Almeida
  Cc: Dan Carpenter, Sidong Yang, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org

From: Kang Minchul
> Sent: 19 October 2022 10:40
> 
> This commit removes warning generated by cocci as follows:
> 
> do_div() does a 64-by-32 division, please consider using div64_u64 instead.
> 
> Using div64_u64 instead of do_div can avoid potential truncation.

Cocci is lying to you.

do_div() exists because a 64 by 32 bit divide is significantly
faster than a 64 by 64 divide.
This is particularly true on 32bit cpu, but is also true on
Intel x86_64 bit cpu.

So unless the result might actually be larger than 32 bits
(which requires code analysis) then do_div() is correct.

	David

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


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

* Re: [PATCH] staging: pi433: Use div64_u64 instead of do_div
  2022-10-19 10:31 ` David Laight
@ 2022-10-19 14:20   ` Kang Minchul
  0 siblings, 0 replies; 3+ messages in thread
From: Kang Minchul @ 2022-10-19 14:20 UTC (permalink / raw)
  To: David Laight
  Cc: Greg Kroah-Hartman, Paulo Miguel Almeida, Dan Carpenter,
	Sidong Yang, linux-staging@lists.linux.dev,
	linux-kernel@vger.kernel.org

2022년 10월 19일 (수) 오후 7:31, David Laight <David.Laight@aculab.com>님이 작성:
>
> From: Kang Minchul
> > Sent: 19 October 2022 10:40
> >
> > This commit removes warning generated by cocci as follows:
> >
> > do_div() does a 64-by-32 division, please consider using div64_u64 instead.
> >
> > Using div64_u64 instead of do_div can avoid potential truncation.
>
> Cocci is lying to you.
>
> do_div() exists because a 64 by 32 bit divide is significantly
> faster than a 64 by 64 divide.
> This is particularly true on 32bit cpu, but is also true on
> Intel x86_64 bit cpu.
I guess I have missed that point,
Thanks for your feedback!

Kang Minchul

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

end of thread, other threads:[~2022-10-19 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-19  9:40 [PATCH] staging: pi433: Use div64_u64 instead of do_div Kang Minchul
2022-10-19 10:31 ` David Laight
2022-10-19 14:20   ` Kang Minchul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox