All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Liam.Howlett@oracle.com
Cc: linux-mm@kvack.org
Subject: [bug report] Maple Tree: add new data structure
Date: Tue, 19 Jul 2022 12:36:36 +0300	[thread overview]
Message-ID: <YtZ7JO6noz2QduUX@kili> (raw)

Hello Liam R. Howlett,

The patch 058c2f0f755f: "Maple Tree: add new data structure" from Jul
17, 2022, leads to the following Smatch static checker warning:

	lib/maple_tree.c:6969 mas_validate_limits()
	warn: add some parenthesis here? '!piv & (i != 0)'

lib/maple_tree.c
    6952 static void mas_validate_limits(struct ma_state *mas)
    6953 {
    6954         int i;
    6955         unsigned long prev_piv = 0;
    6956         enum maple_type type = mte_node_type(mas->node);
    6957         void __rcu **slots = ma_slots(mte_to_node(mas->node), type);
    6958         unsigned long *pivots = ma_pivots(mas_mn(mas), type);
    6959 
    6960         /* all limits are fine here. */
    6961         if (mte_is_root(mas->node))
    6962                 return;
    6963 
    6964         for (i = 0; i < mt_slots[type]; i++) {
    6965                 unsigned long piv;
    6966 
    6967                 piv = mas_safe_pivot(mas, pivots, i, type);
    6968 
--> 6969                 if (!piv & (i != 0))

Sparse and Smatch both hate this.  I think this code is correct and it
should be:

		if ((!piv) & (i != 0))

However the vast majority of the time this warning indicates a
precendence bug where what was intended was:

	if (!(piv & (i != 0)))


I guess it's not common to use booleans for bitwise ANDs...

    6970                         break;
    6971 
    6972                 if (!mte_is_leaf(mas->node)) {

regards,
dan carpenter


             reply	other threads:[~2022-07-19  9:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19  9:36 Dan Carpenter [this message]
2022-07-19 13:37 ` [bug report] Maple Tree: add new data structure Liam Howlett

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=YtZ7JO6noz2QduUX@kili \
    --to=dan.carpenter@oracle.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=linux-mm@kvack.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.