Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hpet: Optimize local variable data type in hpet_alloc()

The local variable period uses at most 32 bits and can be a u32 instead
of unsigned long. The upper 32 bits are all 0 after masking and right
shifting cap by HPET_COUNTER_CLK_PERIOD_SHIFT and can be discarded.

Since do_div() casts the divisor to u32 anyway, changing the data type
of period to u32 also removes the following Coccinelle/coccicheck
warning reported by do_div.cocci:

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

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20240710215238.799239-2-thorsten.blum@toblux.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thorsten Blum and committed by
Greg Kroah-Hartman
104831a1 4d41a49c

+1 -1
+1 -1
drivers/char/hpet.c
··· 808 808 struct hpets *hpetp; 809 809 struct hpet __iomem *hpet; 810 810 static struct hpets *last; 811 - unsigned long period; 811 + u32 period; 812 812 unsigned long long temp; 813 813 u32 remainder; 814 814