lkml.org 
[lkml]   [2022]   [Jan]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] seq_file: fix NULL pointer arithmetic warning
On Sun, Jan 30, 2022 at 12:27:00PM -0300, Maíra Canal wrote:
> 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);

NAK. _If_ you want to bother with that at all, at least make it
use SEQ_START_TOKEN, rather than open-coding it; what's more,
kernfs_seq_start() should simply call single_start() instead of
open-coding it. I.e.
if (ops->seq_start) {
void *next = ops->seq_start(sf, ppos);
/* see the comment above kernfs_seq_stop_active() */
if (next == ERR_PTR(-ENODEV))
kernfs_seq_stop_active(sf, next);
return next;
} else {
return single_start(sf, ppos);
}
and
return *ppos ? NULL : SEQ_START_TOKEN;
in single_start() itself.

\
 
 \ /
  Last update: 2022-01-30 18:23    [W:0.031 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site