From: Christian Brauner Date: Tue, 30 Apr 2024 11:54:46 +0000 (+0200) Subject: fs: new helper vfs_empty_path() X-Git-Tag: v6.11-rc1~242^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1bc6d4452d5c91beb09e37a98a590808e1997b79;p=thirdparty%2Fkernel%2Flinux.git fs: new helper vfs_empty_path() Make it possible to quickly check whether AT_EMPTY_PATH is valid. Note, after some discussion we decided to also allow NULL to be passed instead of requiring the empty string. Signed-off-by: Christian Brauner --- diff --git a/include/linux/fs.h b/include/linux/fs.h index 942cb11dba961..5ff362277834c 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3631,4 +3631,21 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len, extern int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice); +static inline bool vfs_empty_path(int dfd, const char __user *path) +{ + char c; + + if (dfd < 0) + return false; + + /* We now allow NULL to be used for empty path. */ + if (!path) + return true; + + if (unlikely(get_user(c, path))) + return false; + + return !c; +} + #endif /* _LINUX_FS_H */