Skip to contentSkip to conversation

media: i2c: power off the device in remove()

PATCH New Cong Nguyen 1 participant 17 messages Nov 23

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

v2 cover media: i2c: power off the device in remove()

Several media/i2c drivers disable runtime PM in remove() without running the runtime suspend callback. pm_runtime_disable() does not do that, so a device that is still runtime active when the driver is unbound can stay
powered: its supplies and clock stay enabled and its reset or power-down lines stay released. ov5670 and ov8856 go the other way and power the device off unconditionally, which disables the regulators and the clock a second time in the usual case where the device is already suspended.

Each fix follows the pattern ov5647, og01a1b and imx412 already use: after pm_runtime_disable(), power the device off if it is not runtime suspended, and set the runtime PM status to suspended.

This replaces the individual patches I sent earlier for hi556, ak7375, ov13b10, ov2740 and ov5670. ov8856, ov5648, ov8865, tw9900, isl7998x and tc358746 are new.

Changes since the individual patches:
- Sent as one series, as Sakari asked. Where remove() is defined before the PM callbacks, moving it is a separate patch with no functional change.
- remove() now also sets the runtime PM status to suspended.
- The commit messages are rewritten.
- ov5647 and og01a1b are dropped: Guangshuo Li's fixes for them are already in.
- ak7375: the earlier patch called the suspend callback after ak7375_subdev_cleanup(), but the callback reads the focus control that the cleanup frees. It is now called before the cleanup.

Cong Nguyen (16):
media: i2c: hi556: move remove() after the PM callbacks
media: i2c: hi556: power off the sensor on remove
media: i2c: ov2740: move remove() after the PM callbacks
media: i2c: ov2740: power off the sensor on remove
media: i2c: ak7375: move remove() after the PM callbacks
media: i2c: ak7375: power off the lens driver on remove
media: i2c: ov13b10: power off the sensor on remove
media: i2c: ov5670: do not power off twice on remove
media: i2c: ov8856: do not power off twice on remove
media: i2c: ov5648: power off the sensor on remove
media: i2c: ov8865: power off the sensor on remove
media: i2c: tw9900: power off the decoder on remove
media: i2c: isl7998x: move remove() after the PM callbacks
media: i2c: isl7998x: power down the decoder on remove
media: i2c: tc358746: move remove() after the PM callbacks
media: i2c: tc358746: power off the bridge on remove

 drivers/media/i2c/ak7375.c   | 22 +++++++++++---------
 drivers/media/i2c/hi556.c    | 28 +++++++++++++++-----------
 drivers/media/i2c/isl7998x.c | 24 +++++++++++++---------
 drivers/media/i2c/ov13b10.c  |  5 ++++-
 drivers/media/i2c/ov2740.c   | 26 ++++++++++++++----------
 drivers/media/i2c/ov5648.c   |  4 ++++
 drivers/media/i2c/ov5670.c   |  5 ++++-
 drivers/media/i2c/ov8856.c   |  5 ++++-
 drivers/media/i2c/ov8865.c   |  4 ++++
 drivers/media/i2c/tc358746.c | 39 +++++++++++++++++++-----------------
 drivers/media/i2c/tw9900.c   |  4 ++++
 11 files changed, 102 insertions(+), 64 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/16 media: i2c: hi556: move remove() after the PM callbacks

Move hi556_remove() below the runtime PM callbacks so that the following patch ("media: i2c: hi556: power off the sensor on remove") can call them from it without a forward declaration.

No functional change.

---
 drivers/media/i2c/hi556.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/media/i2c/hi556.c +12 -12
index 3b725bc59057..a151bab26821 100644
@@ -1266,18 +1266,6 @@ static int hi556_check_hwcfg(struct device *dev)
 	return ret;
 }
 
