34a28fa6fe35a4babf8c17d5f55fd1e1d2978391
[openwrt/staging/mans0n.git] /
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
5
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.
9
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>
14 ---
15 drivers/nvmem/core.c | 12 +++++++++---
16 1 file changed, 9 insertions(+), 3 deletions(-)
17
18 --- a/drivers/nvmem/core.c
19 +++ b/drivers/nvmem/core.c
20 @@ -810,18 +810,24 @@ struct nvmem_device *nvmem_register(cons
21
22 switch (config->id) {
23 case NVMEM_DEVID_NONE:
24 - dev_set_name(&nvmem->dev, "%s", config->name);
25 + rval = dev_set_name(&nvmem->dev, "%s", config->name);
26 break;
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);
30 break;
31 default:
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);
36 break;
37 }
38
39 + if (rval) {
40 + ida_free(&nvmem_ida, nvmem->id);
41 + kfree(nvmem);
42 + return ERR_PTR(rval);
43 + }
44 +
45 nvmem->read_only = device_property_present(config->dev, "read-only") ||
46 config->read_only || !nvmem->reg_write;
47