8f996eab348ff4890a8e8f78ca14fb72f6e1e401
[librecmc/librecmc.git] /
1 From cc5bdd323dde6494623f3ffe3a5b887fa21cd375 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Mon, 6 Feb 2023 13:43:48 +0000
4 Subject: [PATCH] nvmem: core: drop the removal of the cells in
5  nvmem_add_cells()
6
7 If nvmem_add_cells() fails, the whole nvmem_register() will fail
8 and the cells will then be removed anyway. This is a preparation
9 to introduce a nvmem_add_one_cell() which can then be used by
10 nvmem_add_cells().
11
12 This is then the same to what nvmem_add_cells_from_table() and
13 nvmem_add_cells_from_of() do.
14
15 Signed-off-by: Michael Walle <michael@walle.cc>
16 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
17 Link: https://lore.kernel.org/r/20230206134356.839737-15-srinivas.kandagatla@linaro.org
18 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 ---
20  drivers/nvmem/core.c | 14 ++++----------
21  1 file changed, 4 insertions(+), 10 deletions(-)
22
23 --- a/drivers/nvmem/core.c
24 +++ b/drivers/nvmem/core.c
25 @@ -515,7 +515,7 @@ static int nvmem_add_cells(struct nvmem_
26                     int ncells)
27  {
28         struct nvmem_cell_entry **cells;
29 -       int i, rval;
30 +       int i, rval = 0;
31  
32         cells = kcalloc(ncells, sizeof(*cells), GFP_KERNEL);
33         if (!cells)
34 @@ -525,28 +525,22 @@ static int nvmem_add_cells(struct nvmem_
35                 cells[i] = kzalloc(sizeof(**cells), GFP_KERNEL);
36                 if (!cells[i]) {
37                         rval = -ENOMEM;
38 -                       goto err;
39 +                       goto out;
40                 }
41  
42                 rval = nvmem_cell_info_to_nvmem_cell_entry(nvmem, &info[i], cells[i]);
43                 if (rval) {
44                         kfree(cells[i]);
45 -                       goto err;
46 +                       goto out;
47                 }
48  
49                 nvmem_cell_entry_add(cells[i]);
50         }
51  
52 +out:
53         /* remove tmp array */
54         kfree(cells);
55  
56 -       return 0;
57 -err:
58 -       while (i--)
59 -               nvmem_cell_entry_drop(cells[i]);
60 -
61 -       kfree(cells);
62 -
63         return rval;
64  }
65