-static void hi556_remove(struct i2c_client *client)
-{
-	struct v4l2_subdev *sd = i2c_get_clientdata(client);
-	struct hi556 *hi556 = to_hi556(sd);
-
-	v4l2_async_unregister_subdev(sd);
-	media_entity_cleanup(&sd->entity);
-	v4l2_ctrl_handler_free(sd->ctrl_handler);
-	pm_runtime_disable(hi556->dev);
-	mutex_destroy(&hi556->mutex);
-}
-
 static int hi556_suspend(struct device *dev)
 {
 	struct v4l2_subdev *sd = dev_get_drvdata(dev);
@@ -1427,6 +1415,18 @@ static int hi556_probe(struct i2c_client *client)
 	return ret;
 }
 
+static void hi556_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *sd = i2c_get_clientdata(client);
+	struct hi556 *hi556 = to_hi556(sd);
+
+	v4l2_async_unregister_subdev(sd);
+	media_entity_cleanup(&sd->entity);
+	v4l2_ctrl_handler_free(sd->ctrl_handler);
+	pm_runtime_disable(hi556->dev);
+	mutex_destroy(&hi556->mutex);
+}
+
 static DEFINE_RUNTIME_DEV_PM_OPS(hi556_pm_ops, hi556_suspend, hi556_resume,
 				 NULL);
 
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/16 media: i2c: hi556: power off the sensor on remove

In reply to Cong Nguyen

hi556_set_stream() takes a runtime PM reference with pm_runtime_resume_and_get() when streaming starts and drops it when streaming stops. hi556_remove() only calls pm_runtime_disable(), which does not run the runtime suspend callback, so a device that is still runtime active when the driver is unbound can keep its clock and regulators enabled and its reset line released.

The probe error path already calls hi556_suspend() when the sensor was powered on. After disabling runtime PM in remove(), do the same if the device is not runtime suspended, and set the runtime PM status to suspended. Avoid powering it off again when runtime suspend has already done so.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes e62138403a84 ("media: hi556: Add support for Hi-556 sensor")
---
 drivers/media/i2c/hi556.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/i2c/hi556.c +4 -0
index a151bab26821..0d1d52d79a79 100644
@@ -1424,6 +1424,10 @@ static void hi556_remove(struct i2c_client *client)
 	media_entity_cleanup(&sd->entity);
 	v4l2_ctrl_handler_free(sd->ctrl_handler);
 	pm_runtime_disable(hi556->dev);
+	if (!pm_runtime_status_suspended(hi556->dev)) {
+		hi556_suspend(hi556->dev);
+		pm_runtime_set_suspended(hi556->dev);
+	}
 	mutex_destroy(&hi556->mutex);
 }
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 3/16 media: i2c: ov2740: move remove() after the PM callbacks

In reply to Cong Nguyen

Move ov2740_remove() below the runtime PM callbacks so that the following patch ("media: i2c: ov2740: power off the sensor on remove") can call them from it without a forward declaration.

No functional change.

---
 drivers/media/i2c/ov2740.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/media/i2c/ov2740.c +11 -11
index 31513d1524a3..ca2ea5d4e0a3 100644
@@ -1199,17 +1199,6 @@ static int ov2740_check_hwcfg(struct ov2740 *ov2740)
 	return ret;
 }
 
-static void ov2740_remove(struct i2c_client *client)
-{
-	struct v4l2_subdev *sd = i2c_get_clientdata(client);
-
-	v4l2_async_unregister_subdev(sd);
-	media_entity_cleanup(&sd->entity);
-	v4l2_subdev_cleanup(sd);
-	v4l2_ctrl_handler_free(sd->ctrl_handler);
-	pm_runtime_disable(&client->dev);
-}
-
 static int ov2740_nvmem_read(void *priv, unsigned int off, void *val,
 			     size_t count)
 {
@@ -1458,6 +1447,17 @@ static int ov2740_probe(struct i2c_client *client)
 	return ret;
 }
 
+static void ov2740_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *sd = i2c_get_clientdata(client);
+
+	v4l2_async_unregister_subdev(sd);
+	media_entity_cleanup(&sd->entity);
+	v4l2_subdev_cleanup(sd);
+	v4l2_ctrl_handler_free(sd->ctrl_handler);
+	pm_runtime_disable(&client->dev);
+}
+
 static DEFINE_RUNTIME_DEV_PM_OPS(ov2740_pm_ops, ov2740_suspend, ov2740_resume,
 				 NULL);
 
Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 4/16 media: i2c: ov2740: power off the sensor on remove

