1 From 5544e90c81261e82e02bbf7c6015a4b9c8c825ef Mon Sep 17 00:00:00 2001
2 From: Gaosheng Cui <cuigaosheng1@huawei.com>
3 Date: Fri, 16 Sep 2022 13:20:50 +0100
4 Subject: [PATCH] nvmem: core: add error handling for dev_set_name
6 The type of return value of dev_set_name is int, which may return
7 wrong result, so we add error handling for it to reclaim memory
8 of nvmem resource, and return early when an error occurs.
10 Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
11 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
12 Link: https://lore.kernel.org/r/20220916122100.170016-4-srinivas.kandagatla@linaro.org
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
15 drivers/nvmem/core.c | 12 +++++++++---
16 1 file changed, 9 insertions(+), 3 deletions(-)
18 --- a/drivers/nvmem/core.c
19 +++ b/drivers/nvmem/core.c
20 @@ -809,18 +809,24 @@ struct nvmem_device *nvmem_register(cons
23 case NVMEM_DEVID_NONE:
24 - dev_set_name(&nvmem->dev, "%s", config->name);
25 + rval = dev_set_name(&nvmem->dev, "%s", config->name);
27 case NVMEM_DEVID_AUTO:
28 - dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id);
29 + rval = dev_set_name(&nvmem->dev, "%s%d", config->name, nvmem->id);
32 - dev_set_name(&nvmem->dev, "%s%d",
33 + rval = dev_set_name(&nvmem->dev, "%s%d",
34 config->name ? : "nvmem",
35 config->name ? config->id : nvmem->id);
40 + ida_free(&nvmem_ida, nvmem->id);
42 + return ERR_PTR(rval);
45 nvmem->read_only = device_property_present(config->dev, "read-only") ||
46 config->read_only || !nvmem->reg_write;