Skip to contentSkip to conversation

drm/gma500: unwind resources on backlight init failure

PATCH New Myeonghun Pak 1 participant 1 message Sep 15

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

PATCH v2 1/1 drm/gma500: unwind resources on backlight init failure

psb_driver_load() initializes KMS polling before it attempts to initialize backlight support. If gma_backlight_init() fails, the function returns directly and skips psb_driver_unload(), leaving the resources allocated earlier in probe, including KMS polling, active.

Simply using out_err is not safe: a failed backlight_device_register() leaves an error pointer in backlight_device, which gma_backlight_exit() would pass to backlight_device_unregister().

Move backlight cleanup to psb_device_release(), which is registered only after successful backlight initialization, and use out_err on backlight initialization failure. This unwinds the earlier resources without trying to unregister a failed backlight device. Normal device release and failure to register the managed release action retain the existing cleanup order.

This issue was identified during our ongoing static-analysis research while reviewing kernel code.

Fixes 1f90b1232773 ("drm/gma500: Refactor backlight support (v2)")

---
Changes in v2:
- Move backlight cleanup to the managed release callback so the probe error path cannot unregister an ERR_PTR, addressing Patrik's feedback.

 drivers/gpu/drm/gma500/psb_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/gma500/psb_drv.c +2 -2
index 005ab7f535..c4cc4bf5f4 100644
@@ -170,7 +170,6 @@ static void psb_driver_unload(struct drm_device *dev)
 
 	/* TODO: Kill vblank etc here */
 
-	gma_backlight_exit(dev);
 	psb_modeset_cleanup(dev);
 
 	gma_irq_uninstall(dev);
@@ -227,6 +226,7 @@ static void psb_device_release(void *data)
 {
 	struct drm_device *dev = data;
 
+	gma_backlight_exit(dev);
 	psb_driver_unload(dev);
 }
 
@@ -406,7 +406,7 @@ static int psb_driver_load(struct drm_device *dev, unsigned long flags)
 	drm_connector_list_iter_end(&conn_iter);
 
 	if (ret)
-		return ret;
+		goto out_err;
 	psb_intel_opregion_enable_asle(dev);
 
 	return devm_add_action_or_reset(dev->dev, psb_device_release, dev);
Signature · 1 line
2.47.1