From 4b0e09a918fbcdb3938ecb8e0efc3313bd3b2308 Mon Sep 17 00:00:00 2001 From: Olivier Certner Date: Thu, 29 Jan 2026 10:00:02 +0100 Subject: [PATCH] hwpstate_amd(4): Fix BITS_WITH_VALUE()/SET_BITS_VALUE() to obey the mask While here, rename an argument of BITS_VALUE() to be consistent with the other macros. Reviewed by: aokblast Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D54997 --- sys/x86/cpufreq/hwpstate_amd.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sys/x86/cpufreq/hwpstate_amd.c b/sys/x86/cpufreq/hwpstate_amd.c index 34838753e22..08c833d1a2d 100644 --- a/sys/x86/cpufreq/hwpstate_amd.c +++ b/sys/x86/cpufreq/hwpstate_amd.c @@ -115,9 +115,11 @@ #define HWP_AMD_CLASSNAME "hwpstate_amd" -#define BITS_VALUE(bits, num) (((num) & (bits)) >> (ffsll((bits)) - 1)) -#define BITS_WITH_VALUE(bits, val) ((uintmax_t)(val) << (ffsll((bits)) - 1)) -#define SET_BITS_VALUE(var, bits, val) \ +#define BITS_VALUE(bits, val) \ + (((val) & (bits)) >> (ffsll((bits)) - 1)) +#define BITS_WITH_VALUE(bits, val) \ + (((uintmax_t)(val) << (ffsll((bits)) - 1)) & (bits)) +#define SET_BITS_VALUE(var, bits, val) \ ((var) = ((var) & ~(bits)) | BITS_WITH_VALUE((bits), (val))) #define HWPSTATE_DEBUG(dev, msg...) \