lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200217233518.3159-1-hauke@hauke-m.de>
Date:   Tue, 18 Feb 2020 00:35:16 +0100
From:   Hauke Mehrtens <hauke@...ke-m.de>
To:     davem@...emloft.net, linux@...pel-privat.de
Cc:     netdev@...r.kernel.org, jcliburn@...il.com, chris.snook@...il.com,
        Hauke Mehrtens <hauke@...ke-m.de>
Subject: [PATCH 1/3] ag71xx: Handle allocation errors in ag71xx_rings_init()

Free the allocated resources in ag71xx_rings_init() in case
ag71xx_ring_rx_init() returns an error.

This is only a potential problem, I did not ran into this one.

Signed-off-by: Hauke Mehrtens <hauke@...ke-m.de>
Fixes: d51b6ce441d3 ("net: ethernet: add ag71xx driver")
---
 drivers/net/ethernet/atheros/ag71xx.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/atheros/ag71xx.c b/drivers/net/ethernet/atheros/ag71xx.c
index e95687a780fb..6f7281f38d5a 100644
--- a/drivers/net/ethernet/atheros/ag71xx.c
+++ b/drivers/net/ethernet/atheros/ag71xx.c
@@ -1133,6 +1133,7 @@ static int ag71xx_rings_init(struct ag71xx *ag)
 	struct ag71xx_ring *tx = &ag->tx_ring;
 	struct ag71xx_ring *rx = &ag->rx_ring;
 	int ring_size, tx_size;
+	int ret;
 
 	ring_size = BIT(tx->order) + BIT(rx->order);
 	tx_size = BIT(tx->order);
@@ -1145,9 +1146,8 @@ static int ag71xx_rings_init(struct ag71xx *ag)
 					   ring_size * AG71XX_DESC_SIZE,
 					   &tx->descs_dma, GFP_KERNEL);
 	if (!tx->descs_cpu) {
-		kfree(tx->buf);
-		tx->buf = NULL;
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto err_free_buf;
 	}
 
 	rx->buf = &tx->buf[tx_size];
@@ -1155,7 +1155,21 @@ static int ag71xx_rings_init(struct ag71xx *ag)
 	rx->descs_dma = tx->descs_dma + tx_size * AG71XX_DESC_SIZE;
 
 	ag71xx_ring_tx_init(ag);
-	return ag71xx_ring_rx_init(ag);
+	ret = ag71xx_ring_rx_init(ag);
+	if (ret)
+		goto err_free_dma;
+
+	return 0;
+
+err_free_dma:
+	dma_free_coherent(&ag->pdev->dev, ring_size * AG71XX_DESC_SIZE,
+			  tx->descs_cpu, tx->descs_dma);
+	rx->buf = NULL;
+err_free_buf:
+	kfree(tx->buf);
+	tx->buf = NULL;
+
+	return ret;
 }
 
 static void ag71xx_rings_free(struct ag71xx *ag)
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