netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrea Claudi <aclaudi@redhat.com>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, dsahern@gmail.com
Subject: [PATCH iproute2 1/2] lib/fs: avoid double call to mkdir on make_path()
Date: Fri, 18 Dec 2020 20:09:22 +0100	[thread overview]
Message-ID: <625c55227b1f4e03320940cb087e466f019ca67e.1608315719.git.aclaudi@redhat.com> (raw)
In-Reply-To: <cover.1608315719.git.aclaudi@redhat.com>

make_path() function calls mkdir two times in a row. The first one it
stores mkdir return code, and then it calls it again to check for errno.

This seems unnecessary, as we can use the return code from the first
call and check for errno if not 0.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
---
 lib/fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/fs.c b/lib/fs.c
index 4b90a704..2ae506ec 100644
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -253,7 +253,7 @@ int make_path(const char *path, mode_t mode)
 			*delim = '\0';
 
 		rc = mkdir(dir, mode);
-		if (mkdir(dir, mode) != 0 && errno != EEXIST) {
+		if (rc && errno != EEXIST) {
 			fprintf(stderr, "mkdir failed for %s: %s\n",
 				dir, strerror(errno));
 			goto out;
-- 
2.29.2


  reply	other threads:[~2020-12-18 19:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-18 19:09 [PATCH iproute2 0/2] Some fixes to lib/fs.c Andrea Claudi
2020-12-18 19:09 ` Andrea Claudi [this message]
2020-12-18 22:59   ` [PATCH iproute2 1/2] lib/fs: avoid double call to mkdir on make_path() Phil Sutter
2020-12-18 19:09 ` [PATCH iproute2 2/2] lib/fs: Fix single return points for get_cgroup2_* Andrea Claudi
2020-12-18 23:08   ` Phil Sutter
2020-12-18 23:29     ` Andrea Claudi

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=625c55227b1f4e03320940cb087e466f019ca67e.1608315719.git.aclaudi@redhat.com \
    --to=aclaudi@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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).