mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/apic: Use div64_ul() instead of do_div()
@ 2024-02-27 11:43 Thorsten Blum
  2024-02-29 22:13 ` David Laight
  0 siblings, 1 reply; 12+ messages in thread
From: Thorsten Blum @ 2024-02-27 11:43 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86
  Cc: H. Peter Anvin, Peter Zijlstra (Intel),
	Wei Liu, linux-kernel, Thorsten Blum

Fixes Coccinelle/coccicheck warnings reported by do_div.cocci.

Change deltapm to unsigned long and replace do_div() with div64_ul()
which doesn't implicitly cast the divisor and doesn't unnecessarily
calculate the remainder.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 arch/x86/kernel/apic/apic.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 4667bc4b00ab..facfb03ef5c8 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -699,7 +699,7 @@ static void __init lapic_cal_handler(struct clock_event_device *dev)
 }
 
 static int __init
-calibrate_by_pmtimer(long deltapm, long *delta, long *deltatsc)
+calibrate_by_pmtimer(unsigned long deltapm, long *delta, long *deltatsc)
 {
 	const long pm_100ms = PMTMR_TICKS_PER_SEC / 10;
 	const long pm_thresh = pm_100ms / 100;
@@ -710,7 +710,7 @@ calibrate_by_pmtimer(long deltapm, long *delta, long *deltatsc)
 	return -1;
 #endif
 
-	apic_printk(APIC_VERBOSE, "... PM-Timer delta = %ld\n", deltapm);
+	apic_printk(APIC_VERBOSE, "... PM-Timer delta = %lu\n", deltapm);
 
 	/* Check, if the PM timer is available */
 	if (!deltapm)
@@ -724,14 +724,14 @@ calibrate_by_pmtimer(long deltapm, long *delta, long *deltatsc)
 		return 0;
 	}
 
-	res = (((u64)deltapm) *  mult) >> 22;
+	res = (((u64)deltapm) * mult) >> 22;
 	do_div(res, 1000000);
 	pr_warn("APIC calibration not consistent "
 		"with PM-Timer: %ldms instead of 100ms\n", (long)res);
 
 	/* Correct the lapic counter value */
 	res = (((u64)(*delta)) * pm_100ms);
-	do_div(res, deltapm);
+	res = div64_ul(res, deltapm);
 	pr_info("APIC delta adjusted to PM-Timer: "
 		"%lu (%ld)\n", (unsigned long)res, *delta);
 	*delta = (long)res;
@@ -739,7 +739,7 @@ calibrate_by_pmtimer(long deltapm, long *delta, long *deltatsc)
 	/* Correct the tsc counter value */
 	if (boot_cpu_has(X86_FEATURE_TSC)) {
 		res = (((u64)(*deltatsc)) * pm_100ms);
-		do_div(res, deltapm);
+		res = div64_ul(res, deltapm);
 		apic_printk(APIC_VERBOSE, "TSC delta adjusted to "
 					  "PM-Timer: %lu (%ld)\n",
 					(unsigned long)res, *deltatsc);
-- 
2.43.2


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

end of thread, other threads:[~2024-03-18 16:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 11:43 [PATCH] x86/apic: Use div64_ul() instead of do_div() Thorsten Blum
2024-02-29 22:13 ` David Laight
2024-03-01  1:01   ` H. Peter Anvin
2024-03-01  8:53     ` David Laight
2024-03-01 12:28   ` Thorsten Blum
2024-03-01 20:39     ` [PATCH v2] x86/apic: Use u32 instead of unsigned long Thorsten Blum
2024-03-08 12:43       ` [RESEND PATCH " Thorsten Blum
2024-03-08 16:12         ` Dave Hansen
2024-03-08 19:50           ` Thorsten Blum
2024-03-08 23:02             ` [PATCH v3] x86/apic: Improve data types to fix Coccinelle warnings Thorsten Blum
2024-03-18 10:47               ` [RESEND PATCH " Thorsten Blum
2024-03-18 16:13                 ` Dave Hansen

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

all inboxes | Powered by JetHome®