[PATCH] s5p-csis: Check return value of clk_enable/clk_set_rate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



clk_set_rate(), clk_enable() functions can fail, so check the return
values to avoid surprises. While at it fix the error path and use
ERR_PTR() value to indicate invalid clock.

Signed-off-by: Sylwester Nawrocki <s.nawrocki@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
---
 drivers/media/platform/s5p-fimc/mipi-csis.c |   29 ++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/media/platform/s5p-fimc/mipi-csis.c b/drivers/media/platform/s5p-fimc/mipi-csis.c
index c25dbc4..b9eea8e 100644
--- a/drivers/media/platform/s5p-fimc/mipi-csis.c
+++ b/drivers/media/platform/s5p-fimc/mipi-csis.c
@@ -365,11 +365,11 @@ static void s5pcsis_clk_put(struct csis_state *state)
 	int i;

 	for (i = 0; i < NUM_CSIS_CLOCKS; i++) {
-		if (IS_ERR_OR_NULL(state->clock[i]))
+		if (IS_ERR(state->clock[i]))
 			continue;
 		clk_unprepare(state->clock[i]);
 		clk_put(state->clock[i]);
-		state->clock[i] = NULL;
+		state->clock[i] = ERR_PTR(-EINVAL);
 	}
 }

@@ -378,14 +378,19 @@ static int s5pcsis_clk_get(struct csis_state *state)
 	struct device *dev = &state->pdev->dev;
 	int i, ret;

+	for (i = 0; i < NUM_CSIS_CLOCKS; i++)
+		state->clock[i] = ERR_PTR(-EINVAL);
+
 	for (i = 0; i < NUM_CSIS_CLOCKS; i++) {
 		state->clock[i] = clk_get(dev, csi_clock_name[i]);
-		if (IS_ERR(state->clock[i]))
+		if (IS_ERR(state->clock[i])) {
+			ret = PTR_ERR(state->clock[i]);
 			goto err;
+		}
 		ret = clk_prepare(state->clock[i]);
 		if (ret < 0) {
 			clk_put(state->clock[i]);
-			state->clock[i] = NULL;
+			state->clock[i] = ERR_PTR(-EINVAL);
 			goto err;
 		}
 	}
@@ -393,7 +398,7 @@ static int s5pcsis_clk_get(struct csis_state *state)
 err:
 	s5pcsis_clk_put(state);
 	dev_err(dev, "failed to get clock: %s\n", csi_clock_name[i]);
-	return -ENXIO;
+	return ret;
 }

 static void dump_regs(struct csis_state *state, const char *label)
@@ -825,19 +830,25 @@ static int __devinit s5pcsis_probe(struct platform_device *pdev)

 	ret = s5pcsis_clk_get(state);
 	if (ret)
-		goto e_clkput;
+		goto e_regput;

-	clk_enable(state->clock[CSIS_CLK_MUX]);
 	if (state->clk_frequency)
-		clk_set_rate(state->clock[CSIS_CLK_MUX], state->clk_frequency);
+		ret = clk_set_rate(state->clock[CSIS_CLK_MUX],
+				   state->clk_frequency);
 	else
 		dev_WARN(dev, "No clock frequency specified!\n");
+	if (ret < 0)
+		goto e_clkput;
+
+	ret = clk_enable(state->clock[CSIS_CLK_MUX]);
+	if (ret < 0)
+		goto e_clkput;

 	ret = devm_request_irq(dev, state->irq, s5pcsis_irq_handler,
 			       0, dev_name(dev), state);
 	if (ret) {
 		dev_err(dev, "Interrupt request failed\n");
-		goto e_regput;
+		goto e_clkput;
 	}

 	v4l2_subdev_init(&state->sd, &s5pcsis_subdev_ops);
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux