mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] of: use of_property_read_bool where appropriate
@ 2017-04-12 10:13 Sascha Hauer
  2017-04-12 10:13 ` [PATCH 2/2] of: of_net: use a loop Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2017-04-12 10:13 UTC (permalink / raw)
  To: Barebox List

Use of_property_read_bool where boolean properties are read.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/eeprom/at25.c | 2 +-
 drivers/net/dm9k.c    | 2 +-
 drivers/spi/spi.c     | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/eeprom/at25.c b/drivers/eeprom/at25.c
index 1caaebd371..9f16f964a8 100644
--- a/drivers/eeprom/at25.c
+++ b/drivers/eeprom/at25.c
@@ -290,7 +290,7 @@ static int at25_np_to_chip(struct device_d *dev,
 				val);
 			return -ENODEV;
 		}
-		if (of_find_property(np, "read-only", NULL))
+		if (of_property_read_bool(np, "read-only"))
 			chip->flags |= EE_READONLY;
 	}
 	return 0;
diff --git a/drivers/net/dm9k.c b/drivers/net/dm9k.c
index 25f08602f6..c99d188ded 100644
--- a/drivers/net/dm9k.c
+++ b/drivers/net/dm9k.c
@@ -737,7 +737,7 @@ static int dm9000_parse_dt(struct device_d *dev, struct dm9k *priv)
 	if (!IS_ENABLED(CONFIG_OFDEVICE) || !np)
 		return -ENODEV;
 
-	if (of_find_property(np, "davicom,no-eeprom", NULL)) {
+	if (of_property_read_bool(np, "davicom,no-eeprom")) {
 		priv->srom = 0;
 	} else {
 		priv->srom = 1;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 99412b07e2..5650098a0a 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -118,13 +118,13 @@ static void spi_of_register_slaves(struct spi_master *master)
 		chip.name = xstrdup(n->name);
 		chip.bus_num = master->bus_num;
 		/* Mode (clock phase/polarity/etc.) */
-		if (of_find_property(n, "spi-cpha", NULL))
+		if (of_property_read_bool(n, "spi-cpha"))
 			chip.mode |= SPI_CPHA;
-		if (of_find_property(n, "spi-cpol", NULL))
+		if (of_property_read_bool(n, "spi-cpol"))
 			chip.mode |= SPI_CPOL;
-		if (of_find_property(n, "spi-cs-high", NULL))
+		if (of_property_read_bool(n, "spi-cs-high"))
 			chip.mode |= SPI_CS_HIGH;
-		if (of_find_property(n, "spi-3wire", NULL))
+		if (of_property_read_bool(n, "spi-3wire"))
 			chip.mode |= SPI_3WIRE;
 		of_property_read_u32(n, "spi-max-frequency",
 				&chip.max_speed_hz);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] of: of_net: use a loop
  2017-04-12 10:13 [PATCH 1/2] of: use of_property_read_bool where appropriate Sascha Hauer
@ 2017-04-12 10:13 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2017-04-12 10:13 UTC (permalink / raw)
  To: Barebox List

iterate over the different property names rather than having
the same code three times.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/of_net.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index 086573fc1a..9b54e44674 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -77,19 +77,15 @@ EXPORT_SYMBOL_GPL(of_get_phy_mode);
 */
 const void *of_get_mac_address(struct device_node *np)
 {
-	struct property *pp;
+	const void *p;
+	int len, i;
+	const char *str[] = { "mac-address", "local-mac-address", "address" };
 
-	pp = of_find_property(np, "mac-address", NULL);
-	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-		return pp->value;
-
-	pp = of_find_property(np, "local-mac-address", NULL);
-	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-		return pp->value;
-
-	pp = of_find_property(np, "address", NULL);
-	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-		return pp->value;
+	for (i = 0; i < ARRAY_SIZE(str); i++) {
+		p = of_get_property(np, str[i], &len);
+		if (p && (len == 6) && is_valid_ether_addr(p))
+			return p;
+	}
 
 	return NULL;
 }
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-12 10:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12 10:13 [PATCH 1/2] of: use of_property_read_bool where appropriate Sascha Hauer
2017-04-12 10:13 ` [PATCH 2/2] of: of_net: use a loop Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox