* [PATCH] media: ov7740: fix runtime pm initialization
@ 2019-02-17 15:17 Akinobu Mita
2019-02-18 8:21 ` Eugen.Hristev
0 siblings, 1 reply; 2+ messages in thread
From: Akinobu Mita @ 2019-02-17 15:17 UTC (permalink / raw)
To: linux-media
Cc: Akinobu Mita, Eugen Hristev, Wenyou Yang, Sakari Ailus,
Mauro Carvalho Chehab
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: Eugen Hristev <eugen.hristev@microchip.com>
Cc: Wenyou Yang <wenyou.yang@microchip.com>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
I don't have the ov7740 device, but I saw the same problem with the
mt9m001 device when I was adding the runtime PM support for it.
Eugen Hristev reported the problem with ov7740.
https://www.mail-archive.com/linux-media@vger.kernel.org/msg144540.html
I suspect that it is related to this runtime PM problem.
There seems to be the same problem in other devices. I would like to see
if this patch actually fix the ov7740's problem and then propagate other
devices.
drivers/media/i2c/ov7740.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
index 177688a..8835b83 100644
--- a/drivers/media/i2c/ov7740.c
+++ b/drivers/media/i2c/ov7740.c
@@ -1101,6 +1101,9 @@ static int ov7740_probe(struct i2c_client *client,
if (ret)
return ret;
+ pm_runtime_set_active(&client->dev);
+ pm_runtime_enable(&client->dev);
+
ret = ov7740_detect(ov7740);
if (ret)
goto error_detect;
@@ -1123,8 +1126,6 @@ static int ov7740_probe(struct i2c_client *client,
if (ret)
goto error_async_register;
- pm_runtime_set_active(&client->dev);
- pm_runtime_enable(&client->dev);
pm_runtime_idle(&client->dev);
return 0;
@@ -1134,6 +1135,8 @@ static int ov7740_probe(struct i2c_client *client,
error_init_controls:
ov7740_free_controls(ov7740);
error_detect:
+ pm_runtime_disable(&client->dev);
+ pm_runtime_set_suspended(&client->dev);
ov7740_set_power(ov7740, 0);
media_entity_cleanup(&ov7740->subdev.entity);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] media: ov7740: fix runtime pm initialization
2019-02-17 15:17 [PATCH] media: ov7740: fix runtime pm initialization Akinobu Mita
@ 2019-02-18 8:21 ` Eugen.Hristev
0 siblings, 0 replies; 2+ messages in thread
From: Eugen.Hristev @ 2019-02-18 8:21 UTC (permalink / raw)
To: akinobu.mita, linux-media; +Cc: wenyou.yang, sakari.ailus, mchehab
On 17.02.2019 17:17, Akinobu Mita wrote:
> 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: Eugen Hristev <eugen.hristev@microchip.com>
> Cc: Wenyou Yang <wenyou.yang@microchip.com>
> Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> ---
> I don't have the ov7740 device, but I saw the same problem with the
> mt9m001 device when I was adding the runtime PM support for it.
>
> Eugen Hristev reported the problem with ov7740.
Hi,
This fixes my issue with this sensor in latest mediatree
For anything's worth, for Atmel ISC + ov7740, with my patch,
Tested-by: Eugen Hristev <eugen.hristev@microchip.com>
Thanks
>
> https://www.mail-archive.com/linux-media@vger.kernel.org/msg144540.html
>
> I suspect that it is related to this runtime PM problem.
>
> There seems to be the same problem in other devices. I would like to see
> if this patch actually fix the ov7740's problem and then propagate other
> devices.
>
> drivers/media/i2c/ov7740.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
> index 177688a..8835b83 100644
> --- a/drivers/media/i2c/ov7740.c
> +++ b/drivers/media/i2c/ov7740.c
> @@ -1101,6 +1101,9 @@ static int ov7740_probe(struct i2c_client *client,
> if (ret)
> return ret;
>
> + pm_runtime_set_active(&client->dev);
> + pm_runtime_enable(&client->dev);
> +
> ret = ov7740_detect(ov7740);
> if (ret)
> goto error_detect;
> @@ -1123,8 +1126,6 @@ static int ov7740_probe(struct i2c_client *client,
> if (ret)
> goto error_async_register;
>
> - pm_runtime_set_active(&client->dev);
> - pm_runtime_enable(&client->dev);
> pm_runtime_idle(&client->dev);
>
> return 0;
> @@ -1134,6 +1135,8 @@ static int ov7740_probe(struct i2c_client *client,
> error_init_controls:
> ov7740_free_controls(ov7740);
> error_detect:
> + pm_runtime_disable(&client->dev);
> + pm_runtime_set_suspended(&client->dev);
> ov7740_set_power(ov7740, 0);
> media_entity_cleanup(&ov7740->subdev.entity);
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-02-18 8:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-17 15:17 [PATCH] media: ov7740: fix runtime pm initialization Akinobu Mita
2019-02-18 8:21 ` Eugen.Hristev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).