Skip to contentSkip to conversation

drm/nouveau/nvkm: adjust memory check and use in proper order

PATCH New Weiguo Li 1 participant 2 messages Jan 27, 2022 – Feb 9, 2022

Subsystems (3)
lore
Share & tools
lore

Weiguo Li

author
#0 lore raw

PATCH 1/1 drm/nouveau/nvkm: adjust memory check and use in proper order

---
 drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c     | 2 +-
 drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c | 2 +-
 drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c +1 -1
index 57199be082fd..e83715873ffc 100644
@@ -416,9 +416,9 @@ nvkm_pstate_new(struct nvkm_clk *clk, int idx)
 		return 0;
 
 	pstate = kzalloc(sizeof(*pstate), GFP_KERNEL);
-	cstate = &pstate->base;
 	if (!pstate)
 		return -ENOMEM;
+	cstate = &pstate->base;
 
 	INIT_LIST_HEAD(&pstate->list);
 
drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c +1 -1
index 340f37a299dc..f4b34ebdcae5 100644
@@ -98,9 +98,9 @@ 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;
drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c +1 -1
index ff9fbe7950e5..71a1e56d0d99 100644
@@ -100,9 +100,9 @@ nvkm_fantog_create(struct nvkm_therm *therm, struct dcb_gpio_func *func)
 	}
 
 	fan = kzalloc(sizeof(*fan), GFP_KERNEL);
-	therm->fan = &fan->base;
 	if (!fan)
 		return -ENOMEM;
+	therm->fan = &fan->base;
 
 	fan->base.type = "toggle";
 	fan->base.get = nvkm_fantog_get;
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/1 drm/nouveau/nvkm: fix dereference before null check

Move pointer dereference after null check.

---
v2:
* update commit log

---
 drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c     | 2 +-
 drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c | 2 +-
 drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/clk/base.c +1 -1
index 57199be082fd..e83715873ffc 100644
@@ -416,9 +416,9 @@ nvkm_pstate_new(struct nvkm_clk *clk, int idx)
 		return 0;
 
 	pstate = kzalloc(sizeof(*pstate), GFP_KERNEL);
-	cstate = &pstate->base;
 	if (!pstate)
 		return -ENOMEM;
+	cstate = &pstate->base;
 
 	INIT_LIST_HEAD(&pstate->list);
 
drivers/gpu/drm/nouveau/nvkm/subdev/therm/fanpwm.c +1 -1
index 340f37a299dc..f4b34ebdcae5 100644
@@ -98,9 +98,9 @@ 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;
drivers/gpu/drm/nouveau/nvkm/subdev/therm/fantog.c +1 -1
index ff9fbe7950e5..71a1e56d0d99 100644
@@ -100,9 +100,9 @@ nvkm_fantog_create(struct nvkm_therm *therm, struct dcb_gpio_func *func)
 	}
 
 	fan = kzalloc(sizeof(*fan), GFP_KERNEL);
-	therm->fan = &fan->base;
 	if (!fan)
 		return -ENOMEM;
+	therm->fan = &fan->base;
 
 	fan->base.type = "toggle";
 	fan->base.get = nvkm_fantog_get;
Signature · 1 line
2.25.1