]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.34/media-ov7740-fix-runtime-pm-initialization.patch
Linux 4.19.34
[thirdparty/kernel/stable-queue.git] / releases / 4.19.34 / media-ov7740-fix-runtime-pm-initialization.patch
1 From ca6cf64a68b93bef63167ef8692efedcc1d6769c Mon Sep 17 00:00:00 2001
2 From: Akinobu Mita <akinobu.mita@gmail.com>
3 Date: Sun, 17 Feb 2019 10:17:47 -0500
4 Subject: media: ov7740: fix runtime pm initialization
5
6 [ Upstream commit 12aceee1f412c3ddc7750155fec06c906f14ab51 ]
7
8 The runtime PM of this device is enabled after v4l2_ctrl_handler_setup(),
9 and this makes this device's runtime PM usage count a negative value.
10
11 The ov7740_set_ctrl() tries to do something only if the device's runtime
12 PM usage counter is nonzero.
13
14 ov7740_set_ctrl()
15 {
16 if (!pm_runtime_get_if_in_use(&client->dev))
17 return 0;
18
19 <do something>;
20
21 pm_runtime_put(&client->dev);
22
23 return ret;
24 }
25
26 However, the ov7740_set_ctrl() is called by v4l2_ctrl_handler_setup()
27 while the runtime PM of this device is not yet enabled. In this case,
28 the pm_runtime_get_if_in_use() returns -EINVAL (!= 0).
29
30 Therefore we can't bail out of this function and the usage count is
31 decreased by pm_runtime_put() without increment.
32
33 This fixes this problem by enabling the runtime PM of this device before
34 v4l2_ctrl_handler_setup() so that the ov7740_set_ctrl() is always called
35 when the runtime PM is enabled.
36
37 Cc: Wenyou Yang <wenyou.yang@microchip.com>
38 Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
39 Tested-by: Eugen Hristev <eugen.hristev@microchip.com>
40 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
41 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
42 Signed-off-by: Sasha Levin <sashal@kernel.org>
43 ---
44 drivers/media/i2c/ov7740.c | 7 +++++--
45 1 file changed, 5 insertions(+), 2 deletions(-)
46
47 diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
48 index 605f3e25ad82..f5a1ee90a6c5 100644
49 --- a/drivers/media/i2c/ov7740.c
50 +++ b/drivers/media/i2c/ov7740.c
51 @@ -1101,6 +1101,9 @@ static int ov7740_probe(struct i2c_client *client,
52 if (ret)
53 return ret;
54
55 + pm_runtime_set_active(&client->dev);
56 + pm_runtime_enable(&client->dev);
57 +
58 ret = ov7740_detect(ov7740);
59 if (ret)
60 goto error_detect;
61 @@ -1123,8 +1126,6 @@ static int ov7740_probe(struct i2c_client *client,
62 if (ret)
63 goto error_async_register;
64
65 - pm_runtime_set_active(&client->dev);
66 - pm_runtime_enable(&client->dev);
67 pm_runtime_idle(&client->dev);
68
69 return 0;
70 @@ -1134,6 +1135,8 @@ error_async_register:
71 error_init_controls:
72 ov7740_free_controls(ov7740);
73 error_detect:
74 + pm_runtime_disable(&client->dev);
75 + pm_runtime_set_suspended(&client->dev);
76 ov7740_set_power(ov7740, 0);
77 media_entity_cleanup(&ov7740->subdev.entity);
78
79 --
80 2.19.1
81