In reply to Cong Nguyen

ov2740_set_stream() takes a runtime PM reference with pm_runtime_resume_and_get() when streaming starts and drops it when streaming stops. ov2740_remove() only calls pm_runtime_disable(), which does not run the runtime suspend callback, so a device that is still runtime active when the driver is unbound can keep its regulators and clock enabled and its reset and powerdown GPIOs released.

The probe error path already calls ov2740_suspend() when the sensor was powered on. After disabling runtime PM in remove(), do the same if the device is not runtime suspended, and set the runtime PM status to suspended. Avoid powering it off again when runtime suspend has already done so.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 866edc895171 ("media: i2c: Add ov2740 image sensor driver")
---
 drivers/media/i2c/ov2740.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/i2c/ov2740.c +4 -0
index ca2ea5d4e0a3..8e495c70b961 100644
@@ -1456,6 +1456,10 @@ static void ov2740_remove(struct i2c_client *client)
 	v4l2_subdev_cleanup(sd);
 	v4l2_ctrl_handler_free(sd->ctrl_handler);
 	pm_runtime_disable(&client->dev);
+	if (!pm_runtime_status_suspended(&client->dev)) {
+		ov2740_suspend(&client->dev);
+		pm_runtime_set_suspended(&client->dev);
+	}
 }
 
 static DEFINE_RUNTIME_DEV_PM_OPS(ov2740_pm_ops, ov2740_suspend, ov2740_resume,
Signature · 1 line
2.25.1
#5 lore raw

PATCH v2 5/16 media: i2c: ak7375: move remove() after the PM callbacks

In reply to Cong Nguyen

Move ak7375_remove() below the runtime PM callbacks so that the following patch ("media: i2c: ak7375: power off the lens driver on remove") can call them from it without a forward declaration.

No functional change.

---
 drivers/media/i2c/ak7375.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/media/i2c/ak7375.c +10 -10
index 1ece5708b4b2..2827fdb29298 100644
@@ -228,16 +228,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,
@@ -334,6 +324,16 @@ static const struct of_device_id ak7375_of_table[] = {
 };
 MODULE_DEVICE_TABLE(of, ak7375_of_table);
 
+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);
+}
+
 static const struct dev_pm_ops ak7375_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(ak7375_vcm_suspend, ak7375_vcm_resume)
 	SET_RUNTIME_PM_OPS(ak7375_vcm_suspend, ak7375_vcm_resume, NULL)
Signature · 1 line
2.25.1
#6 lore raw

PATCH v2 6/16 media: i2c: ak7375: power off the lens driver on remove

In reply to Cong Nguyen

ak7375_open() takes a runtime PM reference with pm_runtime_resume_and_get() and ak7375_close() drops it. ak7375_remove() only calls pm_runtime_disable() and pm_runtime_set_suspended(), which neither run the runtime suspend callback nor release the supplies, so a device that is still runtime active when the driver is unbound, for example because the subdev node is still open, can keep its regulators enabled.

After disabling runtime PM, call ak7375_vcm_suspend() if the device is not already runtime suspended. Do this before ak7375_subdev_cleanup(), because the suspend callback reads the focus control that the cleanup frees.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 90ee26fb2f50 ("media: ak7375: Add ak7375 lens voice coil driver")
---
 drivers/media/i2c/ak7375.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/i2c/ak7375.c +3 -1
