From patchwork Wed Dec 6 14:54:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 120864 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp7151884qgn; Wed, 6 Dec 2017 06:54:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMYGfUPtUcFjWOZHjBYdvkjvq9UiSKbskx68QaJu93o0WVcROfufNK4Nk715QR0GCiB20Qs6 X-Received: by 10.84.218.204 with SMTP id g12mr22203872plm.213.1512572057903; Wed, 06 Dec 2017 06:54:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512572057; cv=none; d=google.com; s=arc-20160816; b=UzM0Vn7dTidVtjChj/bc4bTFOVOjgX2cBG2r0YnGr0pFusGEFIRTrwAIiHdZKCl7aO X9xL2eDBeccdaDK2bJhw5GEozbUQ0TVt/EW2oOdZyEZSh3Tqb13z9wSvZHlqkiX2tf/R qAh79kPkEe0OJ8vQpZ92KslkETIb5KeNPS0N38faQQ7gaXjo1r8hqr67bFAQTGhhsER4 wsdUrRDNQnqVduCLQM54EdJt+KtzU6BwAdfZX0q5hoJQTG0BnYgkkxqK4XtwzqbjrFyJ Gz76wS6PvnXaqCddM4/W9cXHTRlHnfI0D7g/RFEcNPn3vnYD+QNF2i3+62WxFKUKKur7 a6pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=8hFh8WcgtffoxwWEAd1JN1da6c2IKcpYZzIOR9CRE70=; b=TB9P+oDdIXGeUi62LxIR2Hl6p9DW6RGR5SXDfvfRaAHpKU44RafAnkXOPFlnkh1pDn OGfnyNyjkNZVnqf5G7bcejX2O7qyqp3bvacIEzAB/puaeFzo2G/CwlztgDdAsm0hANTS VwVRI7qGOaA1UHONzo0dhSuqcl0U8Okg23muW7w/FXXSSaB/R3tPbiTmeacKUtmpDz4k N8bNoAKYiFwN8es5vEE5a3UNlC7payRzQb2iktl6eTfN/CcP6c83J6iwjDrNNF7ZsGMI WtDHam0Yu1zm5DzEgMJZfyzDGJ0YBQYs53LLrug9zW73cLPk5QwRKnSRIyGhxhA5XK2h N6lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZK+V9TnX; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l193si2010998pge.778.2017.12.06.06.54.17; Wed, 06 Dec 2017 06:54:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZK+V9TnX; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752457AbdLFOyP (ORCPT + 4 others); Wed, 6 Dec 2017 09:54:15 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:42591 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752379AbdLFOyO (ORCPT ); Wed, 6 Dec 2017 09:54:14 -0500 Received: by mail-lf0-f66.google.com with SMTP id i2so4528492lfe.9 for ; Wed, 06 Dec 2017 06:54:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=wsA7oX04uA4JIkz9IRMou7acXyI/ZmCqwgeicWBWitw=; b=ZK+V9TnXL2jpRuzksl4t5vYNc55VCiG9ptuK2GKFeRa5qivA9HIg15OfVpfILZWCc/ YpF9uvr8+28cewPxU8bvVK6oKwo2WPNJ7kpY207bGFv052EynxrOxycr3MmPI+konnhf Y1Blz1awQ9vTzwaPEqZvxg5LRXWnVu2YjlJOI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wsA7oX04uA4JIkz9IRMou7acXyI/ZmCqwgeicWBWitw=; b=UIqipW9PY9aam2lVg+KaoBcZnAFeqZl0+5ZkZ+T0jj9oLUh9Qk5WSl+nj8jV5MZqHc 7oMXq6vqDvjj8/hTSptPdrAOdPDa4tgf8uCpPsZnxopDZuAUpfNtflmNC3KQLBZHiHEg VyDj1V3xucJ+LwPsKyGYjzDjKh16WSdU8qXnwP5i2tnapPoNGqZwPaFKshhqwOx7OupQ Y5bOkJ/NX9BkkR7kufjTEWtBeqIIxMrQtr2sS+OA0eJMIIzVS8CMThi8eisGtQtUGRzF qnVLoom08GIMeyZAeKtZ9X1Viyt2Q4Mc5n67w4p8vN6sx+9wNcqZf7JrX5z03uVy7WKG WaKw== X-Gm-Message-State: AKGB3mIpFaf96npybn59rfSd2+rpl1eHV2wZq9sWeFWMnx5xOVl1stdM kldykKuVmRpxCklGPL1Rk8VFtQ== X-Received: by 10.25.80.93 with SMTP id z29mr1361786lfj.9.1512572052957; Wed, 06 Dec 2017 06:54:12 -0800 (PST) Received: from khorivan.synapse.com (59-201-94-178.pool.ukrtel.net. [178.94.201.59]) by smtp.gmail.com with ESMTPSA id n36sm538037lfi.78.2017.12.06.06.54.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Dec 2017 06:54:12 -0800 (PST) From: Ivan Khoronzhuk To: grygorii.strashko@ti.com Cc: netdev@vger.kernel.org, davem@davemloft.net, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, Ivan Khoronzhuk Subject: [PATCH net-next] net: ethernet: ti: cpdma: correct error handling for chan create Date: Wed, 6 Dec 2017 16:54:09 +0200 Message-Id: <1512572050-13442-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org It's not correct to return NULL when that is actually an error and function returns errors in any other wrong case. In the same time, the cpsw driver and davinci emac doesn't check error case while creating channel and it can miss actual error. Correct this mess. Signed-off-by: Ivan Khoronzhuk --- drivers/net/ethernet/ti/cpsw.c | 12 +++++++++--- drivers/net/ethernet/ti/davinci_cpdma.c | 2 +- drivers/net/ethernet/ti/davinci_emac.c | 9 +++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) -- 2.7.4 -- 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 --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index a60a378..ee58f48 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c @@ -3065,10 +3065,16 @@ static int cpsw_probe(struct platform_device *pdev) } cpsw->txv[0].ch = cpdma_chan_create(cpsw->dma, 0, cpsw_tx_handler, 0); + if (WARN_ON(IS_ERR(cpsw->txv[0].ch))) { + dev_err(priv->dev, "error initializing tx dma channel\n"); + ret = PTR_ERR(cpsw->txv[0].ch); + goto clean_dma_ret; + } + cpsw->rxv[0].ch = cpdma_chan_create(cpsw->dma, 0, cpsw_rx_handler, 1); - if (WARN_ON(!cpsw->rxv[0].ch || !cpsw->txv[0].ch)) { - dev_err(priv->dev, "error initializing dma channels\n"); - ret = -ENOMEM; + if (WARN_ON(IS_ERR(cpsw->rxv[0].ch))) { + dev_err(priv->dev, "error initializing rx dma channel\n"); + ret = PTR_ERR(cpsw->rxv[0].ch); goto clean_dma_ret; } diff --git a/drivers/net/ethernet/ti/davinci_cpdma.c b/drivers/net/ethernet/ti/davinci_cpdma.c index dbe9167..a9fab42 100644 --- a/drivers/net/ethernet/ti/davinci_cpdma.c +++ b/drivers/net/ethernet/ti/davinci_cpdma.c @@ -893,7 +893,7 @@ struct cpdma_chan *cpdma_chan_create(struct cpdma_ctlr *ctlr, int chan_num, chan_num = rx_type ? rx_chan_num(chan_num) : tx_chan_num(chan_num); if (__chan_linear(chan_num) >= ctlr->num_chan) - return NULL; + return ERR_PTR(-EINVAL); chan = devm_kzalloc(ctlr->dev, sizeof(*chan), GFP_KERNEL); if (!chan) diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c index f58c0c6..3d4af64 100644 --- a/drivers/net/ethernet/ti/davinci_emac.c +++ b/drivers/net/ethernet/ti/davinci_emac.c @@ -1870,10 +1870,15 @@ static int davinci_emac_probe(struct platform_device *pdev) priv->txchan = cpdma_chan_create(priv->dma, EMAC_DEF_TX_CH, emac_tx_handler, 0); + if (WARN_ON(IS_ERR(priv->txchan))) { + rc = PTR_ERR(priv->txchan); + goto no_cpdma_chan; + } + priv->rxchan = cpdma_chan_create(priv->dma, EMAC_DEF_RX_CH, emac_rx_handler, 1); - if (WARN_ON(!priv->txchan || !priv->rxchan)) { - rc = -ENOMEM; + if (WARN_ON(IS_ERR(priv->rxchan))) { + rc = PTR_ERR(priv->rxchan); goto no_cpdma_chan; }