* [PATCH] tools cpupower: Fix signed shift UB in amd_fam14h_idle
@ 2026-09-03 8:26 liujing
2026-09-04 17:57 ` Shuah Khan
0 siblings, 1 reply; 2+ messages in thread
From: liujing @ 2026-09-03 8:26 UTC (permalink / raw)
To: Thomas Renninger, Shuah Khan, John B . Wyatt IV, John Kacur
Cc: linux-pm, linux-kernel, Liu Jing
From: Liu Jing <liujing@cmss.chinamobile.com>
In amd_fam14h_get_nb_power(), the expression `1 << 31` performs a
signed integer shift, which is undefined behavior in C.
Fix it by using `1U << 31` to perform an unsigned shift.
Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
---
--- a/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
+++ b/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
@@ -270,7 +270,7 @@
{
uint32_t val;
val = pci_read_long(amd_fam14h_pci_dev, PCI_NBP1_CAP_OFFSET);
- return val & (1 << 31);
+ return val & (1U << 31);
}
struct cpuidle_monitor *amd_fam14h_register(void)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tools cpupower: Fix signed shift UB in amd_fam14h_idle
2026-09-03 8:26 [PATCH] tools cpupower: Fix signed shift UB in amd_fam14h_idle liujing
@ 2026-09-04 17:57 ` Shuah Khan
0 siblings, 0 replies; 2+ messages in thread
From: Shuah Khan @ 2026-09-04 17:57 UTC (permalink / raw)
To: liujing, Thomas Renninger, Shuah Khan, John B . Wyatt IV,
John Kacur, Shuah Khan
Cc: linux-pm, linux-kernel, Shuah Khan
On 9/3/26 02:26, liujing wrote:
> From: Liu Jing <liujing@cmss.chinamobile.com>
>
> In amd_fam14h_get_nb_power(), the expression `1 << 31` performs a
> signed integer shift, which is undefined behavior in C.
>
> Fix it by using `1U << 31` to perform an unsigned shift.
How did you find this problem?
>
> Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
> ---
> --- a/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
> +++ b/tools/power/cpupower/utils/idle_monitor/amd_fam14h_idle.c
> @@ -270,7 +270,7 @@
> {
> uint32_t val;
> val = pci_read_long(amd_fam14h_pci_dev, PCI_NBP1_CAP_OFFSET);
> - return val & (1 << 31);
> + return val & (1U << 31);
> }
>
> struct cpuidle_monitor *amd_fam14h_register(void)
>
>
>
>
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-04 17:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-03 8:26 [PATCH] tools cpupower: Fix signed shift UB in amd_fam14h_idle liujing
2026-09-04 17:57 ` Shuah Khan
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®