]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
seq_file: fix NULL pointer arithmetic warning
authorMaíra Canal <maira.canal@usp.br>
Mon, 31 Jan 2022 18:22:42 +0000 (15:22 -0300)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 1 Feb 2022 16:31:55 +0000 (11:31 -0500)
Implement conditional logic in order to replace NULL pointer arithmetic.

The use of NULL pointer arithmetic was pointed out by clang with the
following warning:

fs/kernfs/file.c:128:15: warning: performing pointer arithmetic on a
null pointer has undefined behavior [-Wnull-pointer-arithmetic]
                return NULL + !*ppos;
                       ~~~~ ^
fs/seq_file.c:559:14: warning: performing pointer arithmetic on a
null pointer has undefined behavior [-Wnull-pointer-arithmetic]
        return NULL + (*pos == 0);

Signed-off-by: Maíra Canal <maira.canal@usp.br>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/kernfs/file.c
fs/seq_file.c
include/linux/seq_file.h

index 9414a7a60a9f44c9f7db8ac2df365a10e9d81647..7aefaca876a0248de8a8d6ca3045d2166166aea2 100644 (file)
@@ -120,13 +120,8 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
                if (next == ERR_PTR(-ENODEV))
                        kernfs_seq_stop_active(sf, next);
                return next;
-       } else {
-               /*
-                * The same behavior and code as single_open().  Returns
-                * !NULL if pos is at the beginning; otherwise, NULL.
-                */
-               return NULL + !*ppos;
        }
+       return single_start(sf, ppos);
 }
 
 static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)
index f8e1f4ee87ffca16ee019b4dcd0d29c4fd3fdef3..7ab8a58c29b618b9ead091266dd5b4c55f58c0cb 100644 (file)
@@ -554,9 +554,9 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, const char *esc)
 }
 EXPORT_SYMBOL(seq_dentry);
 
-static void *single_start(struct seq_file *p, loff_t *pos)
+void *single_start(struct seq_file *p, loff_t *pos)
 {
-       return NULL + (*pos == 0);
+       return *pos ? NULL : SEQ_START_TOKEN;
 }
 
 static void *single_next(struct seq_file *p, void *v, loff_t *pos)
index 88cc16444b43125e5fbd274868013fe29869e465..60820ab511d224f3bb655b0a43459591eae6821e 100644 (file)
@@ -162,6 +162,7 @@ int seq_dentry(struct seq_file *, struct dentry *, const char *);
 int seq_path_root(struct seq_file *m, const struct path *path,
                  const struct path *root, const char *esc);
 
+void *single_start(struct seq_file *, loff_t *);
 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
 int single_release(struct inode *, struct file *);