In nouveau_hwmon_init(), if hwmon_device_register_with_info() fails,
the allocated hwmon structure is leaked because the function returns
the error code directly.
Fix this by freeing the allocated memory and clearing the pointer on
the error path.
Fixes: b9ed919f1c8f ("drm/nouveau/drm/pm: remove everything except the hwmon
interfaces to THERM")
Cc: [email protected]
Reviewed-by: Lyude Paul <[email protected]>
Signed-off-by: liupeng <[email protected]>
---
Changes in v4:
- Split the debugfs and hwmon fixes into two separate patches as
requested by Danilo, since they are unrelated fixes with different
Fixes: tags. No functional change to this fix.
drivers/gpu/drm/nouveau/nouveau_hwmon.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c
b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
index 726397ab035d..ffbe7f542ab0 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c
+++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
@@ -697,6 +697,8 @@ nouveau_hwmon_init(struct drm_device *dev)
if (IS_ERR(hwmon_dev)) {
ret = PTR_ERR(hwmon_dev);
NV_ERROR(drm, "Unable to register hwmon device: %d\n", ret);
+ drm->hwmon = NULL;
+ kfree(hwmon);
return ret;
}
--
2.53.0