From: Dan Carpenter <error27@gmail.com>
To: Alex Elder <alex.elder@linaro.org>
Cc: elder@linaro.org, kernel-janitors@vger.kernel.org
Subject: Re: [bug report] net: ipa: reduce arguments to ipa_table_init_add()
Date: Sat, 19 Nov 2022 13:48:17 +0300 [thread overview]
Message-ID: <Y3i0cUmRbxikVRwS@kadam> (raw)
In-Reply-To: <8d3eba21-7950-7179-91f1-75a2529117e0@linaro.org>
On Sat, Nov 19, 2022 at 03:21:48AM -0600, Alex Elder wrote:
> On 11/18/22 03:50, Dan Carpenter wrote:
> > On Thu, Nov 17, 2022 at 07:47:27AM +0300, Dan Carpenter wrote:
> > > Heh. It really feels like this line should have generated a checker
> > > warning as well. I've created two versions. The first complains when
> > > ever there is a divide used as a condition:
> > >
> > > if (a / b) {
> > >
> > > The other complains when it's part of a logical && or ||.
> > >
> > > if (a && a / b) {
> > >
> > > drivers/net/ipa/ipa_table.c:414 ipa_table_init_add() warn: divide condition: 'hash_mem->size / 8'
> > > drivers/net/ipa/ipa_table.c:414 ipa_table_init_add() warn: divide condition (logical): 'hash_mem->size / 8'
> > >
> > > I'll test them out tonight and see if either gives useful results.
> >
> > I modified the test to ignore macros. Otherwise we get warnings where
> > macros are trying to avoid divide by zero bugs. There was no advantage
> > in treating logicals as special so I dropped that.
> >
> > The results are kind of mind bending. I think maybe people sometimes
> > accidentally write "if (a / b) {" meaning does it divide cleanly? When
> > that should be written as: "if ((a % b) == 0) {".
>
> Interesting. I looked at the first few. I think the nvdimm ones
> might be using "if (cleared / 512)" to mean "if (cleared >= 512",
> and in that case, the >= might actually be more efficient than the
> divide. On the real-time clock one it looked like a similar usage.
> Regardless, it's not a typical idiom so I don't think it's
> straightforward to understand.
Yeah. I'm going to publish the check and the new warning message will
be:
drivers/nvdimm/claim.c:287 nsio_rw_bytes() warn: replace divide condition 'cleared / 512' with 'cleared >= 512'
regards,
dan carpenter
next prev parent reply other threads:[~2022-11-19 10:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 13:03 [bug report] net: ipa: reduce arguments to ipa_table_init_add() Dan Carpenter
2022-11-15 17:00 ` Alex Elder
2022-11-17 4:47 ` Dan Carpenter
2022-11-18 9:50 ` Dan Carpenter
2022-11-19 9:21 ` Alex Elder
2022-11-19 10:48 ` Dan Carpenter [this message]
2022-11-19 9:04 ` Alex Elder
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=Y3i0cUmRbxikVRwS@kadam \
--to=error27@gmail.com \
--cc=alex.elder@linaro.org \
--cc=elder@linaro.org \
--cc=kernel-janitors@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 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.