Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vdso/gettimeofday: Return bool from clock_gettime() helpers

The internal helpers are effectively using boolean results,
while pretending to use error numbers.

Switch the return type to bool for more clarity.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20250701-vdso-auxclock-v1-6-df7d9f87b9b8@linutronix.de

authored by

Thomas Weißschuh and committed by
Thomas Gleixner
fb61bdb2 34f888e3

+36 -34
+36 -34
lib/vdso/gettimeofday.c
··· 82 82 #endif /* CONFIG_GENERIC_VDSO_DATA_STORE */ 83 83 84 84 static __always_inline 85 - int do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns, 86 - clockid_t clk, struct __kernel_timespec *ts) 85 + bool do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns, 86 + clockid_t clk, struct __kernel_timespec *ts) 87 87 { 88 88 const struct vdso_time_data *vd = __arch_get_vdso_u_timens_data(vdns); 89 89 const struct timens_offset *offs = &vcns->offset[clk]; ··· 103 103 seq = vdso_read_begin(vc); 104 104 105 105 if (unlikely(!vdso_clocksource_ok(vc))) 106 - return -1; 106 + return false; 107 107 108 108 cycles = __arch_get_hw_counter(vc->clock_mode, vd); 109 109 if (unlikely(!vdso_cycles_ok(cycles))) 110 - return -1; 110 + return false; 111 111 ns = vdso_calc_ns(vc, cycles, vdso_ts->nsec); 112 112 sec = vdso_ts->sec; 113 113 } while (unlikely(vdso_read_retry(vc, seq))); ··· 123 123 ts->tv_sec = sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); 124 124 ts->tv_nsec = ns; 125 125 126 - return 0; 126 + return true; 127 127 } 128 128 #else 129 129 static __always_inline ··· 133 133 } 134 134 135 135 static __always_inline 136 - int do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns, 137 - clockid_t clk, struct __kernel_timespec *ts) 136 + bool do_hres_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns, 137 + clockid_t clk, struct __kernel_timespec *ts) 138 138 { 139 - return -EINVAL; 139 + return false; 140 140 } 141 141 #endif 142 142 143 143 static __always_inline 144 - int do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc, 145 - clockid_t clk, struct __kernel_timespec *ts) 144 + bool do_hres(const struct vdso_time_data *vd, const struct vdso_clock *vc, 145 + clockid_t clk, struct __kernel_timespec *ts) 146 146 { 147 147 const struct vdso_timestamp *vdso_ts = &vc->basetime[clk]; 148 148 u64 cycles, sec, ns; ··· 150 150 151 151 /* Allows to compile the high resolution parts out */ 152 152 if (!__arch_vdso_hres_capable()) 153 - return -1; 153 + return false; 154 154 155 155 do { 156 156 /* ··· 173 173 smp_rmb(); 174 174 175 175 if (unlikely(!vdso_clocksource_ok(vc))) 176 - return -1; 176 + return false; 177 177 178 178 cycles = __arch_get_hw_counter(vc->clock_mode, vd); 179 179 if (unlikely(!vdso_cycles_ok(cycles))) 180 - return -1; 180 + return false; 181 181 ns = vdso_calc_ns(vc, cycles, vdso_ts->nsec); 182 182 sec = vdso_ts->sec; 183 183 } while (unlikely(vdso_read_retry(vc, seq))); ··· 189 189 ts->tv_sec = sec + __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns); 190 190 ts->tv_nsec = ns; 191 191 192 - return 0; 192 + return true; 193 193 } 194 194 195 195 #ifdef CONFIG_TIME_NS 196 196 static __always_inline 197 - int do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns, 198 - clockid_t clk, struct __kernel_timespec *ts) 197 + bool do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns, 198 + clockid_t clk, struct __kernel_timespec *ts) 199 199 { 200 200 const struct vdso_time_data *vd = __arch_get_vdso_u_timens_data(vdns); 201 201 const struct timens_offset *offs = &vcns->offset[clk]; ··· 223 223 */ 224 224 ts->tv_sec = sec + __iter_div_u64_rem(nsec, NSEC_PER_SEC, &nsec); 225 225 ts->tv_nsec = nsec; 226 - return 0; 226 + return true; 227 227 } 228 228 #else 229 229 static __always_inline 230 - int do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns, 231 - clockid_t clk, struct __kernel_timespec *ts) 230 + bool do_coarse_timens(const struct vdso_time_data *vdns, const struct vdso_clock *vcns, 231 + clockid_t clk, struct __kernel_timespec *ts) 232 232 { 233 - return -1; 233 + return false; 234 234 } 235 235 #endif 236 236 237 237 static __always_inline 238 - int do_coarse(const struct vdso_time_data *vd, const struct vdso_clock *vc, 239 - clockid_t clk, struct __kernel_timespec *ts) 238 + bool do_coarse(const struct vdso_time_data *vd, const struct vdso_clock *vc, 239 + clockid_t clk, struct __kernel_timespec *ts) 240 240 { 241 241 const struct vdso_timestamp *vdso_ts = &vc->basetime[clk]; 242 242 u32 seq; ··· 258 258 ts->tv_nsec = vdso_ts->nsec; 259 259 } while (unlikely(vdso_read_retry(vc, seq))); 260 260 261 - return 0; 261 + return true; 262 262 } 263 263 264 - static __always_inline int 264 + static __always_inline bool 265 265 __cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t clock, 266 266 struct __kernel_timespec *ts) 267 267 { ··· 270 270 271 271 /* Check for negative values or invalid clocks */ 272 272 if (unlikely((u32) clock >= MAX_CLOCKS)) 273 - return -1; 273 + return false; 274 274 275 275 /* 276 276 * Convert the clockid to a bitmask and use it to check which ··· 284 284 else if (msk & VDSO_RAW) 285 285 vc = &vc[CS_RAW]; 286 286 else 287 - return -1; 287 + return false; 288 288 289 289 return do_hres(vd, vc, clock, ts); 290 290 } ··· 293 293 __cvdso_clock_gettime_data(const struct vdso_time_data *vd, clockid_t clock, 294 294 struct __kernel_timespec *ts) 295 295 { 296 - int ret = __cvdso_clock_gettime_common(vd, clock, ts); 296 + bool ok; 297 297 298 - if (unlikely(ret)) 298 + ok = __cvdso_clock_gettime_common(vd, clock, ts); 299 + 300 + if (unlikely(!ok)) 299 301 return clock_gettime_fallback(clock, ts); 300 302 return 0; 301 303 } ··· 314 312 struct old_timespec32 *res) 315 313 { 316 314 struct __kernel_timespec ts; 317 - int ret; 315 + bool ok; 318 316 319 - ret = __cvdso_clock_gettime_common(vd, clock, &ts); 317 + ok = __cvdso_clock_gettime_common(vd, clock, &ts); 320 318 321 - if (unlikely(ret)) 319 + if (unlikely(!ok)) 322 320 return clock_gettime32_fallback(clock, res); 323 321 324 - /* For ret == 0 */ 322 + /* For ok == true */ 325 323 res->tv_sec = ts.tv_sec; 326 324 res->tv_nsec = ts.tv_nsec; 327 325 328 - return ret; 326 + return 0; 329 327 } 330 328 331 329 static __maybe_unused int ··· 344 342 if (likely(tv != NULL)) { 345 343 struct __kernel_timespec ts; 346 344 347 - if (do_hres(vd, &vc[CS_HRES_COARSE], CLOCK_REALTIME, &ts)) 345 + if (!do_hres(vd, &vc[CS_HRES_COARSE], CLOCK_REALTIME, &ts)) 348 346 return gettimeofday_fallback(tv, tz); 349 347 350 348 tv->tv_sec = ts.tv_sec;