]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fs: constify file ptr in backing_file accessor helpers
authorAmir Goldstein <amir73il@gmail.com>
Sat, 7 Jun 2025 11:53:03 +0000 (13:53 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 18 Jul 2025 09:09:29 +0000 (11:09 +0200)
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>
fs/backing-file.c
fs/file_table.c
fs/internal.h
include/linux/fs.h

index 763fbe9b72b22753a5b90ac673b10ebb2527403f..8c7396bff121b334d617e0535cc6339fce9e0cd0 100644 (file)
@@ -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);
index 138114d643077118948b4902cffb933ff7ee901e..f09d79a981115bc58746acece9205526c17cdfdd 100644 (file)
@@ -52,17 +52,20 @@ struct backing_file {
        };
 };
 
-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 file_free(struct file *f)
 {
        security_file_free(f);
index 393f6c5c24f6b87ede28ca72764e8d50e0972f65..d733d8bb3d1f89ea180f682040556ef2503dbb9a 100644 (file)
@@ -101,6 +101,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)
 {
index 1d9586a78041bc1e4b7ffed49c5b4db0db76ff78..8116b1080457ffbe8a5648220c2358ae9f59a524 100644 (file)
@@ -2864,7 +2864,7 @@ struct file *dentry_open_nonotify(const struct path *path, int flags,
                                  const struct cred *cred);
 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
@@ -2876,14 +2876,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);