drm/amd/display: Check hpd_gpio for NULL before accessing it

Submitted by Wentland, Harry on Feb. 7, 2019, 8:12 p.m.

Details

Message ID 20190207201235.30106-1-harry.wentland@amd.com
State Accepted
Commit 0461221316ec21e0a535a35fba3feb6ba75706e6
Headers show
Series "drm/amd/display: Check hpd_gpio for NULL before accessing it" ( rev: 1 ) in AMD X.Org drivers

Not browsing as part of any series.

Commit Message

Wentland, Harry Feb. 7, 2019, 8:12 p.m.
dal_gpio_open and dal_gpio_unlock_pin dereference hpd_gpio.
Check for NULL before calling those functions.

Fixes: e261568f94d6 ("drm/amd/display: add gpio lock/unlock")
Reported-by: Przemek Socha <soprwa@gmail.com>
CC: Chiawen Huang <chiawen.huang@amd.com>
CC: Tony Cheng <Tony.Cheng@amd.com>
Signed-off-by: Harry Wentland <harry.wentland@amd.com>
---

I don't have a system to test this on. Can someone give it a spin?

Harry

 drivers/gpu/drm/amd/display/dc/core/dc_link.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link.c b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
index 6d2cef05b4d7..7f5a947ad31d 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_link.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
@@ -1127,10 +1127,11 @@  static bool construct(
 		link->dc->res_pool->funcs->link_init(link);
 
 	link->hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
-	dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
-	dal_gpio_unlock_pin(link->hpd_gpio);
-	if (link->hpd_gpio != NULL)
+	if (link->hpd_gpio != NULL) {
+		dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
+		dal_gpio_unlock_pin(link->hpd_gpio);
 		link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
+	}
 
 	switch (link->link_id.id) {
 	case CONNECTOR_ID_HDMI_TYPE_A:

Comments

On Thu, Feb 7, 2019 at 3:12 PM Harry Wentland <harry.wentland@amd.com> wrote:
>
> dal_gpio_open and dal_gpio_unlock_pin dereference hpd_gpio.
> Check for NULL before calling those functions.
>
> Fixes: e261568f94d6 ("drm/amd/display: add gpio lock/unlock")
> Reported-by: Przemek Socha <soprwa@gmail.com>
> CC: Chiawen Huang <chiawen.huang@amd.com>
> CC: Tony Cheng <Tony.Cheng@amd.com>
> Signed-off-by: Harry Wentland <harry.wentland@amd.com>

Acked-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>
> I don't have a system to test this on. Can someone give it a spin?
>
> Harry
>
>  drivers/gpu/drm/amd/display/dc/core/dc_link.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link.c b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
> index 6d2cef05b4d7..7f5a947ad31d 100644
> --- a/drivers/gpu/drm/amd/display/dc/core/dc_link.c
> +++ b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
> @@ -1127,10 +1127,11 @@ static bool construct(
>                 link->dc->res_pool->funcs->link_init(link);
>
>         link->hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
> -       dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
> -       dal_gpio_unlock_pin(link->hpd_gpio);
> -       if (link->hpd_gpio != NULL)
> +       if (link->hpd_gpio != NULL) {
> +               dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
> +               dal_gpio_unlock_pin(link->hpd_gpio);
>                 link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
> +       }
>
>         switch (link->link_id.id) {
>         case CONNECTOR_ID_HDMI_TYPE_A:
> --
> 2.19.1
>
On Thu, Feb 7, 2019 at 3:14 PM Alex Deucher <alexdeucher@gmail.com> wrote:
>
> On Thu, Feb 7, 2019 at 3:12 PM Harry Wentland <harry.wentland@amd.com> wrote:
> >
> > dal_gpio_open and dal_gpio_unlock_pin dereference hpd_gpio.
> > Check for NULL before calling those functions.
> >
> > Fixes: e261568f94d6 ("drm/amd/display: add gpio lock/unlock")
> > Reported-by: Przemek Socha <soprwa@gmail.com>
> > CC: Chiawen Huang <chiawen.huang@amd.com>
> > CC: Tony Cheng <Tony.Cheng@amd.com>
> > Signed-off-by: Harry Wentland <harry.wentland@amd.com>
>
> Acked-by: Alex Deucher <alexander.deucher@amd.com>
>

Just tried it on a bonaire.
Tested-by: Alex Deucher <alexander.deucher@amd.com>

> > ---
> >
> > I don't have a system to test this on. Can someone give it a spin?
> >
> > Harry
> >
> >  drivers/gpu/drm/amd/display/dc/core/dc_link.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_link.c b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
> > index 6d2cef05b4d7..7f5a947ad31d 100644
> > --- a/drivers/gpu/drm/amd/display/dc/core/dc_link.c
> > +++ b/drivers/gpu/drm/amd/display/dc/core/dc_link.c
> > @@ -1127,10 +1127,11 @@ static bool construct(
> >                 link->dc->res_pool->funcs->link_init(link);
> >
> >         link->hpd_gpio = get_hpd_gpio(link->ctx->dc_bios, link->link_id, link->ctx->gpio_service);
> > -       dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
> > -       dal_gpio_unlock_pin(link->hpd_gpio);
> > -       if (link->hpd_gpio != NULL)
> > +       if (link->hpd_gpio != NULL) {
> > +               dal_gpio_open(link->hpd_gpio, GPIO_MODE_INTERRUPT);
> > +               dal_gpio_unlock_pin(link->hpd_gpio);
> >                 link->irq_source_hpd = dal_irq_get_source(link->hpd_gpio);
> > +       }
> >
> >         switch (link->link_id.id) {
> >         case CONNECTOR_ID_HDMI_TYPE_A:
> > --
> > 2.19.1
> >