index 2827fdb29298..a81cc1df81e7 100644
@@ -329,9 +329,11 @@ 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);
+	ak7375_subdev_cleanup(ak7375_dev);
 }
 
 static const struct dev_pm_ops ak7375_pm_ops = {
Signature · 1 line
2.25.1
#7 lore raw

PATCH v2 7/16 media: i2c: ov13b10: power off the sensor on remove

In reply to Cong Nguyen

ov13b10_set_stream() takes a runtime PM reference with pm_runtime_resume_and_get() when streaming starts and drops it when streaming stops. ov13b10_remove() calls pm_runtime_disable() and pm_runtime_set_suspended() but never ov13b10_power_off(), so a device that is still runtime active when the driver is unbound can keep its clock and regulators enabled.

After disabling runtime PM, call ov13b10_power_off() if the device is not already runtime suspended, and only then set the runtime PM status to suspended. Avoid powering it off again when runtime suspend has already done so.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 7ee850546822 ("media: Add sensor driver support for the ov13b10 camera.")
---
 drivers/media/i2c/ov13b10.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/ov13b10.c +4 -1
index f639a70f60dc..b4d67018c983 100644
@@ -1689,7 +1689,10 @@ static void ov13b10_remove(struct i2c_client *client)
 	ov13b10_free_controls(ov13b);
 
 	pm_runtime_disable(ov13b->dev);
-	pm_runtime_set_suspended(ov13b->dev);
+	if (!pm_runtime_status_suspended(ov13b->dev)) {
+		ov13b10_power_off(ov13b->dev);
+		pm_runtime_set_suspended(ov13b->dev);
+	}
 }
 
 static DEFINE_RUNTIME_DEV_PM_OPS(ov13b10_pm_ops, ov13b10_suspend,
Signature · 1 line
2.25.1
#8 lore raw

PATCH v2 8/16 media: i2c: ov5670: do not power off twice on remove

In reply to Cong Nguyen

ov5670_remove() calls ov5670_runtime_suspend() unconditionally after pm_runtime_disable(). In the usual case the device is already runtime suspended by then, because probe ends with pm_runtime_idle() and the stream has stopped, so the regulators and the clock are disabled a second time. That can trigger the unbalanced disable warnings from the regulator and clock cores.

Only call ov5670_runtime_suspend() if the device is not runtime suspended, and set the runtime PM status to suspended afterwards. This also covers the case where the device is still runtime active, which the unconditional call handled by accident.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 62ab1e325978 ("media: i2c: ov5670: Add runtime_pm operations")
---
 drivers/media/i2c/ov5670.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/ov5670.c +4 -1
index 90352140e5fe..dcf335abcf5b 100644
@@ -2786,7 +2786,10 @@ static void ov5670_remove(struct i2c_client *client)
 	mutex_destroy(&ov5670->mutex);
 
 	pm_runtime_disable(ov5670->dev);
-	ov5670_runtime_suspend(ov5670->dev);
+	if (!pm_runtime_status_suspended(ov5670->dev)) {
+		ov5670_runtime_suspend(ov5670->dev);
+		pm_runtime_set_suspended(ov5670->dev);
+	}
 
 	v4l2_fwnode_endpoint_free(&ov5670->endpoint);
 }
Signature · 1 line
2.25.1
#9 lore raw

PATCH v2 9/16 media: i2c: ov8856: do not power off twice on remove

In reply to Cong Nguyen

ov8856_remove() calls ov8856_power_off() unconditionally after pm_runtime_disable(). In the usual case the device is already runtime suspended by then, because probe ends with pm_runtime_idle() and the stream has stopped, so the regulators and the clock are disabled a second time. That can trigger the unbalanced disable warnings from the regulator and clock cores.

Only call ov8856_power_off() if the device is not runtime suspended, and set the runtime PM status to suspended afterwards. This also covers the case where the device is still runtime active, which the unconditional call handled by accident.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 08304923d317 ("media: ov8856: Add runtime PM callbacks")
---
 drivers/media/i2c/ov8856.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/ov8856.c +4 -1
index 1c879e461fa5..bc17deb945d9 100644
@@ -2367,7 +2367,10 @@ static void ov8856_remove(struct i2c_client *client)
 	pm_runtime_disable(ov8856->dev);
 	mutex_destroy(&ov8856->mutex);
 
-	ov8856_power_off(ov8856->dev);
+	if (!pm_runtime_status_suspended(ov8856->dev)) {
+		ov8856_power_off(ov8856->dev);
+		pm_runtime_set_suspended(ov8856->dev);
+	}
 }
 
 static int ov8856_probe(struct i2c_client *client)
