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 <tduszyn...@marvell.com>
Reviewed-by: Jerin Jacob Kollanukkaran <jer...@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 via email to