From: Heiner Kallweit Date: Fri, 9 Jun 2017 09:59:09 +0000 (+0100) Subject: nvmem: core: add locking to nvmem_find_cell X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=666d6a36234f3123e909165ac32ea692213f0155;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git nvmem: core: add locking to nvmem_find_cell Adding entries to nvmem_cells and deleting entries from it is protected by nvmem_cells_mutex. Therefore this mutex should also protect iterating over the list. Signed-off-by: Heiner Kallweit Signed-off-by: Srinivas Kandagatla Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 0cbac71195b5..4c49285168fb 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -287,9 +287,15 @@ static struct nvmem_cell *nvmem_find_cell(const char *cell_id) { struct nvmem_cell *p; + mutex_lock(&nvmem_cells_mutex); + list_for_each_entry(p, &nvmem_cells, node) - if (p && !strcmp(p->name, cell_id)) + if (p && !strcmp(p->name, cell_id)) { + mutex_unlock(&nvmem_cells_mutex); return p; + } + + mutex_unlock(&nvmem_cells_mutex); return NULL; }