From: Andrea Claudi Date: Mon, 22 Feb 2021 18:14:31 +0000 (+0100) Subject: lib/fs: avoid double call to mkdir on make_path() X-Git-Tag: v5.11.0~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1de363b1800c371037ff2b2a6c1004627e58f68e;p=thirdparty%2Fiproute2.git lib/fs: avoid double call to mkdir on make_path() 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. Fixes: ac3415f5c1b1d ("lib/fs: Fix and simplify make_path()") Acked-by: Phil Sutter Signed-off-by: Andrea Claudi Signed-off-by: Stephen Hemminger --- diff --git a/lib/fs.c b/lib/fs.c index 4b90a7046..2ae506ecc 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;