Skip to content

Commit 65e08c4

Browse files
committed
media: bcm2835-unicam: Return early from stop_streaming() if stopped
clk_disable_unprepare() is called unconditionally in stop_streaming(). This is incorrect in the cases where start_streaming() fails, and unprepares all clocks as part of the failure cleanup. To avoid this, ensure that clk_disable_unprepare() is only called in stop_streaming() if the clocks are in a prepared state. Signed-off-by: Naushir Patuck <[email protected]>
1 parent 92d8835 commit 65e08c4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/media/platform/bcm2835/bcm2835-unicam.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ struct unicam_device {
426426
struct clk *clock;
427427
/* vpu clock handle */
428428
struct clk *vpu_clock;
429+
/* clock status for error handling */
430+
bool clocks_enabled;
429431
/* V4l2 device */
430432
struct v4l2_device v4l2_dev;
431433
struct media_device mdev;
@@ -1724,6 +1726,7 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
17241726
goto err_disable_unicam;
17251727
}
17261728

1729+
dev->clocks_enabled = true;
17271730
return 0;
17281731

17291732
err_disable_unicam:
@@ -1750,8 +1753,6 @@ static void unicam_stop_streaming(struct vb2_queue *vq)
17501753
node->streaming = false;
17511754

17521755
if (node->pad_id == IMAGE_PAD) {
1753-
int ret;
1754-
17551756
/*
17561757
* Stop streaming the sensor and disable the peripheral.
17571758
* We cannot continue streaming embedded data with the
@@ -1762,12 +1763,13 @@ static void unicam_stop_streaming(struct vb2_queue *vq)
17621763

17631764
unicam_disable(dev);
17641765

1765-
ret = clk_set_min_rate(dev->vpu_clock, 0);
1766-
if (ret)
1767-
unicam_err(dev, "failed to reset the min VPU clock\n");
1766+
if (dev->clocks_enabled) {
1767+
if (clk_set_min_rate(dev->vpu_clock, 0))
1768+
unicam_err(dev, "failed to reset the min VPU clock\n");
17681769

1769-
clk_disable_unprepare(dev->vpu_clock);
1770-
clk_disable_unprepare(dev->clock);
1770+
clk_disable_unprepare(dev->vpu_clock);
1771+
clk_disable_unprepare(dev->clock);
1772+
}
17711773
unicam_runtime_put(dev);
17721774

17731775
} else if (node->pad_id == METADATA_PAD) {

0 commit comments

Comments
 (0)