Skip to content

Commit 4441b97

Browse files
andy-shevKAGA-KOKO
authored andcommitted
hrtimers: Replace hrtimer_clock_to_base_table with switch-case
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
1 parent 2ea97b7 commit 4441b97

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

kernel/time/hrtimer.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,6 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
117117
.csd = CSD_INIT(retrigger_next_event, NULL)
118118
};
119119

120-
static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
121-
/* Make sure we catch unsupported clockids */
122-
[0 ... MAX_CLOCKS - 1] = HRTIMER_MAX_CLOCK_BASES,
123-
124-
[CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
125-
[CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC,
126-
[CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME,
127-
[CLOCK_TAI] = HRTIMER_BASE_TAI,
128-
};
129-
130120
static inline bool hrtimer_base_is_online(struct hrtimer_cpu_base *base)
131121
{
132122
if (!IS_ENABLED(CONFIG_HOTPLUG_CPU))
@@ -1587,14 +1577,19 @@ u64 hrtimer_next_event_without(const struct hrtimer *exclude)
15871577

15881578
static inline int hrtimer_clockid_to_base(clockid_t clock_id)
15891579
{
1590-
if (likely(clock_id < MAX_CLOCKS)) {
1591-
int base = hrtimer_clock_to_base_table[clock_id];
1592-
1593-
if (likely(base != HRTIMER_MAX_CLOCK_BASES))
1594-
return base;
1580+
switch (clock_id) {
1581+
case CLOCK_REALTIME:
1582+
return HRTIMER_BASE_REALTIME;
1583+
case CLOCK_MONOTONIC:
1584+
return HRTIMER_BASE_MONOTONIC;
1585+
case CLOCK_BOOTTIME:
1586+
return HRTIMER_BASE_BOOTTIME;
1587+
case CLOCK_TAI:
1588+
return HRTIMER_BASE_TAI;
1589+
default:
1590+
WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
1591+
return HRTIMER_BASE_MONOTONIC;
15951592
}
1596-
WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
1597-
return HRTIMER_BASE_MONOTONIC;
15981593
}
15991594

16001595
static enum hrtimer_restart hrtimer_dummy_timeout(struct hrtimer *unused)

0 commit comments

Comments
 (0)