]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
nvmem: core: fix possibly memleak when use nvmem_cell_info_to_nvmem_cell()
authorVadym Kochan <vadym.kochan@plvision.eu>
Wed, 23 Sep 2020 20:44:56 +0000 (23:44 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 09:07:45 +0000 (10:07 +0100)
commit70f1f999e24df212e09784a29a58bf77ec29b5eb
tree45a7feb9362458a441060a223e63d7487a03bfb6
parentb21749762534ad08ab1c2cd96d5acb025862c29f
nvmem: core: fix possibly memleak when use nvmem_cell_info_to_nvmem_cell()

[ Upstream commit fc9eec4d643597cf4cb2fef17d48110e677610da ]

Fix missing 'kfree_const(cell->name)' when call to
nvmem_cell_info_to_nvmem_cell() in several places:

     * after nvmem_cell_info_to_nvmem_cell() failed during
       nvmem_add_cells()

     * during nvmem_device_cell_{read,write} when cell->name is
       kstrdup'ed() without calling kfree_const() at the end, but
       really there is no reason to do that 'dup, because the cell
       instance is allocated on the stack for some short period to be
       read/write without exposing it to the caller.

So the new nvmem_cell_info_to_nvmem_cell_nodup() helper is introduced
which is used to convert cell_info -> cell without name duplication as
a lighweight version of nvmem_cell_info_to_nvmem_cell().

Fixes: e2a5402ec7c6 ("nvmem: Add nvmem_device based consumer apis.")
Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Vadym Kochan <vadym.kochan@plvision.eu>
Link: https://lore.kernel.org/r/20200923204456.14032-1-vadym.kochan@plvision.eu
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvmem/core.c