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

From: Cong Nguyen

Date: Mon Nov 23 2026 - 10:40:32 EST


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")
Signed-off-by: Cong Nguyen <congnt264@xxxxxxxxx>
---
drivers/media/i2c/ov8865.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/media/i2c/ov8865.c b/drivers/media/i2c/ov8865.c
index c7dc97bf75f6..02948c5888f4 100644
--- a/drivers/media/i2c/ov8865.c
+++ b/drivers/media/i2c/ov8865.c
@@ -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);
--
2.25.1