RE: [PATCH] dax: Check dev_set_name() return value
From: Dan Williams
Date: Tue Sep 20 2022 - 13:38:52 EST
Bo Liu wrote:
> It's possible that dev_set_name() returns -ENOMEM, catch and handle this.
>
> Signed-off-by: Bo Liu <liubo03@xxxxxxxxxx>
> ---
> drivers/dax/bus.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
> index 1dad813ee4a6..36cf245ee467 100644
> --- a/drivers/dax/bus.c
> +++ b/drivers/dax/bus.c
> @@ -765,7 +765,12 @@ static int devm_register_dax_mapping(struct dev_dax *dev_dax, int range_id)
> device_initialize(dev);
> dev->parent = &dev_dax->dev;
> dev->type = &dax_mapping_type;
> - dev_set_name(dev, "mapping%d", mapping->id);
> + rc = dev_set_name(dev, "mapping%d", mapping->id);
> + if (rc) {
> + kfree(mapping);
No, this needs to trigger put_device() otherwise it leaks mapping->id.