From d698a388146c5ba72e7cf7e79f13932f2046bf29 Mon Sep 17 00:00:00 2001 From: Krishna Reddy Date: Wed, 22 May 2019 16:17:11 +0530 Subject: of: reserved-memory: ignore disabled memory-region nodes Ignore disabled nodes in the memory-region nodes list and continue to initialize the rest of enabled nodes. Check if the "reserved-memory" node is available and if it's not available, return 0 to ignore the "reserved-memory" node and continue parsing with next node in memory-region nodes list. Signed-off-by: Krishna Reddy Signed-off-by: Puneet Saxena Signed-off-by: Rob Herring --- drivers/of/of_reserved_mem.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 89e190e94af7..7989703b883c 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -324,6 +324,9 @@ int of_reserved_mem_device_init_by_idx(struct device *dev, if (!target) return -ENODEV; + if (!of_device_is_available(target)) + return 0; + rmem = __find_rmem(target); of_node_put(target); -- cgit v1.2.3-59-g8ed1b From 9b4d2b635bd0cf8dfc45223f66fd85792fd2dc7b Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Tue, 14 May 2019 13:40:52 -0700 Subject: of/fdt: Remove dead code and mark functions with __init Some functions in here are never called, and others are only called during __init. Remove the dead code and some dead exports for functions that don't exist (I'm looking at you of_fdt_get_string!). Mark some functions with __init so we can throw them away after we boot up and poke at the FDT blob too. Cc: Hsin-Yi Wang Signed-off-by: Stephen Boyd Signed-off-by: Rob Herring --- drivers/of/fdt.c | 37 +++++-------------------------------- include/linux/of_fdt.h | 11 ----------- 2 files changed, 5 insertions(+), 43 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index de893c9616a1..918098c9f72a 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -38,7 +38,7 @@ * memory entries in the /memory node. This function may be called * any time after initial_boot_param is set. */ -void of_fdt_limit_memory(int limit) +void __init of_fdt_limit_memory(int limit) { int memory; int len; @@ -110,25 +110,6 @@ static int of_fdt_is_compatible(const void *blob, return 0; } -/** - * of_fdt_is_big_endian - Return true if given node needs BE MMIO accesses - * @blob: A device tree blob - * @node: node to test - * - * Returns true if the node has a "big-endian" property, or if the kernel - * was compiled for BE *and* the node has a "native-endian" property. - * Returns false otherwise. - */ -bool of_fdt_is_big_endian(const void *blob, unsigned long node) -{ - if (fdt_getprop(blob, node, "big-endian", NULL)) - return true; - if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) && - fdt_getprop(blob, node, "native-endian", NULL)) - return true; - return false; -} - static bool of_fdt_device_is_available(const void *blob, unsigned long node) { const char *status = fdt_getprop(blob, node, "status", NULL); @@ -145,8 +126,8 @@ static bool of_fdt_device_is_available(const void *blob, unsigned long node) /** * of_fdt_match - Return true if node matches a list of compatible values */ -int of_fdt_match(const void *blob, unsigned long node, - const char *const *compat) +static int __init of_fdt_match(const void *blob, unsigned long node, + const char *const *compat) { unsigned int tmp, score = 0; @@ -758,7 +739,7 @@ int __init of_scan_flat_dt_subnodes(unsigned long parent, * @return offset of the subnode, or -FDT_ERR_NOTFOUND if there is none */ -int of_get_flat_dt_subnode_by_name(unsigned long node, const char *uname) +int __init of_get_flat_dt_subnode_by_name(unsigned long node, const char *uname) { return fdt_subnode_offset(initial_boot_params, node, uname); } @@ -771,14 +752,6 @@ unsigned long __init of_get_flat_dt_root(void) return 0; } -/** - * of_get_flat_dt_size - Return the total size of the FDT - */ -int __init of_get_flat_dt_size(void) -{ - return fdt_totalsize(initial_boot_params); -} - /** * of_get_flat_dt_prop - Given a node in the flat blob, return the property ptr * @@ -804,7 +777,7 @@ int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) /** * of_flat_dt_match - Return true if node matches a list of compatible values */ -int __init of_flat_dt_match(unsigned long node, const char *const *compat) +static int __init of_flat_dt_match(unsigned long node, const char *const *compat) { return of_fdt_match(initial_boot_params, node, compat); } diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index a713e5d156d8..acf820e88952 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -23,15 +23,6 @@ struct device_node; /* For scanning an arbitrary device-tree at any time */ -extern char *of_fdt_get_string(const void *blob, u32 offset); -extern void *of_fdt_get_property(const void *blob, - unsigned long node, - const char *name, - int *size); -extern bool of_fdt_is_big_endian(const void *blob, - unsigned long node); -extern int of_fdt_match(const void *blob, unsigned long node, - const char *const *compat); extern void *of_fdt_unflatten_tree(const unsigned long *blob, struct device_node *dad, struct device_node **mynodes); @@ -64,9 +55,7 @@ extern int of_get_flat_dt_subnode_by_name(unsigned long node, extern const void *of_get_flat_dt_prop(unsigned long node, const char *name, int *size); extern int of_flat_dt_is_compatible(unsigned long node, const char *name); -extern int of_flat_dt_match(unsigned long node, const char *const *matches); extern unsigned long of_get_flat_dt_root(void); -extern int of_get_flat_dt_size(void); extern uint32_t of_get_flat_dt_phandle(unsigned long node); extern int early_init_dt_scan_chosen(unsigned long node, const char *uname, -- cgit v1.2.3-59-g8ed1b From 7c71650f9a3640464dd907bd7a6510cc7ea02ba6 Mon Sep 17 00:00:00 2001 From: Stephen Boyd Date: Tue, 14 May 2019 13:40:53 -0700 Subject: of/fdt: Mark initial_boot_params as __ro_after_init The FDT pointer, i.e. initial_boot_params, shouldn't be changed after init. It's only set by boot code and then the only user of the FDT is the raw sysfs reading API. Mark this pointer with __ro_after_init so that the pointer can't be changed after init. Cc: Hsin-Yi Wang Signed-off-by: Stephen Boyd Signed-off-by: Rob Herring --- drivers/of/fdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 918098c9f72a..3d36b5afd9bd 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -516,7 +516,7 @@ EXPORT_SYMBOL_GPL(of_fdt_unflatten_tree); int __initdata dt_root_addr_cells; int __initdata dt_root_size_cells; -void *initial_boot_params; +void *initial_boot_params __ro_after_init; #ifdef CONFIG_OF_EARLY_FLATTREE -- cgit v1.2.3-59-g8ed1b From 5d9c4e9591dc0cce80dac170cbdc9015e34b074a Mon Sep 17 00:00:00 2001 From: Kefeng Wang Date: Sat, 15 Jun 2019 11:03:43 +0800 Subject: of/fdt: Fix ‘of_fdt_match’ defined but not used compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When CONFIG_OF_EARLY_FLATTREE is disabled, there is a compiler warning, drivers/of/fdt.c:129:19: warning: ‘of_fdt_match’ defined but not used [-Wunused-function] static int __init of_fdt_match(const void *blob, unsigned long node, Since the only caller of of_fdt_match() is of_flat_dt_match(), let's move the body of of_fdt_match() into of_flat_dt_match() and eliminate of_fdt_match(). Meanwhile, move of_fdt_is_compatible() under CONFIG_OF_EARLY_FLATTREE, as all callers are over there. Fixes: 9b4d2b635bd0 ("of/fdt: Remove dead code and mark functions with __init") Cc: Frank Rowand Signed-off-by: Kefeng Wang Reviewed-by: Stephen Boyd Signed-off-by: Rob Herring --- drivers/of/fdt.c | 99 ++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 54 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 3d36b5afd9bd..cd17dc62a719 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -78,38 +78,6 @@ void __init of_fdt_limit_memory(int limit) } } -/** - * of_fdt_is_compatible - Return true if given node from the given blob has - * compat in its compatible list - * @blob: A device tree blob - * @node: node to test - * @compat: compatible string to compare with compatible list. - * - * On match, returns a non-zero value with smaller values returned for more - * specific compatible values. - */ -static int of_fdt_is_compatible(const void *blob, - unsigned long node, const char *compat) -{ - const char *cp; - int cplen; - unsigned long l, score = 0; - - cp = fdt_getprop(blob, node, "compatible", &cplen); - if (cp == NULL) - return 0; - while (cplen > 0) { - score++; - if (of_compat_cmp(cp, compat, strlen(compat)) == 0) - return score; - l = strlen(cp) + 1; - cp += l; - cplen -= l; - } - - return 0; -} - static bool of_fdt_device_is_available(const void *blob, unsigned long node) { const char *status = fdt_getprop(blob, node, "status", NULL); @@ -123,27 +91,6 @@ static bool of_fdt_device_is_available(const void *blob, unsigned long node) return false; } -/** - * of_fdt_match - Return true if node matches a list of compatible values - */ -static int __init of_fdt_match(const void *blob, unsigned long node, - const char *const *compat) -{ - unsigned int tmp, score = 0; - - if (!compat) - return 0; - - while (*compat) { - tmp = of_fdt_is_compatible(blob, node, *compat); - if (tmp && (score == 0 || (tmp < score))) - score = tmp; - compat++; - } - - return score; -} - static void *unflatten_dt_alloc(void **mem, unsigned long size, unsigned long align) { @@ -764,6 +711,38 @@ const void *__init of_get_flat_dt_prop(unsigned long node, const char *name, return fdt_getprop(initial_boot_params, node, name, size); } +/** + * of_fdt_is_compatible - Return true if given node from the given blob has + * compat in its compatible list + * @blob: A device tree blob + * @node: node to test + * @compat: compatible string to compare with compatible list. + * + * On match, returns a non-zero value with smaller values returned for more + * specific compatible values. + */ +static int of_fdt_is_compatible(const void *blob, + unsigned long node, const char *compat) +{ + const char *cp; + int cplen; + unsigned long l, score = 0; + + cp = fdt_getprop(blob, node, "compatible", &cplen); + if (cp == NULL) + return 0; + while (cplen > 0) { + score++; + if (of_compat_cmp(cp, compat, strlen(compat)) == 0) + return score; + l = strlen(cp) + 1; + cp += l; + cplen -= l; + } + + return 0; +} + /** * of_flat_dt_is_compatible - Return true if given node has compat in compatible list * @node: node to test @@ -779,7 +758,19 @@ int __init of_flat_dt_is_compatible(unsigned long node, const char *compat) */ static int __init of_flat_dt_match(unsigned long node, const char *const *compat) { - return of_fdt_match(initial_boot_params, node, compat); + unsigned int tmp, score = 0; + + if (!compat) + return 0; + + while (*compat) { + tmp = of_fdt_is_compatible(initial_boot_params, node, *compat); + if (tmp && (score == 0 || (tmp < score))) + score = tmp; + compat++; + } + + return score; } /** -- cgit v1.2.3-59-g8ed1b From d88590dc262f90d260e97b85ca50c992931457d4 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Mon, 24 Jun 2019 14:46:20 +0200 Subject: of/platform: Drop superfluous cast in of_device_make_bus_id() There is no need to cast "u64" to "unsigned long long" before printing it, as both types have been made identical on all architectures many years ago. Signed-off-by: Geert Uytterhoeven Signed-off-by: Rob Herring --- drivers/of/platform.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 04ad312fd85b..efbff44581b3 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -92,8 +92,7 @@ static void of_device_make_bus_id(struct device *dev) reg = of_get_property(node, "reg", NULL); if (reg && (addr = of_translate_address(node, reg)) != OF_BAD_ADDR) { dev_set_name(dev, dev_name(dev) ? "%llx.%pOFn:%s" : "%llx.%pOFn", - (unsigned long long)addr, node, - dev_name(dev)); + addr, node, dev_name(dev)); return; } -- cgit v1.2.3-59-g8ed1b From 5c68b8231e9c361fc3dc96997ea377b31c4dbd3e Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 30 May 2019 19:39:27 +0900 Subject: of/fdt: pass early_init_dt_reserve_memory_arch() with bool type nomap The third argument 'nomap' of early_init_dt_reserve_memory_arch() is bool. It is preferred to pass it with a bool type parameter. Signed-off-by: Masahiro Yamada Reviewed-by: Frank Rowand Signed-off-by: Rob Herring --- drivers/of/fdt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index cd17dc62a719..9cdf14b9aaab 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -479,7 +479,8 @@ static int __init __reserved_mem_reserve_reg(unsigned long node, phys_addr_t base, size; int len; const __be32 *prop; - int nomap, first = 1; + int first = 1; + bool nomap; prop = of_get_flat_dt_prop(node, "reg", &len); if (!prop) @@ -594,7 +595,7 @@ void __init early_init_fdt_scan_reserved_mem(void) fdt_get_mem_rsv(initial_boot_params, n, &base, &size); if (!size) break; - early_init_dt_reserve_memory_arch(base, size, 0); + early_init_dt_reserve_memory_arch(base, size, false); } of_scan_flat_dt(__fdt_scan_reserved_mem, NULL); @@ -612,7 +613,7 @@ void __init early_init_fdt_reserve_self(void) /* Reserve the dtb region */ early_init_dt_reserve_memory_arch(__pa(initial_boot_params), fdt_totalsize(initial_boot_params), - 0); + false); } /** -- cgit v1.2.3-59-g8ed1b From 272d28bdae1189791df4d118432bfae3feb53fe3 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Mon, 10 Jun 2019 11:51:56 +0200 Subject: of: unittest: simplify getting the adapter of a client We have a dedicated pointer for that, so use it. Much easier to read and less computation involved. Reported-by: Peter Rosin Signed-off-by: Wolfram Sang Signed-off-by: Rob Herring --- drivers/of/unittest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 3832a5de4602..e6b175370f2e 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1946,7 +1946,7 @@ static int unittest_i2c_mux_probe(struct i2c_client *client, { int i, nchans; struct device *dev = &client->dev; - struct i2c_adapter *adap = to_i2c_adapter(dev->parent); + struct i2c_adapter *adap = client->adapter; struct device_node *np = client->dev.of_node, *child; struct i2c_mux_core *muxc; u32 reg, max_reg; -- cgit v1.2.3-59-g8ed1b