2022-05-30 12:06:27

by baihaowen

[permalink] [raw]
Subject: [PATCH] drm/nouveau/therm: Fix pointer dereferenced before checking

The fan->base is dereferencing before null checking, so move
it after checking.

Signed-off-by: Haowen Bai <[email protected]>
---
drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c
index 340f37a299dc..b13ba9b2f6be 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c
@@ -98,10 +98,10 @@ nvkm_fanpwm_create(struct nvkm_therm *therm, struct dcb_gpio_func *func)
return -ENODEV;

fan = kzalloc(sizeof(*fan), GFP_KERNEL);
- therm->fan = &fan->base;
if (!fan)
return -ENOMEM;

+ therm->fan = &fan->base;
fan->base.type = "PWM";
fan->base.get = nvkm_fanpwm_get;
fan->base.set = nvkm_fanpwm_set;
--
2.7.4



2022-06-01 20:46:19

by baihaowen

[permalink] [raw]
Subject: Re: [PATCH] drm/nouveau/therm: Fix pointer dereferenced before checking


在 2022/5/30 上午11:10, Haowen Bai 写道:
> The fan->base is dereferencing before null checking, so move
> it after checking.
>
> Signed-off-by: Haowen Bai <[email protected]>
> ---
> drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c
> index 340f37a299dc..b13ba9b2f6be 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c
> @@ -98,10 +98,10 @@ nvkm_fanpwm_create(struct nvkm_therm *therm, struct dcb_gpio_func *func)
> return -ENODEV;
>
> fan = kzalloc(sizeof(*fan), GFP_KERNEL);
> - therm->fan = &fan->base;
> if (!fan)
> return -ENOMEM;
>
> + therm->fan = &fan->base;
> fan->base.type = "PWM";
> fan->base.get = nvkm_fanpwm_get;
> fan->base.set = nvkm_fanpwm_set;
Sorry, plz ignore this patch.

fan->base is dereferenced, &fan->base is just a pointer math for pointer address offset, so it would not cause a bug(dereferencing null pointer).



--
Haowen Bai