From: Mateusz Kusiak <mateusz.kusiak@intel.com>
To: linux-raid@vger.kernel.org
Cc: jes@trained-monkey.org, mariusz.tkaczyk@linux.intel.com
Subject: [PATCH 6/6] mdmon: refactor md device name check in main()
Date: Tue, 20 Feb 2024 11:56:12 +0100 [thread overview]
Message-ID: <20240220105612.31058-7-mateusz.kusiak@intel.com> (raw)
In-Reply-To: <20240220105612.31058-1-mateusz.kusiak@intel.com>
Refactor mdmon main function to verify if fd is valid prior to checking
device name. This is due to static code analysis complaining after
change b938519e7719 ("util: remove obsolete code from get_md_name").
Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
---
mdmon.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/mdmon.c b/mdmon.c
index a2038fe6c35f..5fdb5cdb5a49 100644
--- a/mdmon.c
+++ b/mdmon.c
@@ -302,12 +302,12 @@ static int mdmon(char *devnm, int must_fork, int takeover);
int main(int argc, char *argv[])
{
char *container_name = NULL;
- char *devnm = NULL;
int status = 0;
int opt;
int all = 0;
int takeover = 0;
int dofork = 1;
+ int mdfd = -1;
bool help = false;
static struct option options[] = {
{"all", 0, NULL, 'a'},
@@ -410,19 +410,20 @@ int main(int argc, char *argv[])
free_mdstat(mdstat);
return status;
- } else {
- int mdfd = open_mddev(container_name, 0);
- devnm = fd2devnm(mdfd);
+ }
+
+ mdfd = open_mddev(container_name, 0);
+ if (is_fd_valid(mdfd)) {
+ char *devnm = fd2devnm(mdfd);
close(mdfd);
- }
- if (!devnm) {
- pr_err("%s is not a valid md device name\n",
- container_name);
- return 1;
+ if (devnm)
+ return mdmon(devnm, dofork && do_fork(), takeover);
}
- return mdmon(devnm, dofork && do_fork(), takeover);
+
+ pr_err("%s is not a valid md device name\n", container_name);
+ return 1;
}
static int mdmon(char *devnm, int must_fork, int takeover)
--
2.35.3
next prev parent reply other threads:[~2024-02-20 11:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-20 10:56 [PATCH 0/6] SAST fixes Mateusz Kusiak
2024-02-20 10:56 ` [PATCH 1/6] Create: add_disk_to_super() fix resource leak Mateusz Kusiak
2024-02-20 10:56 ` [PATCH 2/6] mdadm: signal_s() init variables Mateusz Kusiak
2024-02-20 10:56 ` [PATCH 3/6] Monitor: open file before check in check_one_sharer() Mateusz Kusiak
2024-02-20 10:56 ` [PATCH 4/6] Grow: remove dead condition in Grow_reshape() Mateusz Kusiak
2024-02-20 10:56 ` [PATCH 5/6] super1: check fd before passing to get_dev_size() in add_to_super1() Mateusz Kusiak
2024-02-20 10:56 ` Mateusz Kusiak [this message]
2024-02-23 11:45 ` [PATCH 0/6] SAST fixes Mariusz Tkaczyk
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=20240220105612.31058-7-mateusz.kusiak@intel.com \
--to=mateusz.kusiak@intel.com \
--cc=jes@trained-monkey.org \
--cc=linux-raid@vger.kernel.org \
--cc=mariusz.tkaczyk@linux.intel.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).