Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp605450ybl; Fri, 10 Jan 2020 03:55:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzOtXCX+vbvGJ72YpEA6wH4m3Bdko2QoIHSC4xfRR99Te9RgEWP9Ji15pv+XGh1WbQLaUfM X-Received: by 2002:a05:6808:a11:: with SMTP id n17mr1827972oij.94.1578657334567; Fri, 10 Jan 2020 03:55:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578657334; cv=none; d=google.com; s=arc-20160816; b=Hpb3vZOToUfT4CATr1A+wVhCgyLHXxqtNrEzeo4qdtSdxPtOqhCV8YIl/6BvU4L3WC OGMCDXLhM/pFRk5bkUl/lSgFJHsTm+z65se3wKRdc70w2k3VJbfpNYNamDX88meOxc59 ha6zbx5MX/4BSnOcHUVEr7rHl4mzsmt9t1x9JQRjC8LpdjgXsO1F+sq6ds+lsJ7wMDLe XvLGtcwG/IyVuTG2Zfifs9EouTXz6kKpzXYHgL+Q9iu2NkWXGE86mjsaDNVcqK2oNhST k2wYF9u7x2zANBwvQIN1CmJN98m6OsZmXTfOttdYUfJ5PgANlPq7PxIN6EhK/MSAal83 DcWw== 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; bh=gqnJl3HIf6PHvlIkYckfTEjEc5Uru+zCIvVp3GQciHc=; b=jMRhoF27ZvkbIaw2UXjguMy8hp+szlPg79Tp621CHjfbaRoMeXTncyJ/GzLhpG0SX+ Cu4Dhb/GD1EOYYhXQXY4ooHMpr95kHTQ9dvRuGcy8gn75zLwOTeL8tr6HX5jxo/DiPHm KcKvwVaAbGw6fsH+hYkZ3L4LYcYKMrSKQ1D3HlknjJtTVXpgDiSHkRx9wr8G7OAShcjH gFy5B5uJVz6sAZSAAnWxJY2kcA9JT85HhFB6LUnTB2HIaUXcmi6Oc75DUVqhdsRCQPkB xD2idZM4vdNTWOW91a4LFFf+ZkbcH1crfqFHvo1QlbnmXNxmMy4hmW2aQUfVnP8IzkL9 rp/w== 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 l19si840773oii.54.2020.01.10.03.55.23; Fri, 10 Jan 2020 03:55:34 -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 S1728034AbgAJLy2 (ORCPT + 99 others); Fri, 10 Jan 2020 06:54:28 -0500 Received: from foss.arm.com ([217.140.110.172]:43096 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728015AbgAJLy0 (ORCPT ); Fri, 10 Jan 2020 06:54:26 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 16A13139F; Fri, 10 Jan 2020 03:54:26 -0800 (PST) Received: from donnerap.arm.com (donnerap.cambridge.arm.com [10.1.197.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EE2283F534; Fri, 10 Jan 2020 03:54:24 -0800 (PST) From: Andre Przywara To: "David S . Miller" , Radhey Shyam Pandey Cc: Michal Simek , Robert Hancock , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/14] net: axienet: Propagate failure of DMA descriptor setup Date: Fri, 10 Jan 2020 11:54:03 +0000 Message-Id: <20200110115415.75683-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200110115415.75683-1-andre.przywara@arm.com> References: <20200110115415.75683-1-andre.przywara@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we fail allocating the DMA buffers in axienet_dma_bd_init(), we report this error, but carry on with initialisation nevertheless. This leads to a kernel panic when the driver later wants to send a packet, as it uses uninitialised data structures. Make the axienet_device_reset() routine return an error value, as it contains the DMA buffer initialisation. Make sure we propagate the error up the chain and eventually fail the driver initialisation, to avoid relying on non-initialised buffers. Signed-off-by: Andre Przywara --- .../net/ethernet/xilinx/xilinx_axienet_main.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 20746b801959..97482cf093ce 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -437,9 +437,10 @@ static void axienet_setoptions(struct net_device *ndev, u32 options) lp->options |= options; } -static void __axienet_device_reset(struct axienet_local *lp) +static int __axienet_device_reset(struct axienet_local *lp) { u32 timeout; + /* Reset Axi DMA. This would reset Axi Ethernet core as well. The reset * process of Axi DMA takes a while to complete as all pending * commands/transfers will be flushed or completed during this @@ -455,9 +456,11 @@ static void __axienet_device_reset(struct axienet_local *lp) if (--timeout == 0) { netdev_err(lp->ndev, "%s: DMA reset timeout!\n", __func__); - break; + return -ETIMEDOUT; } } + + return 0; } /** @@ -471,12 +474,15 @@ static void __axienet_device_reset(struct axienet_local *lp) * Ethernet core. No separate hardware reset is done for the Axi Ethernet * core. */ -static void axienet_device_reset(struct net_device *ndev) +static int axienet_device_reset(struct net_device *ndev) { u32 axienet_status; struct axienet_local *lp = netdev_priv(ndev); + int ret; - __axienet_device_reset(lp); + ret = __axienet_device_reset(lp); + if (ret) + return ret; lp->max_frm_size = XAE_MAX_VLAN_FRAME_SIZE; lp->options |= XAE_OPTION_VLAN; @@ -491,9 +497,11 @@ static void axienet_device_reset(struct net_device *ndev) lp->options |= XAE_OPTION_JUMBO; } - if (axienet_dma_bd_init(ndev)) { + ret = axienet_dma_bd_init(ndev); + if (ret) { netdev_err(ndev, "%s: descriptor allocation failed\n", __func__); + return ret; } axienet_status = axienet_ior(lp, XAE_RCW1_OFFSET); @@ -518,6 +526,8 @@ static void axienet_device_reset(struct net_device *ndev) axienet_setoptions(ndev, lp->options); netif_trans_update(ndev); + + return 0; } /** @@ -921,8 +931,9 @@ static int axienet_open(struct net_device *ndev) */ mutex_lock(&lp->mii_bus->mdio_lock); axienet_mdio_disable(lp); - axienet_device_reset(ndev); - ret = axienet_mdio_enable(lp); + ret = axienet_device_reset(ndev); + if (ret == 0) + ret = axienet_mdio_enable(lp); mutex_unlock(&lp->mii_bus->mdio_lock); if (ret < 0) return ret; -- 2.17.1