From patchwork Mon Dec 3 13:49:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_L=C3=BCbbe?= X-Patchwork-Id: 1833111 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 319253FC5A for ; Mon, 3 Dec 2012 13:50:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755019Ab2LCNt6 (ORCPT ); Mon, 3 Dec 2012 08:49:58 -0500 Received: from metis.ext.pengutronix.de ([92.198.50.35]:53713 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754459Ab2LCNtv (ORCPT ); Mon, 3 Dec 2012 08:49:51 -0500 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1TfWP1-0000iD-IN; Mon, 03 Dec 2012 14:49:43 +0100 Received: from jlu by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1TfWOz-0001dH-DW; Mon, 03 Dec 2012 14:49:41 +0100 From: Jan Luebbe To: netdev@vger.kernel.org Cc: "David S. Miller" , Mugunthan V N , Vaibhav Hiremath , linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, Jan Luebbe Subject: [PATCH 2/3] net: cpsw: verify correct number of slaves in DT Date: Mon, 3 Dec 2012 14:49:28 +0100 Message-Id: <1354542569-6165-2-git-send-email-jlu@pengutronix.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1354542569-6165-1-git-send-email-jlu@pengutronix.de> References: <1354542569-6165-1-git-send-email-jlu@pengutronix.de> X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: jlu@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-omap@vger.kernel.org Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org 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 Acked-by: Mugunthan V N --- 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... */