Re: [PATCH 16/36] sh: dma-sysfs: move to use bus_get_dev_root()

From: John Paul Adrian Glaubitz
Date: Mon Mar 13 2023 - 14:50:15 EST


Hi Greg!

On Mon, 2023-03-13 at 19:28 +0100, Greg Kroah-Hartman wrote:
> Direct access to the struct bus_type dev_root pointer is going away soon
> so replace that with a call to bus_get_dev_root() instead, which is what
> it is there for.
>
> Cc: Yoshinori Sato <ysato@xxxxxxxxxxxxxxxxxxxx>
> Cc: Rich Felker <dalias@xxxxxxxx>
> Cc: linux-sh@xxxxxxxxxxxxxxx
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> ---
> Note, this is a patch that is a prepatory cleanup as part of a larger
> series of patches that is working on resolving some old driver core
> design mistakes. It will build and apply cleanly on top of 6.3-rc2 on
> its own, but I'd prefer if I could take it through my driver-core tree
> so that the driver core changes can be taken through there for 6.4-rc1.
>
> arch/sh/drivers/dma/dma-sysfs.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/arch/sh/drivers/dma/dma-sysfs.c b/arch/sh/drivers/dma/dma-sysfs.c
> index 8ef318150f84..431bc18f0a41 100644
> --- a/arch/sh/drivers/dma/dma-sysfs.c
> +++ b/arch/sh/drivers/dma/dma-sysfs.c
> @@ -45,13 +45,19 @@ static DEVICE_ATTR(devices, S_IRUGO, dma_show_devices, NULL);
>
> static int __init dma_subsys_init(void)
> {
> + struct device *dev_root;
> int ret;
>
> ret = subsys_system_register(&dma_subsys, NULL);
> if (unlikely(ret))
> return ret;
>
> - return device_create_file(dma_subsys.dev_root, &dev_attr_devices);
> + dev_root = bus_get_dev_root(&dma_subsys);
> + if (dev_root) {
> + ret = device_create_file(dev_root, &dev_attr_devices);
> + put_device(dev_root);
> + }
> + return ret;
> }
> postcore_initcall(dma_subsys_init);
>

After acking this, I noticed that if bus_get_dev_root() fails, "ret" remains
set to the value by subsys_system_register() which might confuse the caller
thinking that dma_subsys_init() succeeded unless I am missing something?

Adrian

--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer
`. `' Physicist
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913