Skip to content

Commit 1bc6d44

Browse files
committed
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 <[email protected]>
1 parent 9fb9ff7 commit 1bc6d44

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

include/linux/fs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,4 +3631,21 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len,
36313631
extern int generic_fadvise(struct file *file, loff_t offset, loff_t len,
36323632
int advice);
36333633

3634+
static inline bool vfs_empty_path(int dfd, const char __user *path)
3635+
{
3636+
char c;
3637+
3638+
if (dfd < 0)
3639+
return false;
3640+
3641+
/* We now allow NULL to be used for empty path. */
3642+
if (!path)
3643+
return true;
3644+
3645+
if (unlikely(get_user(c, path)))
3646+
return false;
3647+
3648+
return !c;
3649+
}
3650+
36343651
#endif /* _LINUX_FS_H */

0 commit comments

Comments
 (0)