diff options
| author | Amir Goldstein <amir73il@gmail.com> | 2026-06-29 15:03:36 +0800 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2026-07-04 13:43:31 +0200 |
| commit | 28f020bce41540e6cb27ee2565929c75d11e28d1 (patch) | |
| tree | afe92af2a55eeaec58d762c35fbe0ae01fe12601 | |
| parent | 46f201f8b4c39633a1fa3dc12459f506d470993d (diff) | |
| download | linux-stable-28f020bce41540e6cb27ee2565929c75d11e28d1.tar.gz linux-stable-28f020bce41540e6cb27ee2565929c75d11e28d1.zip | |
fs: constify file ptr in backing_file accessor helpers
[ Upstream commit 4e301d858af17ae2ce56886296e5458c5a08219a ]
Add internal helper backing_file_set_user_path() for the only
two cases that need to modify backing_file fields.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://lore.kernel.org/20250607115304.2521155-2-amir73il@gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
| -rw-r--r-- | fs/backing-file.c | 4 | ||||
| -rw-r--r-- | fs/file_table.c | 13 | ||||
| -rw-r--r-- | fs/internal.h | 1 | ||||
| -rw-r--r-- | include/linux/fs.h | 6 |
4 files changed, 14 insertions, 10 deletions
diff --git a/fs/backing-file.c b/fs/backing-file.c index 09a9be945d45..892361c31c3d 100644 --- a/fs/backing-file.c +++ b/fs/backing-file.c @@ -41,7 +41,7 @@ struct file *backing_file_open(const struct path *user_path, int flags, return f; path_get(user_path); - *backing_file_user_path(f) = *user_path; + backing_file_set_user_path(f, user_path); error = vfs_open(real_path, f); if (error) { fput(f); @@ -65,7 +65,7 @@ struct file *backing_tmpfile_open(const struct path *user_path, int flags, return f; path_get(user_path); - *backing_file_user_path(f) = *user_path; + backing_file_set_user_path(f, user_path); error = vfs_tmpfile(real_idmap, real_parentpath, f, mode); if (error) { fput(f); diff --git a/fs/file_table.c b/fs/file_table.c index 2a08bc93b0b9..75a1908d51a9 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -48,17 +48,20 @@ struct backing_file { struct path user_path; }; -static inline struct backing_file *backing_file(struct file *f) -{ - return container_of(f, struct backing_file, file); -} +#define backing_file(f) container_of(f, struct backing_file, file) -struct path *backing_file_user_path(struct file *f) +struct path *backing_file_user_path(const struct file *f) { return &backing_file(f)->user_path; } EXPORT_SYMBOL_GPL(backing_file_user_path); +void backing_file_set_user_path(struct file *f, const struct path *path) +{ + backing_file(f)->user_path = *path; +} +EXPORT_SYMBOL_GPL(backing_file_set_user_path); + static inline void backing_file_free(struct backing_file *ff) { path_put(&ff->user_path); diff --git a/fs/internal.h b/fs/internal.h index 8c1b7acbbe8f..a4352d333c61 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -100,6 +100,7 @@ extern void chroot_fs_refs(const struct path *, const struct path *); struct file *alloc_empty_file(int flags, const struct cred *cred); struct file *alloc_empty_file_noaccount(int flags, const struct cred *cred); struct file *alloc_empty_backing_file(int flags, const struct cred *cred); +void backing_file_set_user_path(struct file *f, const struct path *path); static inline void file_put_write_access(struct file *file) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 87720e1b5419..70bbc00a2bd2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2738,7 +2738,7 @@ struct file *dentry_open(const struct path *path, int flags, const struct cred *creds); struct file *dentry_create(const struct path *path, int flags, umode_t mode, const struct cred *cred); -struct path *backing_file_user_path(struct file *f); +struct path *backing_file_user_path(const struct file *f); /* * When mmapping a file on a stackable filesystem (e.g., overlayfs), the file @@ -2750,14 +2750,14 @@ struct path *backing_file_user_path(struct file *f); * by fstat() on that same fd. */ /* Get the path to display in /proc/<pid>/maps */ -static inline const struct path *file_user_path(struct file *f) +static inline const struct path *file_user_path(const struct file *f) { if (unlikely(f->f_mode & FMODE_BACKING)) return backing_file_user_path(f); return &f->f_path; } /* Get the inode whose inode number to display in /proc/<pid>/maps */ -static inline const struct inode *file_user_inode(struct file *f) +static inline const struct inode *file_user_inode(const struct file *f) { if (unlikely(f->f_mode & FMODE_BACKING)) return d_inode(backing_file_user_path(f)->dentry); |
