of: Warn when of_property_read_bool() is used on non-boolean properties
authorRob Herring (Arm) <robh@kernel.org>
Thu, 9 Jan 2025 19:42:06 +0000 (13:42 -0600)
committerRob Herring (Arm) <robh@kernel.org>
Mon, 13 Jan 2025 23:47:29 +0000 (17:47 -0600)
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 <krzk@kernel.org>
Link: https://lore.kernel.org/r/20250109-dt-type-warnings-v1-2-0150e32e716c@kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
drivers/of/property.c
include/linux/of.h

index 2109515a3bc2a821f31a9aecbf71a5956e6d8b97..8577d659c1623df0977040bf0111f466d84a939b 100644 (file)
 
 #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
index 1cb4eb7fc2eded2246c697c3bcaf1b85d43108ab..0cdd58ff0a4190724309ba1eddbac51b188b6136 100644 (file)
@@ -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.