Skip to content

Commit 90b2433

Browse files
mairacanalAl Viro
authored and
Al Viro
committed
seq_file: fix NULL pointer arithmetic warning
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 <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 6692531 commit 90b2433

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

fs/kernfs/file.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,8 @@ static void *kernfs_seq_start(struct seq_file *sf, loff_t *ppos)
120120
if (next == ERR_PTR(-ENODEV))
121121
kernfs_seq_stop_active(sf, next);
122122
return next;
123-
} else {
124-
/*
125-
* The same behavior and code as single_open(). Returns
126-
* !NULL if pos is at the beginning; otherwise, NULL.
127-
*/
128-
return NULL + !*ppos;
129123
}
124+
return single_start(sf, ppos);
130125
}
131126

132127
static void *kernfs_seq_next(struct seq_file *sf, void *v, loff_t *ppos)

fs/seq_file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, const char *esc)
554554
}
555555
EXPORT_SYMBOL(seq_dentry);
556556

557-
static void *single_start(struct seq_file *p, loff_t *pos)
557+
void *single_start(struct seq_file *p, loff_t *pos)
558558
{
559-
return NULL + (*pos == 0);
559+
return *pos ? NULL : SEQ_START_TOKEN;
560560
}
561561

562562
static void *single_next(struct seq_file *p, void *v, loff_t *pos)

include/linux/seq_file.h

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ int seq_dentry(struct seq_file *, struct dentry *, const char *);
162162
int seq_path_root(struct seq_file *m, const struct path *path,
163163
const struct path *root, const char *esc);
164164

165+
void *single_start(struct seq_file *, loff_t *);
165166
int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
166167
int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
167168
int single_release(struct inode *, struct file *);

0 commit comments

Comments
 (0)