mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: YueHaibing <yuehaibing@huawei.com>
To: <jiawenwu@trustnetic.com>, <mengyuanlou@net-swift.com>,
	<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
	<pabeni@redhat.com>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	YueHaibing <yuehaibing@huawei.com>
Subject: [PATCH net-next 1/2] net: txgbe: Fix memleak in txgbe_calc_eeprom_checksum()
Date: Sat, 5 Nov 2022 16:07:21 +0800	[thread overview]
Message-ID: <20221105080722.20292-2-yuehaibing@huawei.com> (raw)
In-Reply-To: <20221105080722.20292-1-yuehaibing@huawei.com>

eeprom_ptrs should be freed before returned.

Fixes: 049fe5365324 ("net: txgbe: Add operations to interact with firmware")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
 drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c
index 0b1032195859..9cf5fe33118e 100644
--- a/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c
+++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_hw.c
@@ -183,6 +183,7 @@ static int txgbe_calc_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum)
 						  eeprom_ptrs);
 		if (status != 0) {
 			wx_err(wxhw, "Failed to read EEPROM image\n");
+			kvfree(eeprom_ptrs);
 			return status;
 		}
 		local_buffer = eeprom_ptrs;
@@ -196,13 +197,13 @@ static int txgbe_calc_eeprom_checksum(struct txgbe_hw *hw, u16 *checksum)
 		if (i != wxhw->eeprom.sw_region_offset + TXGBE_EEPROM_CHECKSUM)
 			*checksum += local_buffer[i];
 
+	if (eeprom_ptrs)
+		kvfree(eeprom_ptrs);
+
 	*checksum = TXGBE_EEPROM_SUM - *checksum;
 	if (*checksum < 0)
 		return -EINVAL;
 
-	if (eeprom_ptrs)
-		kvfree(eeprom_ptrs);
-
 	return 0;
 }
 
-- 
2.17.1


  reply	other threads:[~2022-11-05  8:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-05  8:07 [PATCH net-next 0/2] net: txgbe: Fix two bugs in txgbe_calc_eeprom_checksum YueHaibing
2022-11-05  8:07 ` YueHaibing [this message]
2022-11-05  8:07 ` [PATCH net-next 2/2] net: txgbe: Fix unsigned comparison to zero in txgbe_calc_eeprom_checksum() YueHaibing
2023-07-11  2:47   ` Jiawen Wu
2022-11-08  4:10 ` [PATCH net-next 0/2] net: txgbe: Fix two bugs in txgbe_calc_eeprom_checksum patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221105080722.20292-2-yuehaibing@huawei.com \
    --to=yuehaibing@huawei.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jiawenwu@trustnetic.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mengyuanlou@net-swift.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®