Signature · 1 line
2.25.1
#10 lore raw

PATCH v2 10/16 media: i2c: ov5648: power off the sensor on remove

In reply to Cong Nguyen

ov5648_probe() ends with the device runtime suspended, and ov5648_s_stream() takes a runtime PM reference with pm_runtime_resume_and_get() when streaming starts and drops it when streaming stops. ov5648_remove() only calls pm_runtime_disable(), which does not run the runtime suspend callback, so a device that is still runtime active when the driver is unbound can keep its regulators and clock enabled and its GPIOs released.

After disabling runtime PM, call ov5648_sensor_power(sensor, false) if the device is not runtime suspended, and set the runtime PM status to suspended. Avoid powering it off again when runtime suspend has already done so.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes e43ccb0a045f ("media: i2c: Add support for the OV5648 image sensor")
---
 drivers/media/i2c/ov5648.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/i2c/ov5648.c +4 -0
index bb06e66d28e0..7b817511ab93 100644
@@ -2603,6 +2603,10 @@ static void ov5648_remove(struct i2c_client *client)
 
 	v4l2_async_unregister_subdev(subdev);
 	pm_runtime_disable(sensor->dev);
+	if (!pm_runtime_status_suspended(sensor->dev)) {
+		ov5648_sensor_power(sensor, false);
+		pm_runtime_set_suspended(sensor->dev);
+	}
 	v4l2_ctrl_handler_free(&sensor->ctrls.handler);
 	mutex_destroy(&sensor->mutex);
 	media_entity_cleanup(&subdev->entity);
Signature · 1 line
2.25.1
#11 lore raw

PATCH v2 11/16 media: i2c: ov8865: power off the sensor on remove

In reply to Cong Nguyen

ov8865_probe() ends with the device runtime suspended, and ov8865_s_stream() takes a runtime PM reference with pm_runtime_resume_and_get() when streaming starts and drops it when streaming stops. ov8865_remove() only calls pm_runtime_disable(), which does not run the runtime suspend callback, so a device that is still runtime active when the driver is unbound can keep its regulators and clock enabled and its GPIOs released.

After disabling runtime PM, call ov8865_sensor_power(sensor, false) if the device is not runtime suspended, and set the runtime PM status to suspended. Avoid powering it off again when runtime suspend has already done so.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 11c0d8fdccc5 ("media: i2c: Add support for the OV8865 image sensor")
---
 drivers/media/i2c/ov8865.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/i2c/ov8865.c +4 -0
index c7dc97bf75f6..02948c5888f4 100644
@@ -3118,6 +3118,10 @@ static void ov8865_remove(struct i2c_client *client)
 
 	v4l2_async_unregister_subdev(subdev);
 	pm_runtime_disable(sensor->dev);
+	if (!pm_runtime_status_suspended(sensor->dev)) {
+		ov8865_sensor_power(sensor, false);
+		pm_runtime_set_suspended(sensor->dev);
+	}
 	v4l2_ctrl_handler_free(&sensor->ctrls.handler);
 	mutex_destroy(&sensor->mutex);
 	media_entity_cleanup(&subdev->entity);
Signature · 1 line
2.25.1
#12 lore raw

PATCH v2 12/16 media: i2c: tw9900: power off the decoder on remove

In reply to Cong Nguyen

tw9900_probe() ends with the device runtime suspended, and tw9900_s_stream() takes a runtime PM reference with pm_runtime_resume_and_get() when streaming starts and drops it when streaming stops. tw9900_remove() only calls pm_runtime_disable(), which does not run the runtime suspend callback, so a device that is still runtime active when the driver is unbound can keep its regulator enabled and its reset line released.

After disabling runtime PM, call tw9900_runtime_suspend() if the device is not runtime suspended, and set the runtime PM status to suspended. This has to happen before the mutex is destroyed, as the callback takes it.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 918b14a26b12 ("media: i2c: Introduce a driver for the Techwell TW9900 decoder")
---
 drivers/media/i2c/tw9900.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/i2c/tw9900.c +4 -0
