summaryrefslogtreecommitdiff
path: root/drivers/button/button-gpio.c
diff options
context:
space:
mode:
authorCaleb Connolly <caleb.connolly@linaro.org>2024-11-13 05:59:24 +0100
committerTom Rini <trini@konsulko.com>2024-12-04 14:06:23 -0600
commit15299fa5dd8985759b705c7b06d7430924ba2407 (patch)
tree67f07c7d2089715097addfcddbd5598b716c033d /drivers/button/button-gpio.c
parent893ae07cc9b0050d635aad704c1bdae41477734a (diff)
button: gpio: handle broken controller
Avoid crashing U-Boot when the GPIO controller for a button is disabled or failed to probe. We also need to check the priv data for each button since even if a button fails to probe it will still be polled by the core code. Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
Diffstat (limited to 'drivers/button/button-gpio.c')
-rw-r--r--drivers/button/button-gpio.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
index 43b82d98aeb..31b85c8150e 100644
--- a/drivers/button/button-gpio.c
+++ b/drivers/button/button-gpio.c
@@ -20,6 +20,9 @@ static enum button_state_t button_gpio_get_state(struct udevice *dev)
struct button_gpio_priv *priv = dev_get_priv(dev);
int ret;
+ if (!priv)
+ return -ENODATA;
+
if (!dm_gpio_is_valid(&priv->gpio))
return -EREMOTEIO;
ret = dm_gpio_get_value(&priv->gpio);
@@ -32,6 +35,8 @@ static enum button_state_t button_gpio_get_state(struct udevice *dev)
static int button_gpio_get_code(struct udevice *dev)
{
struct button_gpio_priv *priv = dev_get_priv(dev);
+ if (!priv)
+ return -ENODATA;
int code = priv->linux_code;
if (!code)
@@ -51,7 +56,7 @@ static int button_gpio_probe(struct udevice *dev)
return 0;
ret = gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_IN);
- if (ret)
+ if (ret || !dm_gpio_is_valid(&priv->gpio))
return ret;
ret = dev_read_u32(dev, "linux,code", &priv->linux_code);
@@ -98,6 +103,8 @@ static int button_gpio_bind(struct udevice *parent)
return ret;
uc_plat = dev_get_uclass_plat(dev);
uc_plat->label = label;
+ debug("Button '%s' bound to driver '%s'\n", label,
+ dev->driver->name);
}
return 0;