[PATCH v1] drm/nouveau/clk: avoid potential null-dereference

Ilia Mirkin imirkin at alum.mit.edu
Wed Jan 7 18:45:31 PST 2015


On Wed, Jan 7, 2015 at 5:29 PM, Andy Shevchenko
<andy.shevchenko at gmail.com> wrote:
> We have to check pointer before usage.
>
> Reported-by: Andrey Karpov <karpov at viva64.com>
> Signed-off-by: Andy Shevchenko <andy.shevchenko at gmail.com>
> ---
>  drivers/gpu/drm/nouveau/core/subdev/clock/base.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/core/subdev/clock/base.c b/drivers/gpu/drm/nouveau/core/subdev/clock/base.c
> index e51b72d..2e84436 100644
> --- a/drivers/gpu/drm/nouveau/core/subdev/clock/base.c
> +++ b/drivers/gpu/drm/nouveau/core/subdev/clock/base.c
> @@ -322,7 +322,6 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)
>                 return 0;
>
>         pstate = kzalloc(sizeof(*pstate), GFP_KERNEL);
> -       cstate = &pstate->base;

What's wrong with this line? If pstate == NULL, &pstate->base == NULL
as well and we return.

>         if (!pstate)
>                 return -ENOMEM;
>
> @@ -330,6 +329,9 @@ nouveau_pstate_new(struct nouveau_clock *clk, int idx)
>
>         pstate->pstate = perfE.pstate;
>         pstate->fanspeed = perfE.fanspeed;
> +
> +       cstate = &pstate->base;
> +
>         cstate->voltage = perfE.voltage;
>         cstate->domain[nv_clk_src_core] = perfE.core;
>         cstate->domain[nv_clk_src_shader] = perfE.shader;
> --
> 1.8.3.101.g727a46b
>
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel


More information about the dri-devel mailing list