Skip to content

Commit 62e7244

Browse files
andy-shevhansendc
authored andcommitted
x86/cpu: Make sure flag_is_changeable_p() is always being used
When flag_is_changeable_p() is unused, it prevents kernel builds with clang, `make W=1` and CONFIG_WERROR=y: arch/x86/kernel/cpu/common.c:351:19: error: unused function 'flag_is_changeable_p' [-Werror,-Wunused-function] 351 | static inline int flag_is_changeable_p(u32 flag) | ^~~~~~~~~~~~~~~~~~~~ Fix this by moving core around to make sure flag_is_changeable_p() is always being used. See also commit 6863f56 ("kbuild: allow Clang to find unused static inline functions for W=1 build"). While at it, fix the argument type to be unsigned long along with the local variables, although it currently only runs in 32-bit cases. Besides that, makes it return boolean instead of int. This induces the change of the returning type of have_cpuid_p() to be boolean as well. Suggested-by: Dave Hansen <dave.hansen@intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: H. Peter Anvin (Intel) <hpa@zytor.com> Link: https://lore.kernel.org/all/20241108153105.1578186-1-andriy.shevchenko%40linux.intel.com
1 parent 86e39b9 commit 62e7244

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

arch/x86/include/asm/cpuid.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef _ASM_X86_CPUID_H
77
#define _ASM_X86_CPUID_H
88

9+
#include <linux/types.h>
10+
911
#include <asm/string.h>
1012

1113
struct cpuid_regs {
@@ -20,11 +22,11 @@ enum cpuid_regs_idx {
2022
};
2123

2224
#ifdef CONFIG_X86_32
23-
extern int have_cpuid_p(void);
25+
bool have_cpuid_p(void);
2426
#else
25-
static inline int have_cpuid_p(void)
27+
static inline bool have_cpuid_p(void)
2628
{
27-
return 1;
29+
return true;
2830
}
2931
#endif
3032
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,

arch/x86/kernel/cpu/common.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,13 @@ static int __init x86_noinvpcid_setup(char *s)
275275
}
276276
early_param("noinvpcid", x86_noinvpcid_setup);
277277

278-
#ifdef CONFIG_X86_32
279-
static int cachesize_override = -1;
280-
static int disable_x86_serial_nr = 1;
281-
282-
static int __init cachesize_setup(char *str)
283-
{
284-
get_option(&str, &cachesize_override);
285-
return 1;
286-
}
287-
__setup("cachesize=", cachesize_setup);
288-
289278
/* Standard macro to see if a specific flag is changeable */
290-
static inline int flag_is_changeable_p(u32 flag)
279+
static inline bool flag_is_changeable_p(unsigned long flag)
291280
{
292-
u32 f1, f2;
281+
unsigned long f1, f2;
282+
283+
if (!IS_ENABLED(CONFIG_X86_32))
284+
return true;
293285

294286
/*
295287
* Cyrix and IDT cpus allow disabling of CPUID
@@ -312,11 +304,22 @@ static inline int flag_is_changeable_p(u32 flag)
312304
: "=&r" (f1), "=&r" (f2)
313305
: "ir" (flag));
314306

315-
return ((f1^f2) & flag) != 0;
307+
return (f1 ^ f2) & flag;
316308
}
317309

310+
#ifdef CONFIG_X86_32
311+
static int cachesize_override = -1;
312+
static int disable_x86_serial_nr = 1;
313+
314+
static int __init cachesize_setup(char *str)
315+
{
316+
get_option(&str, &cachesize_override);
317+
return 1;
318+
}
319+
__setup("cachesize=", cachesize_setup);
320+
318321
/* Probe for the CPUID instruction */
319-
int have_cpuid_p(void)
322+
bool have_cpuid_p(void)
320323
{
321324
return flag_is_changeable_p(X86_EFLAGS_ID);
322325
}
@@ -348,10 +351,6 @@ static int __init x86_serial_nr_setup(char *s)
348351
}
349352
__setup("serialnumber", x86_serial_nr_setup);
350353
#else
351-
static inline int flag_is_changeable_p(u32 flag)
352-
{
353-
return 1;
354-
}
355354
static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
356355
{
357356
}
@@ -1087,7 +1086,6 @@ void get_cpu_address_sizes(struct cpuinfo_x86 *c)
10871086

10881087
static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
10891088
{
1090-
#ifdef CONFIG_X86_32
10911089
int i;
10921090

10931091
/*
@@ -1108,7 +1106,6 @@ static void identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
11081106
break;
11091107
}
11101108
}
1111-
#endif
11121109
}
11131110

11141111
#define NO_SPECULATION BIT(0)

0 commit comments

Comments
 (0)