Skip to contentSkip to conversation

media: i2c: dw9719: power down on detection errors

PATCH In review Myeonghun Pak 2 participants 2 messages Sep 13 – Oct 17

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

PATCH 1/1 media: i2c: dw9719: power down on detection errors

Moving chip detection into dw9719_power_up() introduced direct returns after the regulator has been enabled. An INFO register read failure or an unrecognized ID bypasses the power-down path, while probe only cleans up the media entity and controls after a power-up error.

Route both detection errors through the existing power-down check. Preserve the read error or -ENXIO and leave the successful power-up and regulator enable failure paths unchanged.

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

Fixes 2a1551665a85 ("media: dw9719: Add DW9761 support")
Assisted-by OpenAI:GPT-5.6
---
 drivers/media/i2c/dw9719.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/media/i2c/dw9719.c +4 -2
index 3b7ba88fd..8a34abe18 100644
@@ -150,7 +150,7 @@ static int dw9719_power_up(struct dw9719_device *dw9719, bool detect)
 
 		ret = cci_read(dw9719->regmap, DW9719_INFO, &val, NULL);
 		if (ret < 0)
-			return ret;
+			goto out;
 
 		switch (val) {
 		case DW9719_ID:
@@ -168,7 +168,8 @@ static int dw9719_power_up(struct dw9719_device *dw9719, bool detect)
 		default:
 			dev_err(dw9719->dev,
 				"Error unknown device id 0x%02llx\n", val);
-			return -ENXIO;
+			ret = -ENXIO;
+			goto out;
 		}
 
 props:
@@ -218,6 +219,7 @@ static int dw9719_power_up(struct dw9719_device *dw9719, bool detect)
 		cci_write(dw9719->regmap, DW9719_VCM_FREQ, dw9719->vcm_freq, &ret);
 	}
 
+out:
 	if (ret)
 		dw9719_power_down(dw9719);
 
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 4 lines · Myeonghun Pak

Moving chip detection into dw9719_power_up() introduced direct returns after the regulator has been enabled. An INFO register read failure or an unrecognized ID bypasses the power-down path, while probe only cleans up the media entity and controls after a power-up error.

I found the same leak independently while adding DW9800W support for the Surface Pro 9, and wrote the same change.

I tested both error paths on a Surface Pro 9 (DW9800W, ACPI, a 7.2.11 distro kernel with the linux-surface patches), forcing them with a test-only hook: an unknown INFO id, and a failed INFO read. Without your patch, each failed probe hit the WARN_ON(regulator->enable_count) in _regulator_put(), reported as regulator_put() because it is inlined there, and the (dummy) supply's num_users stayed one higher. With your patch, neither happened. An equivalent change in my tree also runs fine through the normal path, including runtime and system suspend.

The patch still applies cleanly to the media-committers next branch.

Thanks,
Chris

Made with AI assistance. Written by Claude Opus 5.5 (drafting), with review by Claude Fable 5.1 and testing by Claude Opus 5.5, under the direction of Chris Simpson <[email protected]>, who reviewed and approved it.