* [bug report] lib: introduce test_meminit module
@ 2026-04-30 18:14 Dan Carpenter
2026-05-04 7:36 ` Alexander Potapenko
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2026-04-30 18:14 UTC (permalink / raw)
To: Alexander Potapenko; +Cc: kernel-janitors
Hello Alexander Potapenko,
Commit 5015a300a522 ("lib: introduce test_meminit module") from Jul
16, 2019 (linux-next), leads to the following Smatch static checker
warning:
lib/test_meminit.c:390 test_kmemcache()
warn: bool mask is always false 'ctor & zero'
lib/test_meminit.c
378 static int __init test_kmemcache(int *total_failures)
379 {
380 int failures = 0, num_tests = 0;
381 int i, flags, size;
382 bool ctor, rcu, zero;
383
384 for (i = 0; i < 10; i++) {
385 size = 8 << i;
386 for (flags = 0; flags < 8; flags++) {
387 ctor = flags & 1;
388 rcu = flags & 2;
389 zero = flags & 4;
--> 390 if (ctor & zero)
^^^^^^^^^^^
This is like (BIT(1) & BIT(4)) so it can't be true. Was && intended?
391 continue;
392 num_tests += do_kmem_cache_size(size, ctor, rcu, zero,
393 &failures);
394 }
395 num_tests += do_kmem_cache_size_bulk(size, &failures);
396 }
397 REPORT_FAILURES_IN_FN();
398 *total_failures += failures;
399 return num_tests;
400 }
This email is a free service from the Smatch-CI project [smatch.sf.net].
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [bug report] lib: introduce test_meminit module
2026-04-30 18:14 [bug report] lib: introduce test_meminit module Dan Carpenter
@ 2026-05-04 7:36 ` Alexander Potapenko
2026-05-04 9:19 ` Alexander Potapenko
0 siblings, 1 reply; 3+ messages in thread
From: Alexander Potapenko @ 2026-05-04 7:36 UTC (permalink / raw)
To: Dan Carpenter; +Cc: kernel-janitors
On Thu, Apr 30, 2026 at 8:15 PM Dan Carpenter <error27@gmail.com> wrote:
>
> Hello Alexander Potapenko,
>
> Commit 5015a300a522 ("lib: introduce test_meminit module") from Jul
> 16, 2019 (linux-next), leads to the following Smatch static checker
> warning:
>
> lib/test_meminit.c:390 test_kmemcache()
> warn: bool mask is always false 'ctor & zero'
>
> lib/test_meminit.c
> 378 static int __init test_kmemcache(int *total_failures)
> 379 {
> 380 int failures = 0, num_tests = 0;
> 381 int i, flags, size;
> 382 bool ctor, rcu, zero;
> 383
> 384 for (i = 0; i < 10; i++) {
> 385 size = 8 << i;
> 386 for (flags = 0; flags < 8; flags++) {
> 387 ctor = flags & 1;
> 388 rcu = flags & 2;
> 389 zero = flags & 4;
> --> 390 if (ctor & zero)
> ^^^^^^^^^^^
> This is like (BIT(1) & BIT(4)) so it can't be true. Was && intended?
Whoa, thanks!
I wonder why Clang never complained about that.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [bug report] lib: introduce test_meminit module
2026-05-04 7:36 ` Alexander Potapenko
@ 2026-05-04 9:19 ` Alexander Potapenko
0 siblings, 0 replies; 3+ messages in thread
From: Alexander Potapenko @ 2026-05-04 9:19 UTC (permalink / raw)
To: Dan Carpenter; +Cc: kernel-janitors
On Mon, May 4, 2026 at 9:36 AM Alexander Potapenko <glider@google.com> wrote:
>
> On Thu, Apr 30, 2026 at 8:15 PM Dan Carpenter <error27@gmail.com> wrote:
> >
> > Hello Alexander Potapenko,
> >
> > Commit 5015a300a522 ("lib: introduce test_meminit module") from Jul
> > 16, 2019 (linux-next), leads to the following Smatch static checker
> > warning:
> >
> > lib/test_meminit.c:390 test_kmemcache()
> > warn: bool mask is always false 'ctor & zero'
> >
> > lib/test_meminit.c
> > 378 static int __init test_kmemcache(int *total_failures)
> > 379 {
> > 380 int failures = 0, num_tests = 0;
> > 381 int i, flags, size;
> > 382 bool ctor, rcu, zero;
> > 383
> > 384 for (i = 0; i < 10; i++) {
> > 385 size = 8 << i;
> > 386 for (flags = 0; flags < 8; flags++) {
> > 387 ctor = flags & 1;
> > 388 rcu = flags & 2;
> > 389 zero = flags & 4;
> > --> 390 if (ctor & zero)
> > ^^^^^^^^^^^
> > This is like (BIT(1) & BIT(4)) so it can't be true. Was && intended?
Well, in fact I think the "(BIT(1) & BIT(4))" part is incorrect.
Both `ctor` and `zero` are _Bool, so their values are converted to 0/1
before `ctor & zero` is calculated.
So while the code is smelly (because it uses `&` on a bool type) and
needs fixing, the warning generated by Smatch is also misleading.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-04 9:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 18:14 [bug report] lib: introduce test_meminit module Dan Carpenter
2026-05-04 7:36 ` Alexander Potapenko
2026-05-04 9:19 ` Alexander Potapenko
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.