[PATCH] media: cdns-csi2rx: fix call balance for csi2rx->p_clk handling routines

From: Vitalii Mordan
Date: Mon Jan 13 2025 - 05:18:18 EST


If the clock csi2rx->p_clk was not enabled in csi2rx_stop(), it should not
be disabled in any path.

Conversely, if it was enabled in csi2rx_stop(), it must be disabled in all
error paths to ensure proper cleanup.

Found by Linux Verification Center (linuxtesting.org) with Klever.

Fixes: 1fc3b37f34f6 ("media: v4l: cadence: Add Cadence MIPI-CSI2 RX driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Vitalii Mordan <mordan@xxxxxxxxx>
---
drivers/media/platform/cadence/cdns-csi2rx.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index 4d64df829e75..e7e8decf9a02 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -322,11 +322,14 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)

static void csi2rx_stop(struct csi2rx_priv *csi2rx)
{
+ int ret, ret_clk;
unsigned int i;
u32 val;
- int ret;

- clk_prepare_enable(csi2rx->p_clk);
+ ret_clk = clk_prepare_enable(csi2rx->p_clk);
+ if (ret_clk)
+ dev_warn(csi2rx->dev,
+ "Couldn't prepare and enable P clock\n");
reset_control_assert(csi2rx->sys_rst);
clk_disable_unprepare(csi2rx->sys_clk);

@@ -348,7 +351,8 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx)
}

reset_control_assert(csi2rx->p_rst);
- clk_disable_unprepare(csi2rx->p_clk);
+ if (!ret_clk)
+ clk_disable_unprepare(csi2rx->p_clk);

if (v4l2_subdev_call(csi2rx->source_subdev, video, s_stream, false))
dev_warn(csi2rx->dev, "Couldn't disable our subdev\n");
--
2.25.1