Skip to content

Commit c141ecc

Browse files
committed
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent bb39141 commit c141ecc

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

drivers/of/property.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@
3131

3232
#include "of_private.h"
3333

34+
/**
35+
* of_property_read_bool - Find a property
36+
* @np: device node from which the property value is to be read.
37+
* @propname: name of the property to be searched.
38+
*
39+
* Search for a boolean property in a device node. Usage on non-boolean
40+
* property types is deprecated.
41+
*
42+
* Return: true if the property exists false otherwise.
43+
*/
44+
bool of_property_read_bool(const struct device_node *np, const char *propname)
45+
{
46+
struct property *prop = of_find_property(np, propname, NULL);
47+
48+
/*
49+
* Boolean properties should not have a value. Testing for property
50+
* presence should either use of_property_present() or just read the
51+
* property value and check the returned error code.
52+
*/
53+
if (prop && prop->length)
54+
pr_warn("%pOF: Read of boolean property '%s' with a value.\n", np, propname);
55+
56+
return prop ? true : false;
57+
}
58+
EXPORT_SYMBOL(of_property_read_bool);
59+
3460
/**
3561
* of_graph_is_present() - check graph's presence
3662
* @node: pointer to device_node containing graph port

include/linux/of.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ extern struct device_node *of_find_node_with_property(
311311
extern struct property *of_find_property(const struct device_node *np,
312312
const char *name,
313313
int *lenp);
314+
extern bool of_property_read_bool(const struct device_node *np, const char *propname);
314315
extern int of_property_count_elems_of_size(const struct device_node *np,
315316
const char *propname, int elem_size);
316317
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(
615616
return NULL;
616617
}
617618

619+
static inline bool of_property_read_bool(const struct device_node *np,
620+
const char *propname)
621+
{
622+
return false;
623+
}
624+
618625
static inline int of_property_count_elems_of_size(const struct device_node *np,
619626
const char *propname, int elem_size)
620627
{
@@ -1242,24 +1249,6 @@ static inline int of_property_read_string_index(const struct device_node *np,
12421249
return rc < 0 ? rc : 0;
12431250
}
12441251

1245-
/**
1246-
* of_property_read_bool - Find a property
1247-
* @np: device node from which the property value is to be read.
1248-
* @propname: name of the property to be searched.
1249-
*
1250-
* Search for a boolean property in a device node. Usage on non-boolean
1251-
* property types is deprecated.
1252-
*
1253-
* Return: true if the property exists false otherwise.
1254-
*/
1255-
static inline bool of_property_read_bool(const struct device_node *np,
1256-
const char *propname)
1257-
{
1258-
const struct property *prop = of_find_property(np, propname, NULL);
1259-
1260-
return prop ? true : false;
1261-
}
1262-
12631252
/**
12641253
* of_property_present - Test if a property is present in a node
12651254
* @np: device node to search for the property.

0 commit comments

Comments
 (0)