Skip to contentSkip to conversation

intel_th: Clear dangling resource pointer in subdevice alloc error path

PATCH New Haotian Zhang 1 participant 1 message Jul 9

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 intel_th: Clear dangling resource pointer in subdevice alloc error path

When device_add() fails, intel_th_subdevice_alloc() jumps to fail_free_res which kfree()s thdev->resource but leaves the pointer dangling, then falls through to fail_put_device where put_device() triggers the .release callback intel_th_device_free() which kfree()s thdev->resource again, causing a double free.

Set thdev->resource to NULL after kfree() so the subsequent intel_th_device_free() finds a NULL pointer and skips it.

Fixes a753bfcfdb1f ("intel_th: Make the switch allocate its subdevices")
---
 drivers/hwtracing/intel_th/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/hwtracing/intel_th/core.c +1 -0
index 3924e63e2eee..3ab1a37b045e 100644
@@ -696,6 +696,7 @@ intel_th_subdevice_alloc(struct intel_th *th,
 
 fail_free_res:
 	kfree(thdev->resource);
+	thdev->resource = NULL;
 
 fail_put_device:
 	put_device(&thdev->dev);
Signature · 1 line
2.25.1