Skip to content

Commit cf08b62

Browse files
robherringmpe
authored andcommitted
powerpc/kexec: Use of_property_read_reg()
Replace open-coded parsing of "reg" property with of_property_read_reg(). Signed-off-by: Rob Herring (Arm) <[email protected]> [mpe: Rename end to size, add comment to the bail out case] Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent 353d7a8 commit cf08b62

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

arch/powerpc/kexec/file_load_64.c

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/of_fdt.h>
1919
#include <linux/libfdt.h>
2020
#include <linux/of.h>
21+
#include <linux/of_address.h>
2122
#include <linux/memblock.h>
2223
#include <linux/slab.h>
2324
#include <linux/vmalloc.h>
@@ -376,11 +377,10 @@ static int kdump_setup_usable_lmb(struct drmem_lmb *lmb, const __be32 **usm,
376377
static int add_usable_mem_property(void *fdt, struct device_node *dn,
377378
struct umem_info *um_info)
378379
{
379-
int n_mem_addr_cells, n_mem_size_cells, node;
380+
int node;
380381
char path[NODE_PATH_LEN];
381-
int i, len, ranges, ret;
382-
const __be32 *prop;
383-
u64 base, end;
382+
int i, ret;
383+
u64 base, size;
384384

385385
of_node_get(dn);
386386

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

402-
/* Get the address & size cells */
403-
n_mem_addr_cells = of_n_addr_cells(dn);
404-
n_mem_size_cells = of_n_size_cells(dn);
405-
kexec_dprintk("address cells: %d, size cells: %d\n", n_mem_addr_cells,
406-
n_mem_size_cells);
407-
408402
um_info->idx = 0;
409403
if (!check_realloc_usable_mem(um_info, 2)) {
410404
ret = -ENOMEM;
411405
goto out;
412406
}
413407

414-
prop = of_get_property(dn, "reg", &len);
415-
if (!prop || len <= 0) {
416-
ret = 0;
417-
goto out;
418-
}
419-
420408
/*
421409
* "reg" property represents sequence of (addr,size) tuples
422410
* each representing a memory range.
423411
*/
424-
ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
425-
426-
for (i = 0; i < ranges; i++) {
427-
base = of_read_number(prop, n_mem_addr_cells);
428-
prop += n_mem_addr_cells;
429-
end = base + of_read_number(prop, n_mem_size_cells) - 1;
430-
prop += n_mem_size_cells;
412+
for (i = 0; ; i++) {
413+
ret = of_property_read_reg(dn, i, &base, &size);
414+
if (ret)
415+
break;
431416

432-
ret = add_usable_mem(um_info, base, end);
417+
ret = add_usable_mem(um_info, base, base + size - 1);
433418
if (ret)
434419
goto out;
435420
}
436421

422+
// No reg or empty reg? Skip this node.
423+
if (i == 0)
424+
goto out;
425+
437426
/*
438427
* No kdump kernel usable memory found in this memory node.
439428
* Write (0,0) tuple in linux,usable-memory property for

0 commit comments

Comments
 (0)