]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm/mdstat: fix coverity issue CHECKED_RETURN
authorXiao Ni <xni@redhat.com>
Fri, 26 Jul 2024 07:14:11 +0000 (15:14 +0800)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Mon, 5 Aug 2024 09:13:17 +0000 (11:13 +0200)
It needs to check return values when functions return value.

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
mdstat.c

index cbbace3d73aaca6e14003f75afa13b012f26c49f..a971a9570856df601d0b2a40e92cf5b8db46513a 100644 (file)
--- a/mdstat.c
+++ b/mdstat.c
@@ -194,8 +194,11 @@ struct mdstat_ent *mdstat_read(int hold, int start)
                f = fopen("/proc/mdstat", "r");
        if (f == NULL)
                return NULL;
-       else
-               fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
+
+       if (fcntl(fileno(f), F_SETFD, FD_CLOEXEC) < 0) {
+               fclose(f);
+               return NULL;
+       }
 
        all = NULL;
        end = &all;
@@ -329,7 +332,10 @@ struct mdstat_ent *mdstat_read(int hold, int start)
        }
        if (hold && mdstat_fd == -1) {
                mdstat_fd = dup(fileno(f));
-               fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC);
+               if (fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC) < 0) {
+                       fclose(f);
+                       return NULL;
+               }
        }
        fclose(f);