Re: [PATCH 2/2] media: i2c: ov7740: Fix unchecked pm_runtime_get_sync() in remove()

From: Sakari Ailus

Date: Wed Jul 08 2026 - 04:50:48 EST


Hi Biren,

On Tue, Jun 16, 2026 at 02:34:12AM +0530, Biren Pandya wrote:
> The ov7740_remove() function unconditionally called pm_runtime_get_sync()
> but completely ignored the return value. If the device was already in an
> error state or disconnected, this could lead to an unbalanced PM runtime
> usage count or attempt to communicate with an unresponsive device.
>
> Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() to ensure
> the device actually resumed before attempting to issue I2C power-off
> commands, and safely put the PM runtime usage counter.
>
> Signed-off-by: Biren Pandya <birenpandya@xxxxxxxxx>
> ---
> drivers/media/i2c/ov7740.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
> index 62c124a1353a..6b81882da307 100644
> --- a/drivers/media/i2c/ov7740.c
> +++ b/drivers/media/i2c/ov7740.c
> @@ -1115,17 +1115,20 @@ static void ov7740_remove(struct i2c_client *client)
> {
> struct v4l2_subdev *sd = i2c_get_clientdata(client);
> struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev);
> + int ret;
>
> v4l2_async_unregister_subdev(sd);
> media_entity_cleanup(&ov7740->subdev.entity);
> ov7740_free_controls(ov7740);
>
> - pm_runtime_get_sync(&client->dev);
> + ret = pm_runtime_resume_and_get(&client->dev);
> pm_runtime_disable(&client->dev);
> pm_runtime_set_suspended(&client->dev);
> - pm_runtime_put_noidle(&client->dev);
>
> - ov7740_set_power(ov7740, 0);
> + if (ret >= 0) {
> + ov7740_set_power(ov7740, 0);
> + pm_runtime_put_noidle(&client->dev);
> + }

Could you do what's done in other drivers, i.e. disable Runtime PM and then
see if the device is active and if so, power it off?

--
Regards,

Sakari Ailus