Skip to contentSkip to conversation

drm/bridge: anx7625: Check GPIO description to avoid crash

PATCH Applied Xin Ji 2 participants 3 messages Nov 19, 2021 – Jan 4, 2022

Subsystems (3)

v2 of 3 Applied Latest is v3 →

lore
Share & tools
lore

Xin Ji

author
#0 lore raw

PATCH v2 1/1 drm/bridge: anx7625: Check GPIO description to avoid crash

As GPIO probe function "devm_gpiod_get_optional()" may return error code, driver should identify GPIO desc as NULL to avoid crash.

---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/bridge/analogix/anx7625.c +9 -0
index 001fb39d9919..652ae814246d 100644
@@ -1098,9 +1098,18 @@ static void anx7625_init_gpio(struct anx7625_data *platform)
 	/* Gpio for chip power enable */
 	platform->pdata.gpio_p_on =
 		devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
+	if (IS_ERR_OR_NULL(platform->pdata.gpio_p_on)) {
+		DRM_DEV_DEBUG_DRIVER(dev, "no enable gpio found\n");
+		platform->pdata.gpio_p_on = NULL;
+	}
+
 	/* Gpio for chip reset */
 	platform->pdata.gpio_reset =
 		devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	if (IS_ERR_OR_NULL(platform->pdata.gpio_reset)) {
+		DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
+		platform->pdata.gpio_reset = NULL;
+	}
 
 	if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) {
 		platform->pdata.low_power_mode = 1;
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 34 lines · Xin Ji

As GPIO probe function "devm_gpiod_get_optional()" may return error code, driver should identify GPIO desc as NULL to avoid crash.

---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/bridge/analogix/anx7625.c +9 -1
index 001fb39d9919..652ae814246d 100644
@@ -1098,9 +1098,18 @@ static void anx7625_init_gpio(struct anx7625_data *platform)
        /* Gpio for chip power enable */
        platform->pdata.gpio_p_on =
                devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
+       if (IS_ERR_OR_NULL(platform->pdata.gpio_p_on)) {
+               DRM_DEV_DEBUG_DRIVER(dev, "no enable gpio found\n");
+               platform->pdata.gpio_p_on = NULL;
+       }
+
        /* Gpio for chip reset */
        platform->pdata.gpio_reset =
                devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+       if (IS_ERR_OR_NULL(platform->pdata.gpio_reset)) {
+               DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
+               platform->pdata.gpio_reset = NULL;
+       }
 
        if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) {
                platform->pdata.low_power_mode = 1;
--
Quoted 2 lines

2.25.1