index 51db5d5ddbde..1baf55ea48ef 100644
@@ -744,6 +744,10 @@ static void tw9900_remove(struct i2c_client *client)
 	v4l2_ctrl_handler_free(sd->ctrl_handler);
 
 	pm_runtime_disable(&client->dev);
+	if (!pm_runtime_status_suspended(&client->dev)) {
+		tw9900_runtime_suspend(&client->dev);
+		pm_runtime_set_suspended(&client->dev);
+	}
 
 	mutex_destroy(&tw9900->mutex);
 }
Signature · 1 line
2.25.1
#13 lore raw

PATCH v2 13/16 media: i2c: isl7998x: move remove() after the PM callbacks

In reply to Cong Nguyen

Move isl7998x_remove() below the runtime PM callbacks so that the following patch ("media: i2c: isl7998x: power down the decoder on remove") can call them from it without a forward declaration.

No functional change.

---
 drivers/media/i2c/isl7998x.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/media/i2c/isl7998x.c +10 -10
index e36fb355133e..42387bd310fb 100644
@@ -1544,16 +1544,6 @@ static int isl7998x_probe(struct i2c_client *client)
 	return ret;
 }
 
-static void isl7998x_remove(struct i2c_client *client)
-{
-	struct isl7998x *isl7998x = i2c_to_isl7998x(client);
-
-	pm_runtime_disable(&client->dev);
-	v4l2_async_unregister_subdev(&isl7998x->subdev);
-	isl7998x_remove_controls(isl7998x);
-	media_entity_cleanup(&isl7998x->subdev.entity);
-}
-
 static const struct of_device_id isl7998x_of_match[] = {
 	{ .compatible = "isil,isl79987", },
 	{ /* sentinel */ },
@@ -1602,6 +1592,16 @@ static int __maybe_unused isl7998x_runtime_suspend(struct device *dev)
 	return 0;
 }
 
