smatch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Block <bblock@linux.ibm.com>
To: Mailing List linux-smatch <smatch@vger.kernel.org>
Subject: False Positive return_cast check
Date: Fri, 12 Feb 2021 13:42:54 +0100	[thread overview]
Message-ID: <YCZ3ziwJYDpZx2+l@t480-pf1aa2c2.linux.ibm.com> (raw)

Hello,

I hope this is the right avenue to report this.

I noticed yesterday that we get a false positive report from smatch for
`pathmask_to_pos()` in `arch/s390/include/asm/cio.h`. When reviewing
some code I got this error while using smatch:

    CHECK   /home/bblock/src/linux/drivers/s390/cio/device_pgid.c
  /home/bblock/src/linux/arch/s390/include/asm/cio.h:356 pathmask_to_pos() warn: signedness bug returning '(-119)'

Which corresponds to this helper:

  static inline u8 pathmask_to_pos(u8 mask)
  {
  	return 8 - ffs(mask);
  }

First I assumed this corresponds to some corner case where `ffs()` might
return a negative number, or something bigger than 8 (both are not
supposed to be possible); but I couldn't wrap my head around what
exactly the error message is supposed to tell me with `(-119)`. 

After some exhaustive head scratching I took a look at smatch itself and
found this message is emitted by `check_return_cast.c`, and according to
commit `f65a092d16cf` is supposed to warn me that we return a negative
error code via an unsigned return value type.
    That seems to be a false positive here.

Its not really something terrible important, but after I took so long to
understand what this is telling me, I thought I might as well report it.

-- 
Best Regards, Benjamin Block  / Linux on IBM Z Kernel Development / IBM Systems
IBM Deutschland Research & Development GmbH    /    https://www.ibm.com/privacy
Vorsitz. AufsR.: Gregor Pillen         /        Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: AmtsG Stuttgart, HRB 243294

             reply	other threads:[~2021-02-12 12:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 12:42 Benjamin Block [this message]
2021-02-15 12:36 ` False Positive return_cast check Dan Carpenter
2021-02-15 16:04   ` Benjamin Block

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=YCZ3ziwJYDpZx2+l@t480-pf1aa2c2.linux.ibm.com \
    --to=bblock@linux.ibm.com \
    --cc=smatch@vger.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).