diff options
| author | Paulo Alcantara <pc@manguebit.org> | 2026-04-14 11:37:21 -0300 |
|---|---|---|
| committer | Steve French <stfrench@microsoft.com> | 2026-04-14 12:01:12 -0500 |
| commit | 15e9e00a5aa4f56ca1cff7749c166e072d7cb6ac (patch) | |
| tree | ee15cc1a45f142491136b0201ea610e46b516fc5 /fs/dcache.c | |
| parent | 81dc1e4d32b064ac47abc60b0acbf49b66a34d52 (diff) | |
| download | linux-15e9e00a5aa4f56ca1cff7749c166e072d7cb6ac.tar.gz linux-15e9e00a5aa4f56ca1cff7749c166e072d7cb6ac.zip | |
vfs: get rid of BUG_ON() in d_mark_tmpfile_name()
Do proper error handling in d_mark_tmpfile_name() by returning errors
rather than using BUG_ON()'s.
Adjust caller to check for errors from d_mark_tmpfile_name() as well
as clean it up for using return value from scnprintf() in QSTR_LEN()
to make it more obvious where the tmpfile name's length is coming
from.
Link: https://lore.kernel.org/r/CAHk-=wgerpUKCDhdzKH0FEdLyfhj3doc9t+kO9Yb6rSsTp7hdQ@mail.gmail.com
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
CC: linux-fsdevel@vger.kernel.org
Cc: linux-cifs@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
Diffstat (limited to 'fs/dcache.c')
| -rw-r--r-- | fs/dcache.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/fs/dcache.c b/fs/dcache.c index df11bbba0342..dbcbd0affb26 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -3196,15 +3196,18 @@ void d_mark_tmpfile(struct file *file, struct inode *inode) } EXPORT_SYMBOL(d_mark_tmpfile); -void d_mark_tmpfile_name(struct file *file, const struct qstr *name) +int d_mark_tmpfile_name(struct file *file, const struct qstr *name) { struct dentry *dentry = file->f_path.dentry; char *dname = dentry->d_shortname.string; - BUG_ON(dname_external(dentry)); - BUG_ON(d_really_is_positive(dentry)); - BUG_ON(!d_unlinked(dentry)); - BUG_ON(name->len > DNAME_INLINE_LEN - 1); + if (unlikely(dname_external(dentry) || + d_really_is_positive(dentry) || + !d_unlinked(dentry))) + return -EINVAL; + if (unlikely(name->len > DNAME_INLINE_LEN - 1)) + return -ENAMETOOLONG; + spin_lock(&dentry->d_parent->d_lock); spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); dentry->__d_name.len = name->len; @@ -3212,6 +3215,7 @@ void d_mark_tmpfile_name(struct file *file, const struct qstr *name) dname[name->len] = '\0'; spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_parent->d_lock); + return 0; } EXPORT_SYMBOL(d_mark_tmpfile_name); |
