Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ecd31a0 authored by Stepan Moskovchenko's avatar Stepan Moskovchenko
Browse files

of: Generate warnings for malformed boolean properties



A properly-formed boolean property does not contain any
value-specific device tree cells. The mere presence of the
name of the property (without a corresponding value)
indicates that a boolean property has been set to 'true'.
However, a common mistake may be to assign a numeric value
to a boolean property, meaning that of_property_read_bool()
will always return 'true' when querying such a property,
even if the property's numeric value has been set to 0.
Therefore, we add a warning that is printed whenever any
user calls of_property_read_bool() on any property that
contains value cells.

Change-Id: I2b626f6f0647ff8c8e8ae729ccea9ede5580e604
Signed-off-by: default avatarStepan Moskovchenko <stepanm@codeaurora.org>
parent c57e2816
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -544,6 +544,16 @@ static inline bool of_property_read_bool(const struct device_node *np,
{
	struct property *prop = of_find_property(np, propname, NULL);

	/*
	 * Boolean properties have no value cells. The "value" of a boolean
	 * property is determined by the presence or absence of the property
	 * itself, and value cells are disregarded entirely. Declaring a
	 * boolean property with a nonzero number of value cells is a common
	 * configuration error, since even a boolean property having a value of
	 * 0 will be treated as "true" by the DT framework.
	 */
	WARN_ON(prop && prop->length);

	return prop ? true : false;
}