Skip to contentSkip to conversation

media: i2c: t4ka3: power down sensor on resume failure and use devm_mutex_init

PATCH New [email protected] 1 participant 1 message Jul 24

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

PATCH 1/1 media: i2c: t4ka3: power down sensor on resume failure and use devm_mutex_init

From: Surendra Singh Chouhan <[email protected]>

t4ka3_probe() calls t4ka3_pm_resume() to power on the sensor during initialization. If t4ka3_pm_resume() failed (e.g. due to GPIO configuration or hardware errors), t4ka3_probe() returned directly without calling t4ka3_pm_suspend(), leaving powerdown/reset GPIOs in a partially initialized powered-on state.

Fix this by invoking t4ka3_pm_suspend() if t4ka3_pm_resume() fails during probe. In addition, replace mutex_init() with devm_mutex_init() for managed resource lifecycle handling.

Fixes fd5531969215 ("media: Add t4ka3 camera sensor driver")
---
 drivers/media/i2c/t4ka3.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/media/i2c/t4ka3.c +6 -2
index a5a68e3fbec2..0c38bb8dc718 100644
@@ -968,7 +968,9 @@ static int t4ka3_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
-	mutex_init(&sensor->lock);
+	ret = devm_mutex_init(&client->dev, &sensor->lock);
+	if (ret)
+		return ret;
 
 	v4l2_i2c_subdev_init(&sensor->sd, client, &t4ka3_ops);
 	sensor->sd.internal_ops = &t4ka3_internal_ops;
@@ -991,8 +993,10 @@ static int t4ka3_probe(struct i2c_client *client)
 		return PTR_ERR(sensor->regmap);
 
 	ret = t4ka3_pm_resume(sensor->dev);
-	if (ret)
+	if (ret) {
+		t4ka3_pm_suspend(sensor->dev);
 		return ret;
+	}
 
 	pm_runtime_set_active(&client->dev);
 	pm_runtime_enable(&client->dev);
Signature · 1 line
2.55.0