Received: by 10.223.185.116 with SMTP id b49csp3994588wrg; Mon, 19 Feb 2018 09:14:01 -0800 (PST) X-Google-Smtp-Source: AH8x226yIV3L7LJuPRVzCUzqBHD7A/NIjiJ/taLbixpE8KZlV8Rocu8BdLvOyYCk8oyMWCMH5QYC X-Received: by 10.98.87.68 with SMTP id l65mr15177668pfb.72.1519060441227; Mon, 19 Feb 2018 09:14:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519060441; cv=none; d=google.com; s=arc-20160816; b=A8zjKiGStQ0iObuTF4mai5/TimYqrT73nm204WJxowxLaUXOUfi5L2N0A5Jivh9P4S B9PnzA2GXvkLqQ6cg2i85sFMTbb89BYpB/pLcy+T9cvA0oi1PcbqqUr4wA2ZIiIC3AwA Utk88ntiG/P/rXBdhCiekR611dz5THTaYrKaHn8IH+VanXrXi2GRAVOVJVKHXC0OKUE9 pxv6yd0QdknbAkoDEIoU1YzAWGV63gtiXcjQ2e3jzSV/HOoKeKogFCZrA4jLsPP01hWk CAswIutuqhPfVS2qvx02IYD8zYiz0k1JTIO7sQElscohobdIYOHOii22P83tXdfJS6MB R2CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=IrdADhyaCIy6vaLNAwQ61LUM6RNpbk7nhQVdul73f5A=; b=yrJjcLVSkmU7y/lzsrK97h2GIWOpstInLY+G6JGGmnSkvbK10XZMPyTREulzHXr6WC ux9B3iKlawXIVL+754qSds4zm8wwGaCxJUDjKLDzQ7qBI0NifQpe9kT+tRjD7LsZAwWy n64WznQIcvCet6Zx9OHg5HYggQGfTW8c3nLJR/WOf8zzdbuWsDhArM9SJTqLz69Ik+vD nxTp6zLxqWJveE37lamIGbi54aTqq40xGP2J7nHFnfCdJFLlDQP1MeKo6cy+Fal360rO Wvr7w+BsuMqyU1W69bdjsdCpwQfndjxaGXF/PwZdqTTAWkZ0F3aqI37RYhZVdVzprXG+ eJGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si7883696plg.134.2018.02.19.09.13.47; Mon, 19 Feb 2018 09:14:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753673AbeBSRMe (ORCPT + 99 others); Mon, 19 Feb 2018 12:12:34 -0500 Received: from bastet.se.axis.com ([195.60.68.11]:38937 "EHLO bastet.se.axis.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753365AbeBSRMA (ORCPT ); Mon, 19 Feb 2018 12:12:00 -0500 Received: from localhost (localhost [127.0.0.1]) by bastet.se.axis.com (Postfix) with ESMTP id 67F4318341; Mon, 19 Feb 2018 18:11:59 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at bastet.se.axis.com Received: from bastet.se.axis.com ([IPv6:::ffff:127.0.0.1]) by localhost (bastet.se.axis.com [::ffff:127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3H4_fR-8ACez; Mon, 19 Feb 2018 18:11:57 +0100 (CET) Received: from boulder02.se.axis.com (boulder02.se.axis.com [10.0.8.16]) by bastet.se.axis.com (Postfix) with ESMTPS id 3652C1833E; Mon, 19 Feb 2018 18:11:57 +0100 (CET) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 22BAC1A07C; Mon, 19 Feb 2018 18:11:57 +0100 (CET) Received: from boulder02.se.axis.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 17C561A07B; Mon, 19 Feb 2018 18:11:57 +0100 (CET) Received: from seth.se.axis.com (unknown [10.0.2.172]) by boulder02.se.axis.com (Postfix) with ESMTP; Mon, 19 Feb 2018 18:11:57 +0100 (CET) Received: from lnxartpec1.se.axis.com (lnxartpec1.se.axis.com [10.88.4.10]) by seth.se.axis.com (Postfix) with ESMTP id 0BC361A5E; Mon, 19 Feb 2018 18:11:57 +0100 (CET) Received: by lnxartpec1.se.axis.com (Postfix, from userid 20283) id 07222401B8; Mon, 19 Feb 2018 18:11:57 +0100 (CET) From: Niklas Cassel To: Giuseppe Cavallaro , Alexandre Torgue Cc: Jose.Abreu@synopsys.com, vbhadram@nvidia.com, Niklas Cassel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 6/7] net: stmmac: add error handling in stmmac_mtl_setup() Date: Mon, 19 Feb 2018 18:11:14 +0100 Message-Id: <20180219171116.15326-7-niklas.cassel@axis.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180219171116.15326-1-niklas.cassel@axis.com> References: <20180219171116.15326-1-niklas.cassel@axis.com> X-TM-AS-GCONF: 00 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The device tree binding for stmmac says: - Multiple TX Queues parameters: below the list of all the parameters to configure the multiple TX queues: - snps,tx-queues-to-use: number of TX queues to be used in the driver [...] - For each TX queue [...] However, if one specifies snps,tx-queues-to-use = 2, but omits the queue subnodes, or defines just one queue subnode, since the driver appears to initialize queues with sane default values, we will get tx queue timeouts. This is because the initialization code only initializes as many queues as it finds subnodes. Potentially leaving some queues uninitialized. To avoid hard to debug issues, return an error if the number of subnodes differ from snps,tx-queues-to-use/snps,rx-queues-to-use. Signed-off-by: Niklas Cassel --- .../net/ethernet/stmicro/stmmac/stmmac_platform.c | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 05f122b8424a..bcfac84cf6fb 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -135,13 +135,14 @@ static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev) * stmmac_mtl_setup - parse DT parameters for multiple queues configuration * @pdev: platform device */ -static void stmmac_mtl_setup(struct platform_device *pdev, - struct plat_stmmacenet_data *plat) +static int stmmac_mtl_setup(struct platform_device *pdev, + struct plat_stmmacenet_data *plat) { struct device_node *q_node; struct device_node *rx_node; struct device_node *tx_node; u8 queue = 0; + int ret = 0; /* For backwards-compatibility with device trees that don't have any * snps,mtl-rx-config or snps,mtl-tx-config properties, we fall back @@ -159,12 +160,12 @@ static void stmmac_mtl_setup(struct platform_device *pdev, rx_node = of_parse_phandle(pdev->dev.of_node, "snps,mtl-rx-config", 0); if (!rx_node) - return; + return ret; tx_node = of_parse_phandle(pdev->dev.of_node, "snps,mtl-tx-config", 0); if (!tx_node) { of_node_put(rx_node); - return; + return ret; } /* Processing RX queues common config */ @@ -220,6 +221,11 @@ static void stmmac_mtl_setup(struct platform_device *pdev, queue++; } + if (queue != plat->rx_queues_to_use) { + ret = -EINVAL; + dev_err(&pdev->dev, "Not all RX queues were configured\n"); + goto out; + } /* Processing TX queues common config */ if (of_property_read_u32(tx_node, "snps,tx-queues-to-use", @@ -281,10 +287,18 @@ static void stmmac_mtl_setup(struct platform_device *pdev, queue++; } + if (queue != plat->tx_queues_to_use) { + ret = -EINVAL; + dev_err(&pdev->dev, "Not all TX queues were configured\n"); + goto out; + } +out: of_node_put(rx_node); of_node_put(tx_node); of_node_put(q_node); + + return ret; } /** @@ -376,6 +390,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) struct device_node *np = pdev->dev.of_node; struct plat_stmmacenet_data *plat; struct stmmac_dma_cfg *dma_cfg; + int rc; plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); if (!plat) @@ -499,7 +514,11 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) plat->axi = stmmac_axi_setup(pdev); - stmmac_mtl_setup(pdev, plat); + rc = stmmac_mtl_setup(pdev, plat); + if (rc) { + stmmac_remove_config_dt(pdev, plat); + return ERR_PTR(rc); + } /* clock setup */ plat->stmmac_clk = devm_clk_get(&pdev->dev, -- 2.14.2