Re: [PATCH v3 4/5] nvmem: core: fix cleanup after dev_set_name()
From: Dan Carpenter
Date: Wed Jan 04 2023 - 23:24:29 EST
- Next message: Stephen Rothwell: "Re: linux-next: build failure after merge of the kspp tree"
- Previous message: Yangtao Li: "[PATCH] f2fs: use iostat_lat_type directly as a parameter in the iostat_update_and_unbind_ctx()"
- In reply to: Russell King (Oracle): "[PATCH v3 4/5] nvmem: core: fix cleanup after dev_set_name() Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>,Gaosheng Cui <cuigaosheng1@xxxxxxxxxx>,Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>,linux-arm-kernel@xxxxxxxxxxxxxxxxxxx,linux-kernel@xxxxxxxxxxxxxxx,Maxime Ripard <mripard@xxxxxxxxxx>, Hector Martin <marcan@xxxxxxxxx>"
- Next in thread: Russell King (Oracle): "[PATCH v3 5/5] nvmem: core: fix registration vs use race Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>,Gaosheng Cui <cuigaosheng1@xxxxxxxxxx>,Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>,linux-arm-kernel@xxxxxxxxxxxxxxxxxxx,linux-kernel@xxxxxxxxxxxxxxx,Maxime Ripard <mripard@xxxxxxxxxx>, Hector Martin <marcan@xxxxxxxxx>"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Jan 03, 2023 at 04:59:32PM +0000, Russell King (Oracle) wrote:
> If dev_set_name() fails, we leak nvmem->wp_gpio as the cleanup does not
> put this. While a minimal fix for this would be to add the gpiod_put()
> call, we can do better if we split device_register(), and use the
> tested nvmem_release() cleanup code by initialising the device early,
> and putting the device.
>
> This results in a slightly larger fix, but results in clear code.
>
> Note: this patch depends on "nvmem: core: initialise nvmem->id early"
> and "nvmem: core: remove nvmem_config wp_gpio".
>
> Fixes: 5544e90c8126 ("nvmem: core: add error handling for dev_set_name")
> Signed-off-by: Russell King (Oracle) <rmk+kernel@xxxxxxxxxxxxxxx>
> ---
> drivers/nvmem/core.c | 26 +++++++++++---------------
> 1 file changed, 11 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 843e2f5696e6..19497f555e07 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -772,15 +772,17 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
>
> nvmem->id = rval;
>
> + nvmem->dev.type = &nvmem_provider_type;
> + nvmem->dev.bus = &nvmem_bus_type;
> + nvmem->dev.parent = config->dev;
> +
> + device_initialize(&nvmem->dev);
> +
> if (!config->ignore_wp)
> nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
> GPIOD_OUT_HIGH);
> - if (IS_ERR(nvmem->wp_gpio)) {
> - ida_free(&nvmem_ida, nvmem->id);
> - rval = PTR_ERR(nvmem->wp_gpio);
> - kfree(nvmem);
> - return ERR_PTR(rval);
> - }
> + if (IS_ERR(nvmem->wp_gpio))
> + goto err_put_device;
>
Missing error code. It still needs the rval = PTR_ERR(nvmem->wp_gpio);
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <error27@xxxxxxxxx>
regards,
dan carpenter
- Next message: Stephen Rothwell: "Re: linux-next: build failure after merge of the kspp tree"
- Previous message: Yangtao Li: "[PATCH] f2fs: use iostat_lat_type directly as a parameter in the iostat_update_and_unbind_ctx()"
- In reply to: Russell King (Oracle): "[PATCH v3 4/5] nvmem: core: fix cleanup after dev_set_name() Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>,Gaosheng Cui <cuigaosheng1@xxxxxxxxxx>,Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>,linux-arm-kernel@xxxxxxxxxxxxxxxxxxx,linux-kernel@xxxxxxxxxxxxxxx,Maxime Ripard <mripard@xxxxxxxxxx>, Hector Martin <marcan@xxxxxxxxx>"
- Next in thread: Russell King (Oracle): "[PATCH v3 5/5] nvmem: core: fix registration vs use race Bartosz Golaszewski <bgolaszewski@xxxxxxxxxxxx>,Gaosheng Cui <cuigaosheng1@xxxxxxxxxx>,Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>,linux-arm-kernel@xxxxxxxxxxxxxxxxxxx,linux-kernel@xxxxxxxxxxxxxxx,Maxime Ripard <mripard@xxxxxxxxxx>, Hector Martin <marcan@xxxxxxxxx>"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]