Commit cf08b628 authored by Rob Herring (Arm)'s avatar Rob Herring (Arm) Committed by Michael Ellerman
Browse files

powerpc/kexec: Use of_property_read_reg()



Replace open-coded parsing of "reg" property with
of_property_read_reg().

Signed-off-by: default avatarRob Herring (Arm) <robh@kernel.org>
[mpe: Rename end to size, add comment to the bail out case]
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240702210344.722364-1-robh@kernel.org
parent 353d7a84
Loading
Loading
Loading
Loading
+13 −24
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <linux/of_fdt.h>
#include <linux/libfdt.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/memblock.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
@@ -376,11 +377,10 @@ static int kdump_setup_usable_lmb(struct drmem_lmb *lmb, const __be32 **usm,
static int add_usable_mem_property(void *fdt, struct device_node *dn,
				   struct umem_info *um_info)
{
	int n_mem_addr_cells, n_mem_size_cells, node;
	int node;
	char path[NODE_PATH_LEN];
	int i, len, ranges, ret;
	const __be32 *prop;
	u64 base, end;
	int i, ret;
	u64 base, size;

	of_node_get(dn);

@@ -399,41 +399,30 @@ static int add_usable_mem_property(void *fdt, struct device_node *dn,
		goto out;
	}

	/* Get the address & size cells */
	n_mem_addr_cells = of_n_addr_cells(dn);
	n_mem_size_cells = of_n_size_cells(dn);
	kexec_dprintk("address cells: %d, size cells: %d\n", n_mem_addr_cells,
		      n_mem_size_cells);

	um_info->idx  = 0;
	if (!check_realloc_usable_mem(um_info, 2)) {
		ret = -ENOMEM;
		goto out;
	}

	prop = of_get_property(dn, "reg", &len);
	if (!prop || len <= 0) {
		ret = 0;
		goto out;
	}

	/*
	 * "reg" property represents sequence of (addr,size) tuples
	 * each representing a memory range.
	 */
	ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);

	for (i = 0; i < ranges; i++) {
		base = of_read_number(prop, n_mem_addr_cells);
		prop += n_mem_addr_cells;
		end = base + of_read_number(prop, n_mem_size_cells) - 1;
		prop += n_mem_size_cells;
	for (i = 0; ; i++) {
		ret = of_property_read_reg(dn, i, &base, &size);
		if (ret)
			break;

		ret = add_usable_mem(um_info, base, end);
		ret = add_usable_mem(um_info, base, base + size - 1);
		if (ret)
			goto out;
	}

	// No reg or empty reg? Skip this node.
	if (i == 0)
		goto out;

	/*
	 * No kdump kernel usable memory found in this memory node.
	 * Write (0,0) tuple in linux,usable-memory property for