From: Xiao Ni <xni@redhat.com>
To: mariusz.tkaczyk@linux.intel.com
Cc: ncroxon@redhat.com, linux-raid@vger.kernel.org
Subject: [PATCH 1/3] mdadm/Grow: fix coverity issue CHECKED_RETURN
Date: Mon, 22 Jul 2024 16:17:23 +0800 [thread overview]
Message-ID: <20240722081736.20439-2-xni@redhat.com> (raw)
In-Reply-To: <20240722081736.20439-1-xni@redhat.com>
It needs to check return value when functions have return value.
Signed-off-by: Xiao Ni <xni@redhat.com>
---
Grow.c | 43 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 7 deletions(-)
diff --git a/Grow.c b/Grow.c
index b135930d05b8..7ae967bda067 100644
--- a/Grow.c
+++ b/Grow.c
@@ -3261,7 +3261,12 @@ static int reshape_array(char *container, int fd, char *devname,
/* This is a spare that wants to
* be part of the array.
*/
- add_disk(fd, st, info2, d);
+ if (add_disk(fd, st, info2, d) < 0) {
+ pr_err("Can not add disk %s\n",
+ d->sys_name);
+ free(info2);
+ goto release;
+ }
}
}
sysfs_free(info2);
@@ -4413,7 +4418,10 @@ static void validate(int afd, int bfd, unsigned long long offset)
*/
if (afd < 0)
return;
- lseek64(bfd, offset - 4096, 0);
+ if (lseek64(bfd, offset - 4096, 0) < 0) {
+ pr_err("lseek64 fails %d:%s\n", errno, strerror(errno));
+ return;
+ }
if (read(bfd, &bsb2, 512) != 512)
fail("cannot read bsb");
if (bsb2.sb_csum != bsb_csum((char*)&bsb2,
@@ -4444,12 +4452,19 @@ static void validate(int afd, int bfd, unsigned long long offset)
}
}
- lseek64(bfd, offset, 0);
+ if (lseek64(bfd, offset, 0) < 0) {
+ pr_err("lseek64 fails %d:%s\n", errno, strerror(errno));
+ goto out;
+ }
if ((unsigned long long)read(bfd, bbuf, len) != len) {
//printf("len %llu\n", len);
fail("read first backup failed");
}
- lseek64(afd, __le64_to_cpu(bsb2.arraystart)*512, 0);
+
+ if (lseek64(afd, __le64_to_cpu(bsb2.arraystart)*512, 0) < 0) {
+ pr_err("lseek64 fails %d:%s\n", errno, strerror(errno));
+ goto out;
+ }
if ((unsigned long long)read(afd, abuf, len) != len)
fail("read first from array failed");
if (memcmp(bbuf, abuf, len) != 0)
@@ -4466,15 +4481,25 @@ static void validate(int afd, int bfd, unsigned long long offset)
bbuf = xmalloc(abuflen);
}
- lseek64(bfd, offset+__le64_to_cpu(bsb2.devstart2)*512, 0);
+ if (lseek64(bfd, offset+__le64_to_cpu(bsb2.devstart2)*512, 0) < 0) {
+ pr_err("lseek64 fails %d:%s\n", errno, strerror(errno));
+ goto out;
+ }
if ((unsigned long long)read(bfd, bbuf, len) != len)
fail("read second backup failed");
- lseek64(afd, __le64_to_cpu(bsb2.arraystart2)*512, 0);
+ if (lseek64(afd, __le64_to_cpu(bsb2.arraystart2)*512, 0) < 0) {
+ pr_err("lseek64 fails %d:%s\n", errno, strerror(errno));
+ goto out;
+ }
if ((unsigned long long)read(afd, abuf, len) != len)
fail("read second from array failed");
if (memcmp(bbuf, abuf, len) != 0)
fail("data2 compare failed");
}
+out:
+ free(abuf);
+ free(bbuf);
+ return;
}
int child_monitor(int afd, struct mdinfo *sra, struct reshape *reshape,
@@ -5033,7 +5058,11 @@ int Grow_continue_command(char *devname, int fd, struct context *c)
goto Grow_continue_command_exit;
}
content = &array;
- sysfs_init(content, fd, NULL);
+ if (sysfs_init(content, fd, NULL) < 0) {
+ pr_err("sysfs_init fails\n");
+ ret_val = 1;
+ goto Grow_continue_command_exit;
+ }
/* Need to load a superblock.
* FIXME we should really get what we need from
* sysfs
--
2.32.0 (Apple Git-132)
next prev parent reply other threads:[~2024-07-22 8:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-22 8:17 [PATCH V3 00/14] mdadm: fix coverity issues Xiao Ni
2024-07-22 8:17 ` Xiao Ni [this message]
2024-07-22 8:17 ` [PATCH 2/3] mdadm/Grow: fix coverity issue RESOURCE_LEAK Xiao Ni
2024-07-22 8:17 ` [PATCH 3/3] mdadm/Grow: fix coverity issue STRING_OVERFLOW Xiao Ni
2024-07-22 8:17 ` [PATCH 04/14] mdadm/Incremental: fix coverity issues Xiao Ni
2024-07-22 8:17 ` [PATCH 05/14] mdadm/mdmon: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-22 8:17 ` [PATCH 06/14] mdadm/mdmon: fix coverity issue RESOURCE_LEAK Xiao Ni
2024-07-22 8:17 ` [PATCH 07/14] mdadm/mdopen: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-22 8:17 ` [PATCH 08/14] mdadm/mdopen: fix coverity issue STRING_OVERFLOW Xiao Ni
2024-07-22 8:17 ` [PATCH 09/14] mdadm/mdstat: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-22 8:17 ` [PATCH 10/14] mdadm/super0: fix coverity issue CHECKED_RETURN and EVALUATION_ORDER Xiao Ni
2024-07-22 8:17 ` [PATCH 11/14] mdadm/super1: fix coverity issue CHECKED_RETURN Xiao Ni
2024-07-22 8:17 ` [PATCH 12/14] mdadm/super1: fix coverity issue DEADCODE Xiao Ni
2024-07-22 8:17 ` [PATCH 13/14] mdadm/super1: fix coverity issue EVALUATION_ORDER Xiao Ni
2024-07-22 8:17 ` [PATCH 14/14] mdadm/super1: fix coverity issue RESOURCE_LEAK Xiao Ni
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=20240722081736.20439-2-xni@redhat.com \
--to=xni@redhat.com \
--cc=linux-raid@vger.kernel.org \
--cc=mariusz.tkaczyk@linux.intel.com \
--cc=ncroxon@redhat.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 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).