[PATCH 4.14 058/189] thermal: int3403_thermal: Fix NULL pointer deref on module load / probe

Greg Kroah-Hartman
2018-06-18T08:31:41Z

From: Hans de Goede <hdegoede@redhat.com>

[ Upstream commit 13b86f50eaaddaea4bdd2fe476fd12e6a0951add ]

Starting with kernel 4.17 thermal_cooling_device_register() will call the
get_max_state() op during register.

Since we deref priv->priv in int3403_get_max_state() this means we must
set priv->priv before calling thermal_cooling_device_register().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/thermal/int340x_thermal/int3403_thermal.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

--- a/drivers/thermal/int340x_thermal/int3403_thermal.c
+++ b/drivers/thermal/int340x_thermal/int3403_thermal.c
@@ -194,6 +194,7 @@ static int int3403_cdev_add(struct int34
return -EFAULT;
}

+ priv->priv = obj;
obj->max_state = p->package.count - 1;
obj->cdev =
thermal_cooling_device_register(acpi_device_bid(priv->adev),
@@ -201,8 +202,6 @@ static int int3403_cdev_add(struct int34
if (IS_ERR(obj->cdev))
result = PTR_ERR(obj->cdev);

- priv->priv = obj;
-
kfree(buf.pointer);
/* TODO: add ACPI notification support */