Skip to contentSkip to conversation

media: microchip-csi2dc: fix async notifier leak on probe error path

PATCH In review Cong Nguyen 2 participants 2 messages Aug 8 – Aug 10

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

PATCH 1/1 media: microchip-csi2dc: fix async notifier leak on probe error path

csi2dc_of_parse() ends up calling csi2dc_prepare_notifier(), which registers the V4L2 async notifier with v4l2_async_nf_register(). The probe error label csi2dc_probe_cleanup_notifier is reached after csi2dc_of_parse() has already succeeded (e.g. when media entity init, csi2dc_power() or v4l2_async_register_subdev() fail), but it calls only v4l2_async_nf_cleanup() and never v4l2_async_nf_unregister().

The notifier therefore stays chained in the global notifier_list while the enclosing struct csi2dc_device is freed, leading to list corruption and a use-after-free when the list is next walked.

Unregister the notifier before cleaning it up on the error path, matching the teardown already done in csi2dc_remove().

Fixes 2de0b3c0f678 ("media: atmel: introduce microchip csi2dc driver")
Assisted-by Claude:claude-opus-4
---
 drivers/media/platform/microchip/microchip-csi2dc.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/platform/microchip/microchip-csi2dc.c +1 -0
index 70303a0b6919..59574258ab2b 100644
@@ -736,6 +736,7 @@ static int csi2dc_probe(struct platform_device *pdev)
 	return 0;
 
 csi2dc_probe_cleanup_notifier:
+	v4l2_async_nf_unregister(&csi2dc->notifier);
 	v4l2_async_nf_cleanup(&csi2dc->notifier);
 csi2dc_probe_cleanup_entity:
 	media_entity_cleanup(&csi2dc->csi2dc_sd.entity);
Signature · 1 line
2.25.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Cong Nguyen

csi2dc_of_parse() ends up calling csi2dc_prepare_notifier(), which registers the V4L2 async notifier with v4l2_async_nf_register(). The probe error label csi2dc_probe_cleanup_notifier is reached after csi2dc_of_parse() has already succeeded (e.g. when media entity init, csi2dc_power() or v4l2_async_register_subdev() fail), but it calls only v4l2_async_nf_cleanup() and never v4l2_async_nf_unregister().

The notifier therefore stays chained in the global notifier_list while the enclosing struct csi2dc_device is freed, leading to list corruption and a use-after-free when the list is next walked.

Quoted 8 lines

Unregister the notifier before cleaning it up on the error path, matching the teardown already done in csi2dc_remove().

Fixes 2de0b3c0f678 ("media: atmel: introduce microchip csi2dc driver")
Assisted-by Claude:claude-opus-4

---