* [PATCH] drm/bridge: anx7625: Check GPIO description to avoid crash
@ 2021-11-18 3:11 Xin Ji
2021-11-18 4:52 ` Tzung-Bi Shih
0 siblings, 1 reply; 3+ messages in thread
From: Xin Ji @ 2021-11-18 3:11 UTC (permalink / raw)
To: a.hajda, narmstrong, dan.carpenter, robert.foss,
Laurent.pinchart, jonas, jernej.skrabec, airlied, daniel, sam,
pihsun, tzungbi, maxime, drinkcat, hsinyi, dri-devel,
linux-kernel, bliang, qwen
Cc: Xin Ji
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;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/bridge: anx7625: Check GPIO description to avoid crash
2021-11-18 3:11 [PATCH] drm/bridge: anx7625: Check GPIO description to avoid crash Xin Ji
@ 2021-11-18 4:52 ` Tzung-Bi Shih
2021-11-18 5:43 ` Xin Ji
0 siblings, 1 reply; 3+ messages in thread
From: Tzung-Bi Shih @ 2021-11-18 4:52 UTC (permalink / raw)
To: Xin Ji
Cc: a.hajda, narmstrong, dan.carpenter, robert.foss,
Laurent.pinchart, jonas, jernej.skrabec, airlied, daniel, sam,
pihsun, maxime, drinkcat, hsinyi, dri-devel, linux-kernel,
bliang, qwen
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.c#L250).
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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/bridge: anx7625: Check GPIO description to avoid crash
2021-11-18 4:52 ` Tzung-Bi Shih
@ 2021-11-18 5:43 ` Xin Ji
0 siblings, 0 replies; 3+ messages in thread
From: Xin Ji @ 2021-11-18 5:43 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: narmstrong, dan.carpenter, robert.foss, Laurent.pinchart, jonas,
jernej.skrabec, airlied, daniel, sam, pihsun, maxime, drinkcat,
hsinyi, dri-devel, linux-kernel, bliang, qwen
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.bootlin.com%2Flinux%2Fv5.15.2%2Fsource%2Fdrivers%2Fgpio%2Fgpiolib-devres.c%23L250&data=04%7C01%7Cxji%40analogixsemi.com%7C40e84a44676149c2544a08d9aa4f37f0%7Cb099b0b4f26c4cf59a0fd5be9acab205%7C0%7C0%7C637728079481953910%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=2UPuAadtM%2FObwkwE6fLhJr7uCfWN%2Fr29o4t8uqUU2Ls%3D&reserved=0).
> 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>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-18 5:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-18 3:11 [PATCH] drm/bridge: anx7625: Check GPIO description to avoid crash Xin Ji
2021-11-18 4:52 ` Tzung-Bi Shih
2021-11-18 5:43 ` Xin Ji
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).