All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	tduszynski@marvell.com, Jakub Palider <jpalider@marvell.com>
Subject: [PATCH 03/16] raw/cnxk_gpio: fix file descriptor leak
Date: Thu, 14 Nov 2024 22:05:40 -0800	[thread overview]
Message-ID: <20241115060738.313190-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20241115060738.313190-1-stephen@networkplumber.org>

The function would leak file if fscanf failed.
There is a working version in other file, clone that.

Link: https://pvs-studio.com/en/blog/posts/cpp/1183/

Fixes: 0e6557b448fa ("raw/cnxk_gpio: add self test")
Cc: tduszynski@marvell.com

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c | 24 ++++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
index 2f3973a7b5..a0d9942f20 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
@@ -34,24 +34,30 @@ cnxk_gpio_attr_exists(const char *attr)
 static int
 cnxk_gpio_read_attr(char *attr, char *val)
 {
+	int ret, ret2;
 	FILE *fp;
-	int ret;
 
 	fp = fopen(attr, "r");
 	if (!fp)
 		return -errno;
 
 	ret = fscanf(fp, "%s", val);
-	if (ret < 0)
-		return -errno;
-	if (ret != 1)
-		return -EIO;
+	if (ret < 0) {
+		ret = -errno;
+		goto out;
+	}
+	if (ret != 1) {
+		ret = -EIO;
+		goto out;
+	}
 
-	ret = fclose(fp);
-	if (ret)
-		return -errno;
+	ret = 0;
+out:
+	ret2 = fclose(fp);
+	if (!ret)
+		ret = ret2;
 
-	return 0;
+	return ret;
 }
 
 #define CNXK_GPIO_ERR_STR(err, str, ...) do {                                  \
-- 
2.45.2


  parent reply	other threads:[~2024-11-15  6:08 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-15  6:05 [PATCH 00/16] small bug fixes from PVS studio bug list Stephen Hemminger
2024-11-15  6:05 ` [PATCH 01/16] common/cnxk: remove duplicate condition Stephen Hemminger
2024-11-15  6:16   ` [EXTERNAL] " Anoob Joseph
2024-11-15  6:05 ` [PATCH 02/16] net/cpfl: avoid calling log (printf) with null Stephen Hemminger
2024-11-15  6:05 ` Stephen Hemminger [this message]
2024-11-15  6:05 ` [PATCH 04/16] net/ntnic: remove dead code Stephen Hemminger
2024-11-15  6:05 ` [PATCH 05/16] net/i40e: remove duplicate code Stephen Hemminger
2024-11-15 11:00   ` Bruce Richardson
2024-11-15  6:05 ` [PATCH 06/16] eal: fix out of bounds access in devargs Stephen Hemminger
2024-11-15  6:05 ` [PATCH 07/16] net/qede: fix missing debug string Stephen Hemminger
2024-11-15  6:05 ` [PATCH 08/16] examples/ptpclient: replace rte_memcpy with assignment Stephen Hemminger
2024-11-15  6:05 ` [PATCH 09/16] examples/ptpclient: fix self memcmp Stephen Hemminger
2024-11-15  6:05 ` [PATCH 10/16] net/octeon_ep: remove duplicate code Stephen Hemminger
2024-11-15  6:05 ` [PATCH 11/16] net/hinic: fix flow type bitmask overflow Stephen Hemminger
2024-11-15  6:05 ` [PATCH 12/16] crypto/dpaa2_sec: fix bitmask truncation Stephen Hemminger
2024-11-18  7:03   ` Hemant Agrawal
2024-11-15  6:05 ` [PATCH 13/16] crypto/dpaa_sec: " Stephen Hemminger
2024-11-18  7:03   ` Hemant Agrawal
2024-11-15  6:05 ` [PATCH 14/16] event/dpaa: " Stephen Hemminger
2024-11-18  7:04   ` Hemant Agrawal
2024-11-15  6:05 ` [PATCH 15/16] net/dpaa: " Stephen Hemminger
2024-11-18  7:04   ` Hemant Agrawal
2024-11-15  6:05 ` [PATCH 16/16] net/dpaa2: " Stephen Hemminger
2024-11-18  7:04   ` Hemant Agrawal
2024-11-18 18:20 ` [PATCH v2 00/19] minor fixes from PVS studio bug list Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 01/19] common/cnxk: remove duplicate condition Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 02/19] net/cpfl: avoid calling log (printf) with null Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 03/19] raw/cnxk_gpio: fix file descriptor leak Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 04/19] net/ntnic: remove dead code Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 05/19] net/i40e: remove duplicate code Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 06/19] eal: fix out of bounds access in devargs Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 07/19] net/qede: fix missing debug string Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 08/19] examples/ptpclient: replace rte_memcpy with assignment Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 09/19] examples/ptpclient: fix self memcmp Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 10/19] net/octeon_ep: remove duplicate code Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 11/19] net/hinic: fix flow type bitmask overflow Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 12/19] crypto/dpaa2_sec: fix bitmask truncation Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 13/19] crypto/dpaa_sec: " Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 14/19] event/dpaa: " Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 15/19] net/dpaa: " Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 16/19] net/dpaa2: " Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 17/19] net/qede: don't use same loop variable twice Stephen Hemminger
2024-11-18 18:20   ` [PATCH v2 18/19] examples/l3fwd: fix operator precedence bugs Stephen Hemminger
2024-11-18 18:21   ` [PATCH v2 19/19] common/cnxk: fix null ptr check Stephen Hemminger
2024-11-19 15:22   ` [PATCH v2 00/19] minor fixes from PVS studio bug list Thomas Monjalon
2025-02-05 16:23 ` [PATCH v3 " Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 01/19] common/cnxk: remove duplicate condition Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 02/19] net/cpfl: avoid calling log (printf) with null Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 03/19] raw/cnxk_gpio: fix file descriptor leak Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 04/19] net/ntnic: remove dead code Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 05/19] net/i40e: remove duplicate code Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 06/19] eal: fix out of bounds access in devargs Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 07/19] net/qede: fix missing debug string Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 08/19] examples/ptpclient: replace rte_memcpy with assignment Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 09/19] examples/ptpclient: fix self memcmp Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 10/19] net/octeon_ep: remove duplicate code Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 11/19] net/hinic: fix flow type bitmask overflow Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 12/19] crypto/dpaa2_sec: fix bitmask truncation Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 13/19] crypto/dpaa_sec: " Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 14/19] event/dpaa: " Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 15/19] net/dpaa: " Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 16/19] net/dpaa2: " Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 17/19] net/qede: don't use same loop variable twice Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 18/19] examples/l3fwd: fix operator precedence bugs Stephen Hemminger
2025-02-05 16:23   ` [PATCH v3 19/19] common/cnxk: fix null ptr check Stephen Hemminger
2025-02-06 20:11   ` [PATCH v3 00/19] minor fixes from PVS studio bug list Patrick Robb
2025-02-12 11:53   ` Thomas Monjalon

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=20241115060738.313190-4-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=jpalider@marvell.com \
    --cc=tduszynski@marvell.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.