diff mbox

[media] tc358743: validate lane count and order

Message ID 20170921153139.16657-1-p.zabel@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Philipp Zabel Sept. 21, 2017, 3:31 p.m. UTC
The TC358743 does not support reordering lanes, or more than 4 data
lanes.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/i2c/tc358743.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Sakari Ailus Sept. 22, 2017, 7:04 a.m. UTC | #1
Hi Philipp,

On Thu, Sep 21, 2017 at 05:31:39PM +0200, Philipp Zabel wrote:
> The TC358743 does not support reordering lanes, or more than 4 data
> lanes.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/media/i2c/tc358743.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
> index a35043cefe128..b7285e45b908a 100644
> --- a/drivers/media/i2c/tc358743.c
> +++ b/drivers/media/i2c/tc358743.c
> @@ -1743,6 +1743,7 @@ static int tc358743_probe_of(struct tc358743_state *state)
>  	struct clk *refclk;
>  	u32 bps_pr_lane;
>  	int ret = -EINVAL;
> +	int i;
>  
>  	refclk = devm_clk_get(dev, "refclk");
>  	if (IS_ERR(refclk)) {
> @@ -1771,6 +1772,21 @@ static int tc358743_probe_of(struct tc358743_state *state)
>  		goto free_endpoint;
>  	}
>  
> +	if (endpoint->bus.mipi_csi2.num_data_lanes > 4) {
> +		dev_err(dev, "invalid number of lanes\n");
> +		goto free_endpoint;
> +	}
> +
> +	for (i = 0; i < endpoint->bus.mipi_csi2.num_data_lanes; i++) {
> +		if (endpoint->bus.mipi_csi2.data_lanes[i] != i + 1)
> +			break;
> +	}

No other drivers perform such checks and if the hardware just doesn't
support it, then I'd just care about the number.

Checking that there are no more lanes configured than the hardware supports
makes definitely sense.

> +	if (i != endpoint->bus.mipi_csi2.num_data_lanes ||
> +	    endpoint->bus.mipi_csi2.clock_lane != 0) {
> +		dev_err(dev, "invalid lane order\n");
> +		goto free_endpoint;
> +	}
> +
>  	state->bus = endpoint->bus.mipi_csi2;
>  
>  	ret = clk_prepare_enable(refclk);
diff mbox

Patch

diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c
index a35043cefe128..b7285e45b908a 100644
--- a/drivers/media/i2c/tc358743.c
+++ b/drivers/media/i2c/tc358743.c
@@ -1743,6 +1743,7 @@  static int tc358743_probe_of(struct tc358743_state *state)
 	struct clk *refclk;
 	u32 bps_pr_lane;
 	int ret = -EINVAL;
+	int i;
 
 	refclk = devm_clk_get(dev, "refclk");
 	if (IS_ERR(refclk)) {
@@ -1771,6 +1772,21 @@  static int tc358743_probe_of(struct tc358743_state *state)
 		goto free_endpoint;
 	}
 
+	if (endpoint->bus.mipi_csi2.num_data_lanes > 4) {
+		dev_err(dev, "invalid number of lanes\n");
+		goto free_endpoint;
+	}
+
+	for (i = 0; i < endpoint->bus.mipi_csi2.num_data_lanes; i++) {
+		if (endpoint->bus.mipi_csi2.data_lanes[i] != i + 1)
+			break;
+	}
+	if (i != endpoint->bus.mipi_csi2.num_data_lanes ||
+	    endpoint->bus.mipi_csi2.clock_lane != 0) {
+		dev_err(dev, "invalid lane order\n");
+		goto free_endpoint;
+	}
+
 	state->bus = endpoint->bus.mipi_csi2;
 
 	ret = clk_prepare_enable(refclk);