As GPIO probe function "devm_gpiod_get_optional()" may return error code, driver should identify GPIO desc as NULL to avoid crash.
Signed-off-by: Xin Ji xji@analogixsemi.com --- drivers/gpu/drm/bridge/analogix/anx7625.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index 001fb39d9919..36e0ae5a1c7b 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -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(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(platform->pdata.gpio_reset)) { + DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n"); + platform->pdata.gpio_p_on = NULL; + }
if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) { platform->pdata.low_power_mode = 1;
On Thu, Nov 18, 2021 at 11:11 AM Xin Ji xji@analogixsemi.com wrote:
@@ -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(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(platform->pdata.gpio_reset)) {
DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
platform->pdata.gpio_p_on = NULL;
} if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) { platform->pdata.low_power_mode = 1;
devm_gpiod_get_optional() is possible to return NULL (see https://elixir.bootlin.com/linux/v5.15.2/source/drivers/gpio/gpiolib-devres....). Thus, we should use IS_ERR_OR_NULL for checking the return value.
The cases here would work fine except it will skip to print some informative messages.
Acked-by: Tzung-Bi Shih tzungbi@google.com
On Thu, Nov 18, 2021 at 12:52:14PM +0800, Tzung-Bi Shih wrote:
On Thu, Nov 18, 2021 at 11:11 AM Xin Ji xji@analogixsemi.com wrote:
@@ -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(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(platform->pdata.gpio_reset)) {
DRM_DEV_DEBUG_DRIVER(dev, "no reset gpio found\n");
platform->pdata.gpio_p_on = NULL;
} if (platform->pdata.gpio_p_on && platform->pdata.gpio_reset) { platform->pdata.low_power_mode = 1;
devm_gpiod_get_optional() is possible to return NULL (see https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.boo...). Thus, we should use IS_ERR_OR_NULL for checking the return value.
Hi Tzung-Bi Shih, IS_ERR_OR_NULL is better, I'll use it.
Thanks, Xin
The cases here would work fine except it will skip to print some informative messages.
Acked-by: Tzung-Bi Shih tzungbi@google.com
dri-devel@lists.freedesktop.org