From bb3914101f704a8282f65238d6b021d216efc608 Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Thu, 9 Jan 2025 13:42:05 -0600 Subject: device property: Split property reading bool and presence test ops The fwnode/device property API currently implement (fwnode|device)_property_read_bool() with (fwnode|device)_property_present(). That does not allow having different behavior depending on the backend. Specifically, the usage of (fwnode|device)_property_read_bool() on non-boolean properties is deprecated on DT. In order to add a warning on this deprecated use, these 2 APIs need separate ops for the backend. Acked-by: Greg Kroah-Hartman Reviewed-by: Krzysztof Kozlowski Acked-by: Rafael J. Wysocki Link: https://lore.kernel.org/r/20250109-dt-type-warnings-v1-1-0150e32e716c@kernel.org Signed-off-by: Rob Herring (Arm) --- include/linux/of.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/linux/of.h') diff --git a/include/linux/of.h b/include/linux/of.h index f921786cb8ac..1cb4eb7fc2ed 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -1271,7 +1271,9 @@ static inline bool of_property_read_bool(const struct device_node *np, */ static inline bool of_property_present(const struct device_node *np, const char *propname) { - return of_property_read_bool(np, propname); + struct property *prop = of_find_property(np, propname, NULL); + + return prop ? true : false; } /** -- cgit v1.2.3 From c141ecc3cecd764799e17c8251026336cab86800 Mon Sep 17 00:00:00 2001 From: "Rob Herring (Arm)" Date: Thu, 9 Jan 2025 13:42:06 -0600 Subject: of: Warn when of_property_read_bool() is used on non-boolean properties The use of of_property_read_bool() for non-boolean properties is deprecated. The primary use of it was to test property presence, but that has been replaced in favor of of_property_present(). With those uses now fixed, add a warning to discourage new ones. Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20250109-dt-type-warnings-v1-2-0150e32e716c@kernel.org Signed-off-by: Rob Herring (Arm) --- drivers/of/property.c | 26 ++++++++++++++++++++++++++ include/linux/of.h | 25 +++++++------------------ 2 files changed, 33 insertions(+), 18 deletions(-) (limited to 'include/linux/of.h') diff --git a/drivers/of/property.c b/drivers/of/property.c index 2109515a3bc2..8577d659c162 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -31,6 +31,32 @@ #include "of_private.h" +/** + * of_property_read_bool - Find a property + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * + * Search for a boolean property in a device node. Usage on non-boolean + * property types is deprecated. + * + * Return: true if the property exists false otherwise. + */ +bool of_property_read_bool(const struct device_node *np, const char *propname) +{ + struct property *prop = of_find_property(np, propname, NULL); + + /* + * Boolean properties should not have a value. Testing for property + * presence should either use of_property_present() or just read the + * property value and check the returned error code. + */ + if (prop && prop->length) + pr_warn("%pOF: Read of boolean property '%s' with a value.\n", np, propname); + + return prop ? true : false; +} +EXPORT_SYMBOL(of_property_read_bool); + /** * of_graph_is_present() - check graph's presence * @node: pointer to device_node containing graph port diff --git a/include/linux/of.h b/include/linux/of.h index 1cb4eb7fc2ed..0cdd58ff0a41 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -311,6 +311,7 @@ extern struct device_node *of_find_node_with_property( extern struct property *of_find_property(const struct device_node *np, const char *name, int *lenp); +extern bool of_property_read_bool(const struct device_node *np, const char *propname); extern int of_property_count_elems_of_size(const struct device_node *np, const char *propname, int elem_size); extern int of_property_read_u32_index(const struct device_node *np, @@ -615,6 +616,12 @@ static inline struct device_node *of_find_compatible_node( return NULL; } +static inline bool of_property_read_bool(const struct device_node *np, + const char *propname) +{ + return false; +} + static inline int of_property_count_elems_of_size(const struct device_node *np, const char *propname, int elem_size) { @@ -1242,24 +1249,6 @@ static inline int of_property_read_string_index(const struct device_node *np, return rc < 0 ? rc : 0; } -/** - * of_property_read_bool - Find a property - * @np: device node from which the property value is to be read. - * @propname: name of the property to be searched. - * - * Search for a boolean property in a device node. Usage on non-boolean - * property types is deprecated. - * - * Return: true if the property exists false otherwise. - */ -static inline bool of_property_read_bool(const struct device_node *np, - const char *propname) -{ - const struct property *prop = of_find_property(np, propname, NULL); - - return prop ? true : false; -} - /** * of_property_present - Test if a property is present in a node * @np: device node to search for the property. -- cgit v1.2.3 From 72d1c18262dd5a18d835a94391c31cf04252c748 Mon Sep 17 00:00:00 2001 From: Zijun Hu Date: Tue, 14 Jan 2025 23:23:03 +0800 Subject: of: Do not expose of_alias_scan() and correct its comments of_alias_scan() has no external callers and returns void. Do not expose it and delete return value descriptions in its comments. Signed-off-by: Zijun Hu Link: https://lore.kernel.org/r/20250114-of_core_fix-v5-1-b8bafd00a86f@quicinc.com Signed-off-by: Rob Herring (Arm) --- drivers/of/base.c | 3 +-- drivers/of/of_private.h | 2 ++ drivers/of/pdt.c | 2 ++ include/linux/of.h | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) (limited to 'include/linux/of.h') diff --git a/drivers/of/base.c b/drivers/of/base.c index 969b99838655..f4ab4086b80f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1812,8 +1812,7 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np, * for storing the resulting tree * * The function scans all the properties of the 'aliases' node and populates - * the global lookup table with the properties. It returns the - * number of alias properties found, or an error code in case of failure. + * the global lookup table with the properties. */ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)) { diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 58819222279a..f3e1193c8ded 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -119,6 +119,8 @@ extern void *__unflatten_device_tree(const void *blob, void *(*dt_alloc)(u64 size, u64 align), bool detached); +void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); + /** * General utilities for working with live trees. * diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c index 7eda43c66c91..cb0cb374b21f 100644 --- a/drivers/of/pdt.c +++ b/drivers/of/pdt.c @@ -19,6 +19,8 @@ #include #include +#include "of_private.h" + static struct of_pdt_ops *of_pdt_prom_ops __initdata; #if defined(CONFIG_SPARC) diff --git a/include/linux/of.h b/include/linux/of.h index 0cdd58ff0a41..eaf0e2a2b75c 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -398,7 +398,6 @@ extern int of_phandle_iterator_args(struct of_phandle_iterator *it, uint32_t *args, int size); -extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); extern int of_alias_get_id(const struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); -- cgit v1.2.3