diff mbox

[2/3] net: cpsw: verify correct number of slaves in DT

Message ID 1354542569-6165-2-git-send-email-jlu@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Lübbe Dec. 3, 2012, 1:49 p.m. UTC
Check that the number of available slaves passed from DT matches the
value of the "slaves" property in the cpsw node. Otherwise, priv->slaves
would be the wrong size.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 drivers/net/ethernet/ti/cpsw.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Mugunthan V N Dec. 3, 2012, 5 p.m. UTC | #1
On 12/3/2012 7:19 PM, Jan Luebbe wrote:
> Check that the number of available slaves passed from DT matches the
> value of the "slaves" property in the cpsw node. Otherwise, priv->slaves
> would be the wrong size.
>
> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
> ---
>   drivers/net/ethernet/ti/cpsw.c |   17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
>
> diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
> index c0e676a..8de3e92 100644
> --- a/drivers/net/ethernet/ti/cpsw.c
> +++ b/drivers/net/ethernet/ti/cpsw.c
> @@ -832,6 +832,16 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
>   		const char *phy_id = NULL;
>   		const void *mac_addr = NULL;
>   
> +		if (!of_device_is_available(slave_node))
> +			continue;
> +
> +		if (i >= data->slaves) {
> +			dev_err(&pdev->dev, "Too many slaves in the DT (> %d).\n",
> +				data->slaves);
> +			ret = -EINVAL;
> +			goto error_ret;
> +		}
> +
>   		if (of_property_read_string(slave_node, "phy_id", &phy_id)) {
>   			dev_err(&pdev->dev, "Missing slave[%d] phy_id property.\n", i);
>   			ret = -EINVAL;
> @@ -861,6 +871,13 @@ static int cpsw_probe_dt(struct cpsw_platform_data *data,
>   		i++;
>   	}
>   
> +	if (i < data->slaves) {
> +		dev_err(&pdev->dev, "Not enough slaves in the DT (< %d).\n",
> +			data->slaves);
> +		ret = -EINVAL;
> +		goto error_ret;
> +	}
> +
>   	/*
>   	 * Populate all the child nodes here...
>   	 */

The patches look good to me.

Acked-by: Mugunthan V N<mugunthanvnm@ti.com>

Regards
Mugunthan V N

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

Patch

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index c0e676a..8de3e92 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -832,6 +832,16 @@  static int cpsw_probe_dt(struct cpsw_platform_data *data,
 		const char *phy_id = NULL;
 		const void *mac_addr = NULL;
 
+		if (!of_device_is_available(slave_node))
+			continue;
+
+		if (i >= data->slaves) {
+			dev_err(&pdev->dev, "Too many slaves in the DT (> %d).\n",
+				data->slaves);
+			ret = -EINVAL;
+			goto error_ret;
+		}
+
 		if (of_property_read_string(slave_node, "phy_id", &phy_id)) {
 			dev_err(&pdev->dev, "Missing slave[%d] phy_id property.\n", i);
 			ret = -EINVAL;
@@ -861,6 +871,13 @@  static int cpsw_probe_dt(struct cpsw_platform_data *data,
 		i++;
 	}
 
+	if (i < data->slaves) {
+		dev_err(&pdev->dev, "Not enough slaves in the DT (< %d).\n",
+			data->slaves);
+		ret = -EINVAL;
+		goto error_ret;
+	}
+
 	/*
 	 * Populate all the child nodes here...
 	 */