[PATCH] checks: Detect cascoda,ca8210 extclock-gpio false-positive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



The binding for the cascoda,ca8210 IEEE 802.15.4 (6LoWPAN) device
includes an extclock-gpio property which does not contain a gpio-list,
but is instead an integer representing a pin of the device itself. This
falls foul of the gpios_property check, for example:

    DTC     arch/mips/boot/dts/img/pistachio_marduk.dtb
  arch/mips/boot/dts/img/pistachio_marduk.dtb: Warning (gpios_property):
    /spi@18100f00/sixlowpan@4: Missing property '#gpio-cells' in node
    /clk@18144000 or bad phandle (referred from extclock-gpio[0])

Extend the checking for false-positives in prop_is_gpio() to detect this
case in addition to the existing nr-gpio case. The false-positive cases
are described by an array including a compatible string & property name.
A NULL compatible string indicates that the property may be present in
any node, otherwise the property is only allowed in a node compatible
with the given string. This allows us to whitelist the extclock-gpio
property for the cascoda,ca8210 device without allowing it anywhere
else.

Since checks for false-positives now have a little higher cost, they are
moved to after the detection of the gpio(s) substring, which the vast
majority of property names will fail avoiding needless checks against
the false_positives array.

Signed-off-by: Paul Burton <paul.burton@xxxxxxxx>
Cc: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>
Cc: Jon Loeliger <jdl@xxxxxxx>
Cc: Rob Herring <robh@xxxxxxxxxx>
Cc: Andreas Färber <afaerber@xxxxxxx>
Cc: devicetree-compiler@xxxxxxxxxxxxxxx
Cc: linux-mips@xxxxxxxxxxxxxx
---
 checks.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/checks.c b/checks.c
index a2cc103..c76e312 100644
--- a/checks.c
+++ b/checks.c
@@ -1254,16 +1254,17 @@ WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells");
 WARNING_PROPERTY_PHANDLE_CELLS(sound_dai, "sound-dai", "#sound-dai-cells");
 WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells");
 
-static bool prop_is_gpio(struct property *prop)
+static bool prop_is_gpio(struct node *node, struct property *prop)
 {
+	const struct {
+		char *compat;
+		char *prop;
+	} false_positives[] = {
+		{ NULL, "nr-gpio" },
+		{ "cascoda,ca8210", "extclock-gpio" },
+	};
 	char *str;
-
-	/*
-	 * *-gpios and *-gpio can appear in property names,
-	 * so skip over any false matches (only one known ATM)
-	 */
-	if (strstr(prop->name, "nr-gpio"))
-		return false;
+	int i;
 
 	str = strrchr(prop->name, '-');
 	if (str)
@@ -1273,6 +1274,21 @@ static bool prop_is_gpio(struct property *prop)
 	if (!(streq(str, "gpios") || streq(str, "gpio")))
 		return false;
 
+	/*
+	 * *-gpios and *-gpio can appear in property names,
+	 * so skip over any false matches.
+	 */
+	for (i = 0; i < ARRAY_SIZE(false_positives); i++) {
+		if (strstr(prop->name, false_positives[i].prop))
+			return false;
+
+		if (!false_positives[i].compat)
+			return false;
+
+		if (node_is_compatible(node, false_positives[i].compat))
+			return false;
+	}
+
 	return true;
 }
 
@@ -1289,7 +1305,7 @@ static void check_gpios_property(struct check *c,
 	for_each_property(node, prop) {
 		struct provider provider;
 
-		if (!prop_is_gpio(prop))
+		if (!prop_is_gpio(node, prop))
 			continue;
 
 		provider.prop_name = prop->name;
@@ -1310,7 +1326,7 @@ static void check_deprecated_gpio_property(struct check *c,
 	for_each_property(node, prop) {
 		char *str;
 
-		if (!prop_is_gpio(prop))
+		if (!prop_is_gpio(node, prop))
 			continue;
 
 		str = strstr(prop->name, "gpio");
-- 
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux