diff options
author | John Watts <contact@jookia.org> | 2023-01-25 07:05:55 +1100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-01-26 09:14:21 +0100 |
commit | 47a4ddb1a292c09daf1d11983f53f3fb95a63bbc (patch) | |
tree | 0f1d113564977411eb49d0c26fec128eeb2b56ae /include/of_gpio.h | |
parent | f6f5cbfef751f728bfa985f846fab468d222a019 (diff) | |
download | barebox-47a4ddb1a292c09daf1d11983f53f3fb95a63bbc.tar.gz |
spi: Fix probing SPI drivers with no cs-gpios
of_gpio_named_count returns a negative value on error but this
is discarded and cast to a u16, making error handling impossible.
With debug logging enabled this effectively halts booting so the board can
print an error over serial 65534 times.
Introduce of_gpio_count_csgpios which returns 0 in the case of an error
rather than a negative value.
Signed-off-by: John Watts <contact@jookia.org>
Link: https://lore.barebox.org/20230124200554.1701687-1-contact@jookia.org
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/of_gpio.h')
-rw-r--r-- | include/of_gpio.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/of_gpio.h b/include/of_gpio.h index 30ff204baf..794a9926cd 100644 --- a/include/of_gpio.h +++ b/include/of_gpio.h @@ -69,6 +69,23 @@ static inline int of_gpio_count(struct device_node *np) return of_gpio_named_count(np, "gpios"); } +/** + * of_gpio_count() - Count cs-gpios for a device + * @np: device node to count cs-gpios for + * + * Same as of_gpio_named_count, but hard coded to use the 'cs-gpios' property + * Returns 0 on error + */ +static inline int of_gpio_count_csgpios(struct device_node *np) +{ + int count = of_gpio_named_count(np, "cs-gpios"); + + if (count > 0) + return count; + else + return 0; +} + static inline int of_get_gpio_flags(struct device_node *np, int index, enum of_gpio_flags *flags) { |