hrtimers: Replace hrtimer_clock_to_base_table with switch-case
[ Upstream commit 4441b976dfeff0d3579e8da3c0283300c618a553 ] Clang and GCC complain about overlapped initialisers in the hrtimer_clock_to_base_table definition. With `make W=1` and CONFIG_WERROR=y (which is default nowadays) this breaks the build: CC kernel/time/hrtimer.o kernel/time/hrtimer.c:124:21: error: initializer overrides prior initialization of this subobject [-Werror,-Winitializer-overrides] 124 | [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME, kernel/time/hrtimer.c:122:27: note: previous initialization is here 122 | [0 ... MAX_CLOCKS - 1] = HRTIMER_MAX_CLOCK_BASES, (and similar for CLOCK_MONOTONIC, CLOCK_BOOTTIME, and CLOCK_TAI). hrtimer_clockid_to_base(), which uses the table, is only used in __hrtimer_init(), which is not a hotpath. Therefore replace the table lookup with a switch case in hrtimer_clockid_to_base() to avoid this warning. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20250214134424.3367619-1-andriy.shevchenko@linux.intel.com Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
7f131fda26
commit
dc5f5c9d2b
+11
-16
@@ -117,16 +117,6 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
|
|||||||
.csd = CSD_INIT(retrigger_next_event, NULL)
|
.csd = CSD_INIT(retrigger_next_event, NULL)
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
|
|
||||||
/* Make sure we catch unsupported clockids */
|
|
||||||
[0 ... MAX_CLOCKS - 1] = HRTIMER_MAX_CLOCK_BASES,
|
|
||||||
|
|
||||||
[CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
|
|
||||||
[CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC,
|
|
||||||
[CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME,
|
|
||||||
[CLOCK_TAI] = HRTIMER_BASE_TAI,
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline bool hrtimer_base_is_online(struct hrtimer_cpu_base *base)
|
static inline bool hrtimer_base_is_online(struct hrtimer_cpu_base *base)
|
||||||
{
|
{
|
||||||
if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
|
if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
|
||||||
@@ -1597,15 +1587,20 @@ u64 hrtimer_next_event_without(const struct hrtimer *exclude)
|
|||||||
|
|
||||||
static inline int hrtimer_clockid_to_base(clockid_t clock_id)
|
static inline int hrtimer_clockid_to_base(clockid_t clock_id)
|
||||||
{
|
{
|
||||||
if (likely(clock_id < MAX_CLOCKS)) {
|
switch (clock_id) {
|
||||||
int base = hrtimer_clock_to_base_table[clock_id];
|
case CLOCK_REALTIME:
|
||||||
|
return HRTIMER_BASE_REALTIME;
|
||||||
if (likely(base != HRTIMER_MAX_CLOCK_BASES))
|
case CLOCK_MONOTONIC:
|
||||||
return base;
|
return HRTIMER_BASE_MONOTONIC;
|
||||||
}
|
case CLOCK_BOOTTIME:
|
||||||
|
return HRTIMER_BASE_BOOTTIME;
|
||||||
|
case CLOCK_TAI:
|
||||||
|
return HRTIMER_BASE_TAI;
|
||||||
|
default:
|
||||||
WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
|
WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
|
||||||
return HRTIMER_BASE_MONOTONIC;
|
return HRTIMER_BASE_MONOTONIC;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
|
static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
|
||||||
enum hrtimer_mode mode)
|
enum hrtimer_mode mode)
|
||||||
|
|||||||
Reference in New Issue
Block a user