nvmem: core: add locking to nvmem_find_cell
authorHeiner Kallweit <hkallweit1@gmail.com>
Fri, 9 Jun 2017 09:59:09 +0000 (10:59 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Jun 2017 10:08:27 +0000 (12:08 +0200)
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 <hkallweit1@gmail.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/core.c

index 0cbac71195b5e06c6786f07b5bd95913ae3a7ec3..4c49285168fb79afe7a46cd917b356f5fb260275 100644 (file)
@@ -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;
 }