From c072ad9dbe8af9de6f322e16f090e577bc983e1e Mon Sep 17 00:00:00 2001 From: Naushir Patuck Date: Wed, 2 Dec 2020 14:16:26 +0000 Subject: [PATCH] media: bcm2835-unicam: Correctly handle error states on stream on/off On a failure in start_streaming(), the error code would not propagate to the calling function on all conditions. This would cause the userland caller to not know of the failure. Additionally, clk_disable_unprepare() was 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. Ensure that clk_disable_unprepare() is only called in stop_streaming() if the clocks are in a prepared state. Signed-off-by: Naushir Patuck --- .../media/platform/bcm2835/bcm2835-unicam.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/bcm2835/bcm2835-unicam.c b/drivers/media/platform/bcm2835/bcm2835-unicam.c index 6501fb205e205f..1527b2ba30c24d 100644 --- a/drivers/media/platform/bcm2835/bcm2835-unicam.c +++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c @@ -426,6 +426,8 @@ struct unicam_device { struct clk *clock; /* vpu clock handle */ struct clk *vpu_clock; + /* Clock status */ + bool clocks_enabled; /* V4l2 device */ struct v4l2_device v4l2_dev; struct media_device mdev; @@ -1724,14 +1726,14 @@ static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count) goto err_disable_unicam; } + dev->clocks_enabled = true; return 0; err_disable_unicam: unicam_disable(dev); clk_disable_unprepare(dev->clock); err_vpu_clock: - ret = clk_set_min_rate(dev->vpu_clock, 0); - if (ret) + if (clk_set_min_rate(dev->vpu_clock, 0)) unicam_err(dev, "failed to reset the VPU clock\n"); clk_disable_unprepare(dev->vpu_clock); err_pm_put: @@ -1763,12 +1765,15 @@ static void unicam_stop_streaming(struct vb2_queue *vq) unicam_disable(dev); - ret = clk_set_min_rate(dev->vpu_clock, 0); - if (ret) - unicam_err(dev, "failed to reset the min VPU clock\n"); + if (dev->clocks_enabled) { + ret = clk_set_min_rate(dev->vpu_clock, 0); + if (ret) + unicam_err(dev, "failed to reset the min VPU clock\n"); - clk_disable_unprepare(dev->vpu_clock); - clk_disable_unprepare(dev->clock); + clk_disable_unprepare(dev->vpu_clock); + clk_disable_unprepare(dev->clock); + dev->clocks_enabled = false; + } unicam_runtime_put(dev); } else if (node->pad_id == METADATA_PAD) {