Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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) <robh@kernel.org>
[mpe: Rename end to size, add comment to the bail out case]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240702210344.722364-1-robh@kernel.org

authored by

Rob Herring (Arm) and committed by
Michael Ellerman
cf08b628 353d7a84

+13 -24
+13 -24
arch/powerpc/kexec/file_load_64.c
··· 18 18 #include <linux/of_fdt.h> 19 19 #include <linux/libfdt.h> 20 20 #include <linux/of.h> 21 + #include <linux/of_address.h> 21 22 #include <linux/memblock.h> 22 23 #include <linux/slab.h> 23 24 #include <linux/vmalloc.h> ··· 377 376 static int add_usable_mem_property(void *fdt, struct device_node *dn, 378 377 struct umem_info *um_info) 379 378 { 380 - int n_mem_addr_cells, n_mem_size_cells, node; 379 + int node; 381 380 char path[NODE_PATH_LEN]; 382 - int i, len, ranges, ret; 383 - const __be32 *prop; 384 - u64 base, end; 381 + int i, ret; 382 + u64 base, size; 385 383 386 384 of_node_get(dn); 387 385 ··· 399 399 goto out; 400 400 } 401 401 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 - 408 402 um_info->idx = 0; 409 403 if (!check_realloc_usable_mem(um_info, 2)) { 410 404 ret = -ENOMEM; 411 - goto out; 412 - } 413 - 414 - prop = of_get_property(dn, "reg", &len); 415 - if (!prop || len <= 0) { 416 - ret = 0; 417 405 goto out; 418 406 } 419 407 ··· 409 421 * "reg" property represents sequence of (addr,size) tuples 410 422 * each representing a memory range. 411 423 */ 412 - ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells); 424 + for (i = 0; ; i++) { 425 + ret = of_property_read_reg(dn, i, &base, &size); 426 + if (ret) 427 + break; 413 428 414 - for (i = 0; i < ranges; i++) { 415 - base = of_read_number(prop, n_mem_addr_cells); 416 - prop += n_mem_addr_cells; 417 - end = base + of_read_number(prop, n_mem_size_cells) - 1; 418 - prop += n_mem_size_cells; 419 - 420 - ret = add_usable_mem(um_info, base, end); 429 + ret = add_usable_mem(um_info, base, base + size - 1); 421 430 if (ret) 422 431 goto out; 423 432 } 433 + 434 + // No reg or empty reg? Skip this node. 435 + if (i == 0) 436 + goto out; 424 437 425 438 /* 426 439 * No kdump kernel usable memory found in this memory node.