]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Use unlikely() for error checks
authorMarc Rittinghaus <marc.rittinghaus@unikraft.io>
Mon, 24 Apr 2023 15:17:27 +0000 (17:17 +0200)
committerUnikraft <monkey@unikraft.io>
Tue, 2 May 2023 20:19:25 +0000 (20:19 +0000)
This commit adds the unlikely() macro to remaining error checks in
sys_utimensat().

Signed-off-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Reviewed-by: Rares Miculescu <miculescur@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #865

lib/vfscore/syscalls.c

index f02c12333721d7018647c1917ae3d69bf86ffa68..2e4b53f16b8140cf4562b67590529893bf0e098c 100644 (file)
@@ -1419,30 +1419,31 @@ sys_utimensat(int dirfd, const char *pathname, const struct timespec times[2], i
        }
 
        /* utimensat should return ENOENT when pathname is empty */
-       if(pathname && pathname[0] == 0)
+       if (unlikely(pathname && pathname[0] == 0))
                return ENOENT;
 
        /* Only the AT_SYMLINK_NOFOLLOW is allowed */
-       if (flags && !(flags & AT_SYMLINK_NOFOLLOW))
+       if (unlikely(flags & ~AT_SYMLINK_NOFOLLOW))
                return EINVAL;
 
        if (pathname && pathname[0] == '/') {
                ap = strdup(pathname);
-               if (!ap)
+               if (unlikely(!ap))
                        return ENOMEM;
 
        } else if (dirfd == AT_FDCWD) {
-               if (!pathname)
+               if (unlikely(!pathname))
                        return EFAULT;
+
                error = asprintf(&ap, "%s/%s", main_task->t_cwd, pathname);
                if (unlikely(error == -1))
                        return ENOMEM;
        } else {
                fp = vfscore_get_file(dirfd);
-               if (!fp)
+               if (unlikely(!fp))
                        return EBADF;
 
-               if (!fp->f_dentry)
+               if (unlikely(!fp->f_dentry))
                        return EBADF;
 
                if (pathname) {