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.

of/fdt: Consolidate duplicate code into helper functions

Currently, there are many pieces of nearly identical code scattered across
different places. Consolidate the duplicate code into helper functions to
improve maintainability and reduce the likelihood of errors.

Signed-off-by: Yuntao Wang <yuntao.wang@linux.dev>
Link: https://patch.msgid.link/20251115134753.179931-2-yuntao.wang@linux.dev
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

authored by

Yuntao Wang and committed by
Rob Herring (Arm)
8278cb72 a5387fbc

+50
+41
drivers/of/fdt.c
··· 625 625 return fdt_getprop(initial_boot_params, node, name, size); 626 626 } 627 627 628 + const __be32 *__init of_flat_dt_get_addr_size_prop(unsigned long node, 629 + const char *name, 630 + int *entries) 631 + { 632 + const __be32 *prop; 633 + int len, elen = (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32); 634 + 635 + prop = of_get_flat_dt_prop(node, name, &len); 636 + if (!prop || len % elen) { 637 + *entries = 0; 638 + return NULL; 639 + } 640 + 641 + *entries = len / elen; 642 + return prop; 643 + } 644 + 645 + bool __init of_flat_dt_get_addr_size(unsigned long node, const char *name, 646 + u64 *addr, u64 *size) 647 + { 648 + const __be32 *prop; 649 + int entries; 650 + 651 + prop = of_flat_dt_get_addr_size_prop(node, name, &entries); 652 + if (!prop || entries != 1) 653 + return false; 654 + 655 + of_flat_dt_read_addr_size(prop, 0, addr, size); 656 + return true; 657 + } 658 + 659 + void __init of_flat_dt_read_addr_size(const __be32 *prop, int entry_index, 660 + u64 *addr, u64 *size) 661 + { 662 + int entry_cells = dt_root_addr_cells + dt_root_size_cells; 663 + prop += entry_cells * entry_index; 664 + 665 + *addr = dt_mem_next_cell(dt_root_addr_cells, &prop); 666 + *size = dt_mem_next_cell(dt_root_size_cells, &prop); 667 + } 668 + 628 669 /** 629 670 * of_fdt_is_compatible - Return true if given node from the given blob has 630 671 * compat in its compatible list
+9
include/linux/of_fdt.h
··· 55 55 const char *uname); 56 56 extern const void *of_get_flat_dt_prop(unsigned long node, const char *name, 57 57 int *size); 58 + 59 + extern const __be32 *of_flat_dt_get_addr_size_prop(unsigned long node, 60 + const char *name, 61 + int *entries); 62 + extern bool of_flat_dt_get_addr_size(unsigned long node, const char *name, 63 + u64 *addr, u64 *size); 64 + extern void of_flat_dt_read_addr_size(const __be32 *prop, int entry_index, 65 + u64 *addr, u64 *size); 66 + 58 67 extern int of_flat_dt_is_compatible(unsigned long node, const char *name); 59 68 extern unsigned long of_get_flat_dt_root(void); 60 69 extern uint32_t of_get_flat_dt_phandle(unsigned long node);