From: Alexander Sverdlin <alexander.sverdlin@nokia.com>
To: "krzysztof.sobota@nokia.com" <krzysztof.sobota@nokia.com>,
Guenter Roeck <linux@roeck-us.net>,
wim@linux-watchdog.org, linux-watchdog@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] watchdog: initialize device before misc_register
Date: Thu, 16 Jul 2020 13:48:14 +0200 [thread overview]
Message-ID: <e2b9f886-5a4e-91f3-59d1-c83a46149a82@nokia.com> (raw)
In-Reply-To: <1f20e45d-aba5-6226-27f2-cb6438cc224e@nokia.com>
Hello Krzysztof,
On 16/07/2020 13:32, krzysztof.sobota@nokia.com wrote:
> When watchdog device is being registered, it calls misc_register that
> makes watchdog available for systemd to open. This is a data race
> scenario, because when device is open it may still have device struct
> not initialized - this in turn causes a crash. This patch moves
> device initialization before misc_register call and it solves the
> problem printed below.
[...]
thank you for looking into this!
> Fixes: 72139dfa2464 ("watchdog: Fix the race between the release of watchdog_core_data and cdev")
> Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> Signed-off-by: Krzysztof Sobota <krzysztof.sobota@nokia.com>
> ---
> v1 -> v2:
> * removed Change-Id tag
> * added Review-by tag
> v2 -> v3
> * convert spaces to tabs
> * convert (hopefully) mail to plaintext
> ---
> drivers/watchdog/watchdog_dev.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> index 10b2090f3e5e..1c322caecf7f 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c
> @@ -947,6 +947,15 @@ static int watchdog_cdev_register(struct watchdog_device *wdd)
> if (IS_ERR_OR_NULL(watchdog_kworker))
> return -ENODEV;
>
> + device_initialize(&wd_data->dev);
> + wd_data->dev.devt = MKDEV(MAJOR(watchdog_devt), wdd->id);
> + wd_data->dev.class = &watchdog_class;
> + wd_data->dev.parent = wdd->parent;
> + wd_data->dev.groups = wdd->groups;
> + wd_data->dev.release = watchdog_core_data_release;
> + dev_set_drvdata(&wd_data->dev, wdd);
> + dev_set_name(&wd_data->dev, "watchdog%d", wdd->id);
> +
> kthread_init_work(&wd_data->work, watchdog_ping_work);
> hrtimer_init(&wd_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
> wd_data->timer.function = watchdog_timer_expired;
> @@ -967,15 +976,6 @@ static int watchdog_cdev_register(struct watchdog_device *wdd)
> }
> }
>
> - device_initialize(&wd_data->dev);
> - wd_data->dev.devt = MKDEV(MAJOR(watchdog_devt), wdd->id);
> - wd_data->dev.class = &watchdog_class;
> - wd_data->dev.parent = wdd->parent;
> - wd_data->dev.groups = wdd->groups;
> - wd_data->dev.release = watchdog_core_data_release;
> - dev_set_drvdata(&wd_data->dev, wdd);
> - dev_set_name(&wd_data->dev, "watchdog%d", wdd->id);
> -
> /* Fill in the data structures */
> cdev_init(&wd_data->cdev, &watchdog_fops);
>
> --
> 2.14.0
>
--
Best regards,
Alexander Sverdlin.
next prev parent reply other threads:[~2020-07-16 11:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-15 13:57 [PATCH] watchdog: initialize device before misc_register krzysztof.sobota
2020-07-15 15:09 ` Guenter Roeck
2020-07-16 8:31 ` [PATCH v2] " krzysztof.sobota
2020-07-16 11:32 ` [PATCH v3] " krzysztof.sobota
2020-07-16 11:48 ` Alexander Sverdlin [this message]
2020-07-16 14:00 ` Guenter Roeck
2020-07-16 14:06 Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e2b9f886-5a4e-91f3-59d1-c83a46149a82@nokia.com \
--to=alexander.sverdlin@nokia.com \
--cc=krzysztof.sobota@nokia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.