[PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected

Sascha Hauer sha at pengutronix.de
Mon Jan 9 01:12:17 PST 2023


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 at 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 |



More information about the barebox mailing list