mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected
@ 2023-01-09  8:35 Ahmad Fatoum
  2023-01-09  8:35 ` [PATCH master 2/3] efi: acpi: add SDT resource before registering device Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-09  8:35 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

For drivers that create new virtual child devices, error paths often
tend to use dev_name() on the uninitialized device via the dev_ family
of logging functions. Many such uninitialized devices have a name set
already though, but just lacks registration, which leads to dev_id
returning dev->unique_name, which may be NULL. Change dev_name to
return dev->name if dev->unique_name is NULL.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 include/driver.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/driver.h b/include/driver.h
index 693d5cb3e580..4d500ed21e34 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -191,7 +191,9 @@ static inline const char *dev_id(const struct device *dev)
 
 static inline const char *dev_name(const struct device *dev)
 {
-	return dev_id(dev);
+	if (!dev)
+		return NULL;
+	return dev_id(dev) ?: dev->name;
 }
 
 int dev_set_name(struct device *dev, const char *fmt, ...);
-- 
2.38.1




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH master 2/3] efi: acpi: add SDT resource before registering device
  2023-01-09  8:35 [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Ahmad Fatoum
@ 2023-01-09  8:35 ` Ahmad Fatoum
  2023-01-09  8:36 ` [PATCH master 3/3] reset: core: support deep probe with resets registered in CLK_OF_DECLARE Ahmad Fatoum
  2023-01-09  9:12 ` [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-09  8:35 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Registering a device may end up probing the device if a driver is
readily available. This necessitates the device having its resources
assigned before doing the registration.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 drivers/bus/acpi.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/bus/acpi.c b/drivers/bus/acpi.c
index 354a6119b92f..f69789200633 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -122,18 +122,12 @@ static void acpi_devinfo(struct device *dev)
 
 static int acpi_register_device(struct device *dev, struct acpi_sdt *sdt)
 {
-	int ret;
-
-	ret = register_device(dev);
-	if (ret)
-		return ret;
-
 	device_add_resource(dev, "SDT", (resource_size_t)sdt, sdt->len,
 		IORESOURCE_MEM | IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY);
 
-	dev_dbg(dev, "registered as ACPI device\n");
+	dev_dbg(dev, "registering as ACPI device\n");
 
-	return 0;
+	return register_device(dev);
 }
 
 static struct device *acpi_add_device(struct bus_type *bus,
-- 
2.38.1




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH master 3/3] reset: core: support deep probe with resets registered in CLK_OF_DECLARE
  2023-01-09  8:35 [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Ahmad Fatoum
  2023-01-09  8:35 ` [PATCH master 2/3] efi: acpi: add SDT resource before registering device Ahmad Fatoum
@ 2023-01-09  8:36 ` Ahmad Fatoum
  2023-01-09  9:12 ` [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-09  8:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We already have such an exception for clocks, which may be registered
early outside the driver model using CLK_OF_DECLARE. Add a further
exception for reset controllers, so they too may be registered in
CLK_OF_DECLARE on a deep probe system. Checking for success of
of_device_ensure_probed() here isn't necessary anyways, because if
there is no provider, the list_for_each_entry loop below won't find
any and error is propagated.

Another solution would be to rewrite deep probe drivers to use
the driver model instead of CLK_OF_DECLARE, but this error case
if not very obvious, so save others time by just allowing it.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 drivers/reset/core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 31fac2de0347..5ab21ac95e3a 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -192,9 +192,8 @@ static struct reset_control *of_reset_control_get_by_index(struct device_node *n
 	if (ret)
 		return ERR_PTR(ret);
 
-	ret = of_device_ensure_probed(args.np);
-	if (ret)
-		return ERR_PTR(ret);
+	/* Ignore error, as CLK_OF_DECLARE resets have no proper driver. */
+	of_device_ensure_probed(args.np);
 
 	rcdev = NULL;
 	list_for_each_entry(r, &reset_controller_list, list) {
-- 
2.38.1




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected
  2023-01-09  8:35 [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Ahmad Fatoum
  2023-01-09  8:35 ` [PATCH master 2/3] efi: acpi: add SDT resource before registering device Ahmad Fatoum
  2023-01-09  8:36 ` [PATCH master 3/3] reset: core: support deep probe with resets registered in CLK_OF_DECLARE Ahmad Fatoum
@ 2023-01-09  9:12 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2023-01-09  9:12 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Jan 09, 2023 at 09:35:58AM +0100, Ahmad Fatoum wrote:
> For drivers that create new virtual child devices, error paths often
> tend to use dev_name() on the uninitialized device via the dev_ family
> of logging functions. Many such uninitialized devices have a name set
> already though, but just lacks registration, which leads to dev_id
> returning dev->unique_name, which may be NULL. Change dev_name to
> return dev->name if dev->unique_name is NULL.
> 
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
>  include/driver.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/include/driver.h b/include/driver.h
> index 693d5cb3e580..4d500ed21e34 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -191,7 +191,9 @@ static inline const char *dev_id(const struct device *dev)
>  
>  static inline const char *dev_name(const struct device *dev)
>  {
> -	return dev_id(dev);
> +	if (!dev)
> +		return NULL;
> +	return dev_id(dev) ?: dev->name;
>  }
>  
>  int dev_set_name(struct device *dev, const char *fmt, ...);
> -- 
> 2.38.1
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-09  9:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09  8:35 [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Ahmad Fatoum
2023-01-09  8:35 ` [PATCH master 2/3] efi: acpi: add SDT resource before registering device Ahmad Fatoum
2023-01-09  8:36 ` [PATCH master 3/3] reset: core: support deep probe with resets registered in CLK_OF_DECLARE Ahmad Fatoum
2023-01-09  9:12 ` [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox