DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tomasz Duszynski <tduszynski@marvell.com>
To: <dev@dpdk.org>, Jakub Palider <jpalider@marvell.com>,
	Tomasz Duszynski <tduszynski@marvell.com>
Cc: <thomas@monjalon.net>, <jerinj@marvell.com>
Subject: [PATCH 1/2] raw/cnxk_gpio: fix resource leak
Date: Tue, 22 Feb 2022 09:28:16 +0100	[thread overview]
Message-ID: <20220222082817.1057701-2-tduszynski@marvell.com> (raw)
In-Reply-To: <20220222082817.1057701-1-tduszynski@marvell.com>

All used resources need to be properly cleaned up in error path.

Fixes: 0e6557b448fa ("raw/cnxk_gpio: add self test")
Coverity issue: 376504

Signed-off-by: Tomasz Duszynski <tduszynski@marvell.com>
Reviewed-by: Jerin Jacob Kollanukkaran <jerinj@marvell.com>
---
 drivers/raw/cnxk_gpio/cnxk_gpio.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio.c b/drivers/raw/cnxk_gpio/cnxk_gpio.c
index 4ff132861d..9577753851 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio.c
@@ -178,24 +178,30 @@ cnxk_gpio_parse_allowlist(struct cnxk_gpiochip *gpiochip)
 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;
 }
 
 static int
-- 
2.25.1


  reply	other threads:[~2022-02-22  8:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22  8:28 [PATCH 0/2] raw/cnxk_gpio: fix issues discovered by coverity Tomasz Duszynski
2022-02-22  8:28 ` Tomasz Duszynski [this message]
2022-02-22  8:28 ` [PATCH 2/2] raw/cnxk_gpio: check pointer before using it Tomasz Duszynski
2022-02-23 17:29 ` [PATCH 0/2] raw/cnxk_gpio: fix issues discovered by coverity 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=20220222082817.1057701-2-tduszynski@marvell.com \
    --to=tduszynski@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=jpalider@marvell.com \
    --cc=thomas@monjalon.net \
    /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;
as well as URLs for NNTP newsgroup(s).