Commit 12aceee1 authored by Akinobu Mita's avatar Akinobu Mita Committed by Mauro Carvalho Chehab

media: ov7740: fix runtime pm initialization

The runtime PM of this device is enabled after v4l2_ctrl_handler_setup(),
and this makes this device's runtime PM usage count a negative value.

The ov7740_set_ctrl() tries to do something only if the device's runtime
PM usage counter is nonzero.

ov7740_set_ctrl()
{
	if (!pm_runtime_get_if_in_use(&client->dev))
		return 0;

	<do something>;

	pm_runtime_put(&client->dev);

	return ret;
}

However, the ov7740_set_ctrl() is called by v4l2_ctrl_handler_setup()
while the runtime PM of this device is not yet enabled.  In this case,
the pm_runtime_get_if_in_use() returns -EINVAL (!= 0).

Therefore we can't bail out of this function and the usage count is
decreased by pm_runtime_put() without increment.

This fixes this problem by enabling the runtime PM of this device before
v4l2_ctrl_handler_setup() so that the ov7740_set_ctrl() is always called
when the runtime PM is enabled.

Cc: Wenyou Yang <wenyou.yang@microchip.com>
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Tested-by: default avatarEugen Hristev <eugen.hristev@microchip.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 75e3e5b8
...@@ -1101,6 +1101,9 @@ static int ov7740_probe(struct i2c_client *client, ...@@ -1101,6 +1101,9 @@ static int ov7740_probe(struct i2c_client *client,
if (ret) if (ret)
return ret; return ret;
pm_runtime_set_active(&client->dev);
pm_runtime_enable(&client->dev);
ret = ov7740_detect(ov7740); ret = ov7740_detect(ov7740);
if (ret) if (ret)
goto error_detect; goto error_detect;
...@@ -1123,8 +1126,6 @@ static int ov7740_probe(struct i2c_client *client, ...@@ -1123,8 +1126,6 @@ static int ov7740_probe(struct i2c_client *client,
if (ret) if (ret)
goto error_async_register; goto error_async_register;
pm_runtime_set_active(&client->dev);
pm_runtime_enable(&client->dev);
pm_runtime_idle(&client->dev); pm_runtime_idle(&client->dev);
return 0; return 0;
...@@ -1134,6 +1135,8 @@ static int ov7740_probe(struct i2c_client *client, ...@@ -1134,6 +1135,8 @@ static int ov7740_probe(struct i2c_client *client,
error_init_controls: error_init_controls:
ov7740_free_controls(ov7740); ov7740_free_controls(ov7740);
error_detect: error_detect:
pm_runtime_disable(&client->dev);
pm_runtime_set_suspended(&client->dev);
ov7740_set_power(ov7740, 0); ov7740_set_power(ov7740, 0);
media_entity_cleanup(&ov7740->subdev.entity); media_entity_cleanup(&ov7740->subdev.entity);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment