Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 824a6c4c authored by Srinivas Kandagatla's avatar Srinivas Kandagatla Committed by Mark Salyzyn
Browse files

BACKPORT: nvmem: core: fix regression in of_nvmem_cell_get()



NVMEM DT support seems to be totally broken after
commit e888d445ac33 ("nvmem: resolve cells from DT at registration time")
Fix this!

Index used in of_nvmem_cell_get() to find cell is specific to
consumer, It can not be used for searching the cell in provider.
Use device_node instead of this to find the matching cell in device
tree case.

Fixes: e888d445ac33 ("nvmem: resolve cells from DT at registration time")
Reported-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Tested-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Git-commit: 0749aa25af82c690395a96e799cd2c6e54c459cf
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git


[gkohli@codeaurora: Resolve trivial merge conflicts]
Signed-off-by: default avatarGaurav Kohli <gkohli@codeaurora.org>
(cherry picked from commit 0749aa25af82c690395a96e799cd2c6e54c459cf)
Signed-off-by: default avatarMark Salyzyn <salyzyn@google.com>
Bug: 150014847
Change-Id: I856c6f71c7da7ab50966dabd700ae1513ea16fa6
parent 630590db
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ struct nvmem_cell {
	int			bytes;
	int			bit_offset;
	int			nbits;
	struct device_node	*np;
	struct nvmem_device	*nvmem;
	struct list_head	node;
};
@@ -304,6 +305,7 @@ static void nvmem_cell_drop(struct nvmem_cell *cell)
	mutex_lock(&nvmem_cells_mutex);
	list_del(&cell->node);
	mutex_unlock(&nvmem_cells_mutex);
	of_node_put(cell->np);
	kfree(cell);
}

@@ -468,6 +470,7 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
			return -ENOMEM;

		cell->nvmem = nvmem;
		cell->np = of_node_get(child);
		cell->offset = be32_to_cpup(addr++);
		cell->bytes = be32_to_cpup(addr);
		cell->name = child->name;
@@ -892,14 +895,13 @@ static struct nvmem_cell *nvmem_cell_get_from_list(const char *cell_id)

#if IS_ENABLED(CONFIG_OF)
static struct nvmem_cell *
nvmem_find_cell_by_index(struct nvmem_device *nvmem, int index)
nvmem_find_cell_by_node(struct nvmem_device *nvmem, struct device_node *np)
{
	struct nvmem_cell *cell = NULL;
	int i = 0;

	mutex_lock(&nvmem_mutex);
	list_for_each_entry(cell, &nvmem_cells, node) {
		if (index == i++)
		if (np == cell->np)
			break;
	}
	mutex_unlock(&nvmem_mutex);
@@ -944,7 +946,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
	if (IS_ERR(nvmem))
		return ERR_CAST(nvmem);

	cell = nvmem_find_cell_by_index(nvmem, index);
	cell = nvmem_find_cell_by_node(nvmem, cell_np);
	if (!cell) {
		__nvmem_device_put(nvmem);
		return ERR_PTR(-ENOENT);