Re: [PATCH v4 2/2] livepatch: Convert timeouts to secs_to_jiffies()
From: Petr Mladek
Date: Wed Dec 18 2024 - 03:39:10 EST
On Tue 2024-12-17 23:09:59, Easwar Hariharan wrote:
> Commit b35108a51cf7 ("jiffies: Define secs_to_jiffies()") introduced
> secs_to_jiffies(). As the value here is a multiple of 1000, use
> secs_to_jiffies() instead of msecs_to_jiffies to avoid the multiplication.
>
> This is converted using scripts/coccinelle/misc/secs_to_jiffies.cocci with
> the following Coccinelle rules:
>
> @@ constant C; @@
>
> - msecs_to_jiffies(C * 1000)
> + secs_to_jiffies(C)
>
> @@ constant C; @@
>
> - msecs_to_jiffies(C * MSEC_PER_SEC)
> + secs_to_jiffies(C)
>
> While here, replace the schedule_delayed_work() call with a 0 timeout
> with an immediate schedule_work() call.
>
> --- a/samples/livepatch/livepatch-callbacks-busymod.c
> +++ b/samples/livepatch/livepatch-callbacks-busymod.c
> @@ -44,8 +44,7 @@ static void busymod_work_func(struct work_struct *work)
> static int livepatch_callbacks_mod_init(void)
> {
> pr_info("%s\n", __func__);
> - schedule_delayed_work(&work,
> - msecs_to_jiffies(1000 * 0));
> + schedule_work(&work);
Is it safe to use schedule_work() for struct delayed_work?
It might work in theory but I do not feel comfortable with it.
Also I would expect a compiler warning.
If you really want to use schedule_work() then please
also define the structure with DECLARE_WORK()
and use cancel_work_sync() in livepatch_callbacks_mod_exit().
Best Regards,
Petr