+static void isl7998x_remove(struct i2c_client *client)
+{
+	struct isl7998x *isl7998x = i2c_to_isl7998x(client);
+
+	pm_runtime_disable(&client->dev);
+	v4l2_async_unregister_subdev(&isl7998x->subdev);
+	isl7998x_remove_controls(isl7998x);
+	media_entity_cleanup(&isl7998x->subdev.entity);
+}
+
 static const struct dev_pm_ops isl7998x_pm_ops = {
 	SET_RUNTIME_PM_OPS(isl7998x_runtime_suspend,
 			   isl7998x_runtime_resume,
Signature · 1 line
2.25.1
#14 lore raw

PATCH v2 14/16 media: i2c: isl7998x: power down the decoder on remove

In reply to Cong Nguyen

isl7998x_pre_streamon() takes a runtime PM reference with pm_runtime_resume_and_get(), which isl7998x_post_streamoff() drops. isl7998x_remove() only calls pm_runtime_disable(), which does not run the runtime suspend callback, so a device that is still runtime active when the driver is unbound can be left with its power-down GPIO deasserted.

After disabling runtime PM, call isl7998x_runtime_suspend() if the device is not runtime suspended, and set the runtime PM status to suspended.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 51ef2be546e2 ("media: i2c: isl7998x: Add driver for Intersil ISL7998x")
---
 drivers/media/i2c/isl7998x.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/i2c/isl7998x.c +4 -0
index 42387bd310fb..48fb131c9e45 100644
@@ -1597,6 +1597,10 @@ static void isl7998x_remove(struct i2c_client *client)
 	struct isl7998x *isl7998x = i2c_to_isl7998x(client);
 
 	pm_runtime_disable(&client->dev);
+	if (!pm_runtime_status_suspended(&client->dev)) {
+		isl7998x_runtime_suspend(&client->dev);
+		pm_runtime_set_suspended(&client->dev);
+	}
 	v4l2_async_unregister_subdev(&isl7998x->subdev);
 	isl7998x_remove_controls(isl7998x);
 	media_entity_cleanup(&isl7998x->subdev.entity);
Signature · 1 line
2.25.1
#15 lore raw

PATCH v2 15/16 media: i2c: tc358746: move remove() after the PM callbacks

In reply to Cong Nguyen

Move tc358746_remove() below the runtime PM callbacks so that the following patch ("media: i2c: tc358746: power off the bridge on remove") can call them from it without a forward declaration.

No functional change.

---
 drivers/media/i2c/tc358746.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/media/i2c/tc358746.c +18 -18
index 91d26a634023..88ff4a90eebc 100644
@@ -1607,24 +1607,6 @@ static int tc358746_probe(struct i2c_client *client)
 	return err;
 }
 
-static void tc358746_remove(struct i2c_client *client)
-{
-	struct v4l2_subdev *sd = i2c_get_clientdata(client);
-	struct tc358746 *tc358746 = to_tc358746(sd);
-
-	v4l2_subdev_cleanup(sd);
-	v4l2_ctrl_handler_free(&tc358746->ctrl_hdl);
-	v4l2_fwnode_endpoint_free(&tc358746->csi_vep);
-	v4l2_async_nf_unregister(&tc358746->notifier);
-	v4l2_async_nf_cleanup(&tc358746->notifier);
-	v4l2_async_unregister_subdev(sd);
-	media_entity_cleanup(&sd->entity);
-
-	pm_runtime_disable(sd->dev);
-	pm_runtime_set_suspended(sd->dev);
-	pm_runtime_dont_use_autosuspend(sd->dev);
-}
-
 /*
  * This function has been created just to avoid a smatch warning,
  * please do not merge it into tc358746_suspend until you have
@@ -1692,6 +1674,24 @@ static int tc358746_resume(struct device *dev)
 	return err;
 }
 
+static void tc358746_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *sd = i2c_get_clientdata(client);
+	struct tc358746 *tc358746 = to_tc358746(sd);
+
+	v4l2_subdev_cleanup(sd);
+	v4l2_ctrl_handler_free(&tc358746->ctrl_hdl);
+	v4l2_fwnode_endpoint_free(&tc358746->csi_vep);
+	v4l2_async_nf_unregister(&tc358746->notifier);
+	v4l2_async_nf_cleanup(&tc358746->notifier);
+	v4l2_async_unregister_subdev(sd);
+	media_entity_cleanup(&sd->entity);
+
+	pm_runtime_disable(sd->dev);
+	pm_runtime_set_suspended(sd->dev);
+	pm_runtime_dont_use_autosuspend(sd->dev);
+}
+
 static DEFINE_RUNTIME_DEV_PM_OPS(tc358746_pm_ops, tc358746_suspend,
 				 tc358746_resume, NULL);
 
Signature · 1 line
2.25.1
#16 lore raw

PATCH v2 16/16 media: i2c: tc358746: power off the bridge on remove

In reply to Cong Nguyen

The driver uses runtime PM autosuspend with a one second delay and drops its references with pm_runtime_put_sync_autosuspend(), so after the last use the device stays runtime active until the delay expires. tc358746_remove() only calls pm_runtime_disable() and pm_runtime_set_suspended(), which neither run the runtime suspend callback nor release the supplies and the reference clock. Unbinding within that delay, or while streaming, can leave them enabled.

After disabling runtime PM, call tc358746_suspend() if the device is not runtime suspended, and only then set the runtime PM status to suspended.

This issue was found by auditing the driver with an LLM coding assistant.

Fixes 80a21da36051 ("media: tc358746: add Toshiba TC358746 Parallel to CSI-2 bridge driver")
---
 drivers/media/i2c/tc358746.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/tc358746.c +4 -1
index 88ff4a90eebc..68f483534e0f 100644
@@ -1688,7 +1688,10 @@ static void tc358746_remove(struct i2c_client *client)
 	media_entity_cleanup(&sd->entity);
 
 	pm_runtime_disable(sd->dev);
-	pm_runtime_set_suspended(sd->dev);
+	if (!pm_runtime_status_suspended(sd->dev)) {
+		tc358746_suspend(sd->dev);
+		pm_runtime_set_suspended(sd->dev);
+	}
 	pm_runtime_dont_use_autosuspend(sd->dev);
 }
 
Signature · 1 line
2.25.1