d61fac705feceed658b48ad3de5aefaded86e35f
[openwrt/staging/stintel.git] /
1 From a95a3e417cf425d03b3a62c1b34730cfcb21b197 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Wed, 2 Dec 2020 15:26:09 +0000
4 Subject: [PATCH] media: bcm2835-unicam: Return early from
5 stop_streaming() if stopped
6
7 clk_disable_unprepare() is called unconditionally in stop_streaming().
8 This is incorrect in the cases where start_streaming() fails, and
9 unprepares all clocks as part of the failure cleanup. To avoid this,
10 ensure that clk_disable_unprepare() is only called in stop_streaming()
11 if the clocks are in a prepared state.
12
13 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
14 ---
15 drivers/media/platform/bcm2835/bcm2835-unicam.c | 16 +++++++++-------
16 1 file changed, 9 insertions(+), 7 deletions(-)
17
18 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
19 +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
20 @@ -426,6 +426,8 @@ struct unicam_device {
21 struct clk *clock;
22 /* vpu clock handle */
23 struct clk *vpu_clock;
24 + /* clock status for error handling */
25 + bool clocks_enabled;
26 /* V4l2 device */
27 struct v4l2_device v4l2_dev;
28 struct media_device mdev;
29 @@ -1724,6 +1726,7 @@ static int unicam_start_streaming(struct
30 goto err_disable_unicam;
31 }
32
33 + dev->clocks_enabled = true;
34 return 0;
35
36 err_disable_unicam:
37 @@ -1750,8 +1753,6 @@ static void unicam_stop_streaming(struct
38 node->streaming = false;
39
40 if (node->pad_id == IMAGE_PAD) {
41 - int ret;
42 -
43 /*
44 * Stop streaming the sensor and disable the peripheral.
45 * We cannot continue streaming embedded data with the
46 @@ -1762,12 +1763,13 @@ static void unicam_stop_streaming(struct
47
48 unicam_disable(dev);
49
50 - ret = clk_set_min_rate(dev->vpu_clock, 0);
51 - if (ret)
52 - unicam_err(dev, "failed to reset the min VPU clock\n");
53 + if (dev->clocks_enabled) {
54 + if (clk_set_min_rate(dev->vpu_clock, 0))
55 + unicam_err(dev, "failed to reset the min VPU clock\n");
56
57 - clk_disable_unprepare(dev->vpu_clock);
58 - clk_disable_unprepare(dev->clock);
59 + clk_disable_unprepare(dev->vpu_clock);
60 + clk_disable_unprepare(dev->clock);
61 + }
62 unicam_runtime_put(dev);
63
64 } else if (node->pad_id == METADATA_PAD) {