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

kr494167@gmail.com posted 1 patch 12 hours ago
drivers/media/i2c/t4ka3.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] media: i2c: t4ka3: power down sensor on resume failure and use devm_mutex_init
Posted by kr494167@gmail.com 12 hours ago
From: Surendra Singh Chouhan <kr494167@gmail.com>

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")
Signed-off-by: Surendra Singh Chouhan <kr494167@gmail.com>
---
 drivers/media/i2c/t4ka3.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/t4ka3.c b/drivers/media/i2c/t4ka3.c
index a5a68e3fbec2..0c38bb8dc718 100644
--- a/drivers/media/i2c/t4ka3.c
+++ b/drivers/media/i2c/t4ka3.c
@@ -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);
-- 
2.55.0