git: 4b0e09a918fb - main - hwpstate_amd(4): Fix BITS_WITH_VALUE()/SET_BITS_VALUE() to obey the mask

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Tue, 03 Feb 2026 14:05:06 UTC
The branch main has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=4b0e09a918fbcdb3938ecb8e0efc3313bd3b2308

commit 4b0e09a918fbcdb3938ecb8e0efc3313bd3b2308
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-01-29 09:00:02 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-02-03 14:03:02 +0000

    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 34838753e221..08c833d1a2dd 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...)			\