Skip to contentSkip to conversation

macintosh/windfarm: Zero-initialize cached fan value

PATCH New Thorsten Blum 1 participant 1 message Nov 25 Linux for power macintosh

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 macintosh/windfarm: Zero-initialize cached fan value

smu_fan_create() allocates the control with kmalloc_obj(), which leaves fct->value uninitialized. Once the control is registered, reading the fan control via sysfs and smu_fan_get() before the first call to smu_fan_set() can therefore expose uninitialized heap data.

Use kzalloc_obj() to zero-initialize the control instead.

Note that smu_fan_get() returns the cached value set by smu_fan_set() without querying the SMU. The initial value of 0 is thus only a placeholder and does not indicate that the fan is stopped.

Fixes 75722d3992f5 ("[PATCH] ppc64: Thermal control for SMU based machines")
---
 drivers/macintosh/windfarm_smu_controls.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/macintosh/windfarm_smu_controls.c +1 -1
index 671ff959bf06..2f4dc0e2be40 100644
@@ -149,7 +149,7 @@ static struct smu_fan_control *smu_fan_create(struct device_node *node,
 	const u32 *reg;
 	const char *l;
 
-	fct = kmalloc_obj(struct smu_fan_control);
+	fct = kzalloc_obj(*fct);
 	if (fct == NULL)
 		return NULL;
 	fct->ctrl.ops = &smu_fan_ops;