From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
linux-kernel@vger.kernel.org,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
Dirk Behme <dirk.behme@de.bosch.com>
Subject: Re: [PATCH v3 2/3] driver core: introduce device_set_driver() helper
Date: Fri, 4 Apr 2025 07:17:34 +0900 [thread overview]
Message-ID: <20250404071734.29468deb59106b0310605c3e@kernel.org> (raw)
In-Reply-To: <20250311052417.1846985-2-dmitry.torokhov@gmail.com>
On Mon, 10 Mar 2025 22:24:15 -0700
Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> In preparation to closing a race when reading driver pointer in
> dev_uevent() code, instead of setting device->driver pointer directly
> introduce device_set_driver() helper.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
This looks good to me.
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks,
> ---
>
> v3: new patch introducing device_set_driver() helper (suggested by
> Rafael).
>
> drivers/base/base.h | 6 ++++++
> drivers/base/core.c | 2 +-
> drivers/base/dd.c | 7 +++----
> 3 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/base/base.h b/drivers/base/base.h
> index 0042e4774b0c..eb203cf8370b 100644
> --- a/drivers/base/base.h
> +++ b/drivers/base/base.h
> @@ -180,6 +180,12 @@ int driver_add_groups(const struct device_driver *drv, const struct attribute_gr
> void driver_remove_groups(const struct device_driver *drv, const struct attribute_group **groups);
> void device_driver_detach(struct device *dev);
>
> +static inline void device_set_driver(struct device *dev, const struct device_driver *drv)
> +{
> + // FIXME - this cast should not be needed "soon"
> + dev->driver = (struct device_driver *)drv;
> +}
> +
> int devres_release_all(struct device *dev);
> void device_block_probing(void);
> void device_unblock_probing(void);
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index f9c1c623bca5..b000ee61c149 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3697,7 +3697,7 @@ int device_add(struct device *dev)
> device_pm_remove(dev);
> dpm_sysfs_remove(dev);
> DPMError:
> - dev->driver = NULL;
> + device_set_driver(dev, NULL);
> bus_remove_device(dev);
> BusError:
> device_remove_attrs(dev);
> diff --git a/drivers/base/dd.c b/drivers/base/dd.c
> index f0e4b4aba885..b526e0e0f52d 100644
> --- a/drivers/base/dd.c
> +++ b/drivers/base/dd.c
> @@ -550,7 +550,7 @@ static void device_unbind_cleanup(struct device *dev)
> arch_teardown_dma_ops(dev);
> kfree(dev->dma_range_map);
> dev->dma_range_map = NULL;
> - dev->driver = NULL;
> + device_set_driver(dev, NULL);
> dev_set_drvdata(dev, NULL);
> if (dev->pm_domain && dev->pm_domain->dismiss)
> dev->pm_domain->dismiss(dev);
> @@ -629,8 +629,7 @@ static int really_probe(struct device *dev, const struct device_driver *drv)
> }
>
> re_probe:
> - // FIXME - this cast should not be needed "soon"
> - dev->driver = (struct device_driver *)drv;
> + device_set_driver(dev, drv);
>
> /* If using pinctrl, bind pins now before probing */
> ret = pinctrl_bind_pins(dev);
> @@ -1014,7 +1013,7 @@ static int __device_attach(struct device *dev, bool allow_async)
> if (ret == 0)
> ret = 1;
> else {
> - dev->driver = NULL;
> + device_set_driver(dev, NULL);
> ret = 0;
> }
> } else {
> --
> 2.49.0.rc0.332.g42c0ae87b1-goog
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2025-04-03 22:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-11 5:24 [PATCH v3 1/3] Revert "drivers: core: synchronize really_probe() and dev_uevent()" Dmitry Torokhov
2025-03-11 5:24 ` [PATCH v3 2/3] driver core: introduce device_set_driver() helper Dmitry Torokhov
2025-04-03 22:17 ` Masami Hiramatsu [this message]
2025-03-11 5:24 ` [PATCH v3 3/3] driver core: fix potential NULL pointer dereference in dev_uevent() Dmitry Torokhov
2025-04-03 22:20 ` Masami Hiramatsu
2025-04-03 4:08 ` [PATCH v3 1/3] Revert "drivers: core: synchronize really_probe() and dev_uevent()" Masami Hiramatsu
2026-03-20 6:16 ` Aditya Garg
2026-03-20 7:24 ` Dmitry Torokhov
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=20250404071734.29468deb59106b0310605c3e@kernel.org \
--to=mhiramat@kernel.org \
--cc=dakr@kernel.org \
--cc=dirk.behme@de.bosch.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox