DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/2] raw/cnxk_gpio: fix issues discovered by coverity
@ 2022-02-22  8:28 Tomasz Duszynski
  2022-02-22  8:28 ` [PATCH 1/2] raw/cnxk_gpio: fix resource leak Tomasz Duszynski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tomasz Duszynski @ 2022-02-22  8:28 UTC (permalink / raw)
  To: dev; +Cc: thomas, jerinj, Tomasz Duszynski

Fix issues that were discovered during coverity scan.

Tomasz Duszynski (2):
  raw/cnxk_gpio: fix resource leak
  raw/cnxk_gpio: check pointer before using it

 drivers/raw/cnxk_gpio/cnxk_gpio.c          | 24 ++++++++++++++--------
 drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c |  2 ++
 2 files changed, 17 insertions(+), 9 deletions(-)

--
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] raw/cnxk_gpio: fix resource leak
  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
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Tomasz Duszynski @ 2022-02-22  8:28 UTC (permalink / raw)
  To: dev, Jakub Palider, Tomasz Duszynski; +Cc: thomas, jerinj

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] raw/cnxk_gpio: check pointer before using it
  2022-02-22  8:28 [PATCH 0/2] raw/cnxk_gpio: fix issues discovered by coverity Tomasz Duszynski
  2022-02-22  8:28 ` [PATCH 1/2] raw/cnxk_gpio: fix resource leak Tomasz Duszynski
@ 2022-02-22  8:28 ` Tomasz Duszynski
  2022-02-23 17:29 ` [PATCH 0/2] raw/cnxk_gpio: fix issues discovered by coverity Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Tomasz Duszynski @ 2022-02-22  8:28 UTC (permalink / raw)
  To: dev, Jakub Palider, Tomasz Duszynski; +Cc: thomas, jerinj

Even though nonexistent cnxk_gpio is unlikely at this point
it's a good practice to check pointers before using them.

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

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

diff --git a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
index 7fccc48f30..acb65afa65 100644
--- a/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
+++ b/drivers/raw/cnxk_gpio/cnxk_gpio_selftest.c
@@ -311,6 +311,8 @@ cnxk_gpio_selftest(uint16_t dev_id)
 	int ret, ret2;
 
 	rawdev = rte_rawdev_pmd_get_named_dev("cnxk_gpio");
+	if (!rawdev)
+		return -ENODEV;
 	gpiochip = rawdev->dev_private;
 
 	queues = rte_rawdev_queue_count(dev_id);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] raw/cnxk_gpio: fix issues discovered by coverity
  2022-02-22  8:28 [PATCH 0/2] raw/cnxk_gpio: fix issues discovered by coverity Tomasz Duszynski
  2022-02-22  8:28 ` [PATCH 1/2] raw/cnxk_gpio: fix resource leak Tomasz Duszynski
  2022-02-22  8:28 ` [PATCH 2/2] raw/cnxk_gpio: check pointer before using it Tomasz Duszynski
@ 2022-02-23 17:29 ` Thomas Monjalon
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2022-02-23 17:29 UTC (permalink / raw)
  To: Tomasz Duszynski; +Cc: dev, jerinj

22/02/2022 09:28, Tomasz Duszynski:
> Fix issues that were discovered during coverity scan.
> 
> Tomasz Duszynski (2):
>   raw/cnxk_gpio: fix resource leak
>   raw/cnxk_gpio: check pointer before using it

Applied, thanks.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-23 17:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22  8:28 [PATCH 0/2] raw/cnxk_gpio: fix issues discovered by coverity Tomasz Duszynski
2022-02-22  8:28 ` [PATCH 1/2] raw/cnxk_gpio: fix resource leak Tomasz Duszynski
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

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).