Skip to contentSkip to conversation

media: i2c: ak7375: fix regulator leak on remove while runtime-active

PATCH New Cong Nguyen 1 participant 1 message Sep 28

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

PATCH 1/1 media: i2c: ak7375: fix regulator leak on remove while runtime-active

ak7375_remove() calls pm_runtime_set_suspended(), but that's pure bookkeeping -- it doesn't call ak7375_vcm_suspend() or otherwise disable the regulator. ak7375_open()/close() hold a resume_and_get()/ put() pair for as long as a /dev/v4l-subdevX fd stays open, and nothing requires userspace to close it before unbind -- so removing the driver with an fd still open leaves the regulator on with no code path left to ever disable it.

Call ak7375_vcm_suspend() in that case, guarded by pm_runtime_status_suspended() so the common already-suspended case isn't suspended twice -- same guard sibling imx412.c's remove() uses.

Moved remove() after suspend()/resume()'s definitions since it now calls them directly.

Fixes 90ee26fb2f50 ("media: ak7375: Add ak7375 lens voice coil driver")
Assisted-by LLM
---
 drivers/media/i2c/ak7375.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/media/i2c/ak7375.c +12 -10
index 9a2432cea3ff..79327440f0b5 100644
@@ -229,16 +229,6 @@ static int ak7375_probe(struct i2c_client *client)
 	return ret;
 }
 
-static void ak7375_remove(struct i2c_client *client)
-{
-	struct v4l2_subdev *sd = i2c_get_clientdata(client);
-	struct ak7375_device *ak7375_dev = sd_to_ak7375_vcm(sd);
-
-	ak7375_subdev_cleanup(ak7375_dev);
-	pm_runtime_disable(&client->dev);
-	pm_runtime_set_suspended(&client->dev);
-}
-
 /*
  * This function sets the vcm position, so it consumes least current
  * The lens position is gradually moved in units of ctrl_steps,
@@ -328,6 +318,18 @@ static int __maybe_unused ak7375_vcm_resume(struct device *dev)
 	return 0;
 }
 
+static void ak7375_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *sd = i2c_get_clientdata(client);
+	struct ak7375_device *ak7375_dev = sd_to_ak7375_vcm(sd);
+
+	ak7375_subdev_cleanup(ak7375_dev);
+	pm_runtime_disable(&client->dev);
+	if (!pm_runtime_status_suspended(&client->dev))
+		ak7375_vcm_suspend(&client->dev);
+	pm_runtime_set_suspended(&client->dev);
+}
+
 static const struct of_device_id ak7375_of_table[] = {
 	{ .compatible = "asahi-kasei,ak7345", .data = &ak7345_cdef, },
 	{ .compatible = "asahi-kasei,ak7375", .data = &ak7375_cdef, },
Signature · 1 line
2.25.1