mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: "Maíra Canal" <maira.canal@usp.br>
Cc: gregkh@linuxfoundation.org, tj@kernel.org, nathan@kernel.org,
	ndesaulniers@google.com, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, llvm@lists.linux.dev
Subject: Re: [PATCH] seq_file: fix NULL pointer arithmetic warning
Date: Sun, 30 Jan 2022 17:22:36 +0000	[thread overview]
Message-ID: <YfbJXCWSkc5nSNHC@zeniv-ca.linux.org.uk> (raw)
In-Reply-To: <YfauRJpYiAT3yEnK@fedora>

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.

      reply	other threads:[~2022-01-30 17:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-30 15:27 Maíra Canal
2022-01-30 17:22 ` Al Viro [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YfbJXCWSkc5nSNHC@zeniv-ca.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=maira.canal@usp.br \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome