[PATCH v2] hrtimer: check hrtimer with a NULL function

Anna-Maria Behnsen anna-maria at linutronix.de
Mon Jun 10 02:47:40 PDT 2024


Phil Chang <phil.chang at mediatek.com> writes:

> Since hrtimers do not allow a NULL function to be passed,
> to prevent a kernel crash, return before adding the timer to a queue.

You could point out in the commit message, where the kernel would crash
when using a hrtimer with a NULL pointer as function pointer. And it
shouldn't be a problem to use more than a single sentence for a commit
message :)

> Signed-off-by: Phil Chang <phil.chang at mediatek.com>
> ---
>  kernel/time/hrtimer.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
> index 492c14aac642..d32c1afe59b3 100644
> --- a/kernel/time/hrtimer.c
> +++ b/kernel/time/hrtimer.c
> @@ -1285,6 +1285,9 @@ void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
>  	struct hrtimer_clock_base *base;
>  	unsigned long flags;
>  
> +	if (WARN_ON(!timer->function))
> +		return;
> +

Please use a WARN_ON_ONCE() (as documented in
Documentation/process/coding-style.rst)

>  	/*
>  	 * Check whether the HRTIMER_MODE_SOFT bit and hrtimer.is_soft
>  	 * match on CONFIG_PREEMPT_RT = n. With PREEMPT_RT check the hard

Thanks,

	Anna-Maria




More information about the linux-arm-kernel mailing list