media: i2c: power off the device in remove()
Subsystems (11)
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
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
@@ -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
PATCH v2 2/16 media: i2c: hi556: power off the sensor on remove
In reply to Cong Nguyenhi556_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.
--- drivers/media/i2c/hi556.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/hi556.c +4 -0
@@ -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
PATCH v2 3/16 media: i2c: ov2740: move remove() after the PM callbacks
In reply to Cong NguyenMove 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
@@ -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
PATCH v2 4/16 media: i2c: ov2740: power off the sensor on remove
In reply to Cong Nguyenov2740_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.
--- drivers/media/i2c/ov2740.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/ov2740.c +4 -0
@@ -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
PATCH v2 5/16 media: i2c: ak7375: move remove() after the PM callbacks
In reply to Cong NguyenMove 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
@@ -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
PATCH v2 6/16 media: i2c: ak7375: power off the lens driver on remove
In reply to Cong Nguyenak7375_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.
--- drivers/media/i2c/ak7375.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/i2c/ak7375.c +3 -1
@@ -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
PATCH v2 7/16 media: i2c: ov13b10: power off the sensor on remove
In reply to Cong Nguyenov13b10_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.
--- drivers/media/i2c/ov13b10.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/ov13b10.c +4 -1
@@ -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
PATCH v2 8/16 media: i2c: ov5670: do not power off twice on remove
In reply to Cong Nguyenov5670_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.
--- drivers/media/i2c/ov5670.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/ov5670.c +4 -1
@@ -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
PATCH v2 9/16 media: i2c: ov8856: do not power off twice on remove
In reply to Cong Nguyenov8856_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.
--- drivers/media/i2c/ov8856.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/ov8856.c +4 -1
@@ -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
PATCH v2 10/16 media: i2c: ov5648: power off the sensor on remove
In reply to Cong Nguyenov5648_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.
--- drivers/media/i2c/ov5648.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/ov5648.c +4 -0
@@ -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
PATCH v2 11/16 media: i2c: ov8865: power off the sensor on remove
In reply to Cong Nguyenov8865_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.
--- drivers/media/i2c/ov8865.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/ov8865.c +4 -0
@@ -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
PATCH v2 12/16 media: i2c: tw9900: power off the decoder on remove
In reply to Cong Nguyentw9900_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.
--- drivers/media/i2c/tw9900.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/tw9900.c +4 -0
@@ -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
PATCH v2 13/16 media: i2c: isl7998x: move remove() after the PM callbacks
In reply to Cong NguyenMove 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
@@ -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
PATCH v2 14/16 media: i2c: isl7998x: power down the decoder on remove
In reply to Cong Nguyenisl7998x_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.
--- drivers/media/i2c/isl7998x.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/i2c/isl7998x.c +4 -0
@@ -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
PATCH v2 15/16 media: i2c: tc358746: move remove() after the PM callbacks
In reply to Cong NguyenMove 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
@@ -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
PATCH v2 16/16 media: i2c: tc358746: power off the bridge on remove
In reply to Cong NguyenThe 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.
--- drivers/media/i2c/tc358746.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/i2c/tc358746.c +4 -1
@@ -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