7951cc73004b86a44a69e2ddf74f584a6c8701d4
[openwrt/staging/mans0n.git] /
1 From de0534df93474f268486c486ea7e01b44a478026 Mon Sep 17 00:00:00 2001
2 From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
3 Date: Fri, 6 Aug 2021 09:59:47 +0100
4 Subject: [PATCH] nvmem: core: fix error handling while validating keepout
5 regions
6
7 Current error path on failure of validating keepout regions is calling
8 put_device, eventhough the device is not even registered at that point.
9
10 Fix this by adding proper error handling of freeing ida and nvmem.
11
12 Fixes: fd3bb8f54a88 ("nvmem: core: Add support for keepout regions")
13 Cc: <stable@vger.kernel.org>
14 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
15 Link: https://lore.kernel.org/r/20210806085947.22682-5-srinivas.kandagatla@linaro.org
16 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17 ---
18 drivers/nvmem/core.c | 7 +++++--
19 1 file changed, 5 insertions(+), 2 deletions(-)
20
21 --- a/drivers/nvmem/core.c
22 +++ b/drivers/nvmem/core.c
23 @@ -850,8 +850,11 @@ struct nvmem_device *nvmem_register(cons
24
25 if (nvmem->nkeepout) {
26 rval = nvmem_validate_keepouts(nvmem);
27 - if (rval)
28 - goto err_put_device;
29 + if (rval) {
30 + ida_free(&nvmem_ida, nvmem->id);
31 + kfree(nvmem);
32 + return ERR_PTR(rval);
33 + }
34 }
35
36 dev_dbg(&nvmem->dev, "Registering nvmem device %s\n", config->name);