|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 4/5] x86/amd: Make cpu_has_amd_erratum() non-variadic
cpu_has_amd_erratum() takes the OSVW id and the family-model-stepping
ranges of an erratum as variadic arguments, which MISRA C Rule 17.1
forbids.
Have AMD_LEGACY_ERRATUM() and AMD_OSVW_ERRATUM() expand to a
zero-terminated array instead, and have cpu_has_amd_erratum() walk it.
Callers pass the AMD_ERRATUM_* macros, so they are unaffected.
No functional change.
Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
---
xen/arch/x86/cpu/amd.c | 14 ++++++--------
xen/arch/x86/include/asm/amd.h | 11 +++++++----
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index fbbba0005c..5e22fff81c 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -321,10 +321,10 @@ void amd_set_cpuid_user_dis(bool enable)
* Check for the presence of an AMD erratum. Arguments are defined in amd.h
* for each known erratum. Return 1 if erratum is found.
*/
-int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw_id, ...)
+int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, const int *erratum)
{
- va_list ap;
- u32 range;
+ int osvw_id = erratum[0];
+ const int *p;
u32 ms;
if (cpu->vendor != X86_VENDOR_AMD)
@@ -346,19 +346,17 @@ int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu,
int osvw_id, ...)
}
/* OSVW unavailable or ID unknown, match family-model-stepping range */
- va_start(ap, osvw_id);
-
ms = (cpu->model << 4) | cpu->stepping;
- while ((range = va_arg(ap, int))) {
+ for (p = &erratum[1]; *p; p++) {
+ u32 range = *p;
+
if ((cpu->family == AMD_MODEL_RANGE_FAMILY(range)) &&
(ms >= AMD_MODEL_RANGE_START(range)) &&
(ms <= AMD_MODEL_RANGE_END(range))) {
- va_end(ap);
return 1;
}
}
- va_end(ap);
return 0;
}
diff --git a/xen/arch/x86/include/asm/amd.h b/xen/arch/x86/include/asm/amd.h
index d21df0741a..d897943210 100644
--- a/xen/arch/x86/include/asm/amd.h
+++ b/xen/arch/x86/include/asm/amd.h
@@ -12,7 +12,8 @@
* Errata are defined using the AMD_LEGACY_ERRATUM() or AMD_OSVW_ERRATUM()
* macros. The latter is intended for newer errata that have an OSVW id
* assigned, which it takes as first argument. Both take a variable number
- * of family-specific model-stepping ranges created by AMD_MODEL_RANGE().
+ * of family-specific model-stepping ranges created by AMD_MODEL_RANGE(),
+ * and yield a zero-terminated array to pass to cpu_has_amd_erratum().
*
* Example 1:
* #define AMD_ERRATUM_319 \
@@ -26,8 +27,10 @@
*
*/
-#define AMD_LEGACY_ERRATUM(...) -1 /* legacy */, __VA_ARGS__, 0
-#define AMD_OSVW_ERRATUM(osvw_id, ...) osvw_id, __VA_ARGS__, 0
+#define AMD_LEGACY_ERRATUM(...) \
+ ((const int[]){ -1 /* legacy */, __VA_ARGS__, 0 })
+#define AMD_OSVW_ERRATUM(osvw_id, ...) \
+ ((const int[]){ osvw_id, __VA_ARGS__, 0 })
#define AMD_MODEL_RANGE(f, m_start, s_start, m_end, s_end) \
(((f) << 24) | ((m_start) << 16) | ((s_start) << 12) | \
((m_end) << 4) | (s_end))
@@ -72,7 +75,7 @@
#define is_zen6_uarch() boot_cpu_has(X86_FEATURE_FRED)
struct cpuinfo_x86;
-int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, int osvw_id, ...);
+int cpu_has_amd_erratum(const struct cpuinfo_x86 *cpu, const int *erratum);
extern int8_t opt_allow_unsafe;
--
2.43.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |