[PATCH 00/12] hrtimers: Switch to new hrtimer interface functions (5/5)

Nam Cao posted 12 patches 3 weeks, 6 days ago
Documentation/trace/ftrace.rst                |  4 +-
.../net/wireless/ralink/rt2x00/rt2800mmio.c   |  2 +-
.../net/wireless/ralink/rt2x00/rt2800usb.c    |  2 +-
drivers/tty/serial/xilinx_uartps.c            |  4 +-
include/linux/hrtimer.h                       |  4 +-
include/linux/hrtimer_types.h                 |  4 +-
include/trace/events/timer.h                  |  8 +--
io_uring/io_uring.c                           |  2 +-
kernel/time/hrtimer.c                         | 69 +++++--------------
kernel/time/timer_list.c                      |  2 +-
tools/perf/tests/shell/trace_btf_enum.sh      |  2 +-
11 files changed, 35 insertions(+), 68 deletions(-)
[PATCH 00/12] hrtimers: Switch to new hrtimer interface functions (5/5)
Posted by Nam Cao 3 weeks, 6 days ago
This is the fifth part of a 5-part series (split for convenience). All 5
parts are:

Part 1: https://lore.kernel.org/lkml/cover.1729864615.git.namcao@linutronix.de
Part 2: https://lore.kernel.org/lkml/cover.1729864823.git.namcao@linutronix.de
Part 3: https://lore.kernel.org/lkml/cover.1729865232.git.namcao@linutronix.de
Part 4: https://lore.kernel.org/lkml/cover.1729865485.git.namcao@linutronix.de
Part 5: https://lore.kernel.org/lkml/cover.1729865740.git.namcao@linutronix.de

To use hrtimer, hrtimer_init() (or one of its variant) must be called, and
also the timer's callfack function must be setup separately.

That can cause misuse of hrtimer. For example, because:
  - The callback function is not setup
  - The callback function is setup while it is not safe to do so

To prevent misuse of hrtimer, this series:
  - Introduce new functions hrtimer_setup*(). These new functions are
    similar to hrtimer_init*(), except that they also sanity-check and
    initialize the callback function.
  - Introduce hrtimer_update_function() which checks that it is safe to
    change the callback function. The 'function' field of hrtimer is then
    made private.
  - Convert all users to use the new functions.
  - Some minor cleanups on the way.

Most conversion patches were created using Coccinelle with the sematic
patch below; except for tricky cases that Coccinelle cannot handle, or for
some cases where a Coccinelle's bug regarding 100 column limit is
triggered. Any patches not mentioning Coccinelle were done manually.

virtual patch
@@ expression timer, clock, mode, func; @@
- hrtimer_init(timer, clock, mode);
  ...
- timer->function = func;
+ hrtimer_setup(timer, func, clock, mode);

@@ expression timer, clock, mode, func; @@
- hrtimer_init(&timer, clock, mode);
  ...
- timer.function = func;
+ hrtimer_setup(&timer, func, clock, mode);

@@ expression timer, clock, mode, func; @@
- hrtimer_init_on_stack(&timer, clock, mode);
  ...
- timer.function = func;
+ hrtimer_setup_on_stack(&timer, func, clock, mode);

@@ expression timer, clock, mode; @@
- hrtimer_init_sleeper_on_stack(timer, clock, mode);
+ hrtimer_setup_sleeper_on_stack(timer, clock, mode);

Signed-off-by: Nam Cao <namcao@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Kalle Valo <kvalo@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>

Nam Cao (12):
  hrtimers: Delete hrtimer_init()
  hrtimers: Switch to use __htimer_setup()
  hrtimers: Merge __hrtimer_init() into __hrtimer_setup()
  serial: xilinx_uartps: Use helper function hrtimer_update_function()
  io_uring: Use helper function hrtimer_update_function()
  wifi: rt2x00: Switch to use hrtimer_update_function()
  hrtimers: Make callback function pointer private
  hrtimers: Remove unnecessary NULL check in hrtimer_start_range_ns()
  hrtimers: Rename __hrtimer_init_sleeper() to __hrtimer_setup_sleeper()
  hrtimers: Rename debug_init() to debug_setup()
  hrtimers: Rename debug_init_on_stack() to debug_setup_on_stack()
  tracing/timers: Rename hrtimer_init event to hrtimer_setup

 Documentation/trace/ftrace.rst                |  4 +-
 .../net/wireless/ralink/rt2x00/rt2800mmio.c   |  2 +-
 .../net/wireless/ralink/rt2x00/rt2800usb.c    |  2 +-
 drivers/tty/serial/xilinx_uartps.c            |  4 +-
 include/linux/hrtimer.h                       |  4 +-
 include/linux/hrtimer_types.h                 |  4 +-
 include/trace/events/timer.h                  |  8 +--
 io_uring/io_uring.c                           |  2 +-
 kernel/time/hrtimer.c                         | 69 +++++--------------
 kernel/time/timer_list.c                      |  2 +-
 tools/perf/tests/shell/trace_btf_enum.sh      |  2 +-
 11 files changed, 35 insertions(+), 68 deletions(-)

-- 
2.39.5