mirror of
https://github.com/torvalds/linux.git
synced 2026-06-05 04:56:13 +02:00
nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()
Convert nvmem_add_cells_from_of() to use the new nvmem_add_one_cell(). This will remove duplicate code and it will make it possible to add a hook to a nvmem layout in between, which can change fields before the cell is finally added. Signed-off-by: Michael Walle <michael@walle.cc> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Link: https://lore.kernel.org/r/20230206134356.839737-17-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
2ded6830d3
commit
50014d6596
|
|
@ -688,15 +688,14 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
|
||||||
|
|
||||||
static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
|
static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
|
||||||
{
|
{
|
||||||
struct device_node *parent, *child;
|
|
||||||
struct device *dev = &nvmem->dev;
|
struct device *dev = &nvmem->dev;
|
||||||
struct nvmem_cell_entry *cell;
|
struct device_node *child;
|
||||||
const __be32 *addr;
|
const __be32 *addr;
|
||||||
int len;
|
int len, ret;
|
||||||
|
|
||||||
parent = dev->of_node;
|
for_each_child_of_node(dev->of_node, child) {
|
||||||
|
struct nvmem_cell_info info = {0};
|
||||||
|
|
||||||
for_each_child_of_node(parent, child) {
|
|
||||||
addr = of_get_property(child, "reg", &len);
|
addr = of_get_property(child, "reg", &len);
|
||||||
if (!addr)
|
if (!addr)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -706,40 +705,24 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell = kzalloc(sizeof(*cell), GFP_KERNEL);
|
info.offset = be32_to_cpup(addr++);
|
||||||
if (!cell) {
|
info.bytes = be32_to_cpup(addr);
|
||||||
of_node_put(child);
|
info.name = kasprintf(GFP_KERNEL, "%pOFn", child);
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
cell->nvmem = nvmem;
|
|
||||||
cell->offset = be32_to_cpup(addr++);
|
|
||||||
cell->bytes = be32_to_cpup(addr);
|
|
||||||
cell->name = kasprintf(GFP_KERNEL, "%pOFn", child);
|
|
||||||
|
|
||||||
addr = of_get_property(child, "bits", &len);
|
addr = of_get_property(child, "bits", &len);
|
||||||
if (addr && len == (2 * sizeof(u32))) {
|
if (addr && len == (2 * sizeof(u32))) {
|
||||||
cell->bit_offset = be32_to_cpup(addr++);
|
info.bit_offset = be32_to_cpup(addr++);
|
||||||
cell->nbits = be32_to_cpup(addr);
|
info.nbits = be32_to_cpup(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell->nbits)
|
info.np = of_node_get(child);
|
||||||
cell->bytes = DIV_ROUND_UP(
|
|
||||||
cell->nbits + cell->bit_offset,
|
|
||||||
BITS_PER_BYTE);
|
|
||||||
|
|
||||||
if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
|
ret = nvmem_add_one_cell(nvmem, &info);
|
||||||
dev_err(dev, "cell %s unaligned to nvmem stride %d\n",
|
kfree(info.name);
|
||||||
cell->name, nvmem->stride);
|
if (ret) {
|
||||||
/* Cells already added will be freed later. */
|
|
||||||
kfree_const(cell->name);
|
|
||||||
kfree(cell);
|
|
||||||
of_node_put(child);
|
of_node_put(child);
|
||||||
return -EINVAL;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
cell->np = of_node_get(child);
|
|
||||||
nvmem_cell_entry_add(cell);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user