blk_stack_limits() contains:
t->zoned = max(t->zoned, b->zoned);
These are bool, so it is just a bitwise or.
However it generates:
error: comparison of constant ‘0’ with boolean expression is always true [-Werror=bool-compare]
inside the signedness check that max() does unless a '+ 0' is added.
It is a shame the compiler generates this warning for code that will
be optimised away.
Change so that the extra '+ 0' can be removed.
Signed-off-by: David Laight <david.laight@aculab.com>
---
block/blk-settings.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 06ea91e51b8b..9ca21fea039d 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -688,7 +688,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
b->max_secure_erase_sectors);
t->zone_write_granularity = max(t->zone_write_granularity,
b->zone_write_granularity);
- t->zoned = max(t->zoned, b->zoned);
+ t->zoned = t->zoned | b->zoned;
return ret;
}
EXPORT_SYMBOL(blk_stack_limits);
--
2.17.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
On Sun, 28 Jan 2024, David Laight <David.Laight@ACULAB.COM> wrote: > blk_stack_limits() contains: > t->zoned = max(t->zoned, b->zoned); > These are bool, so it is just a bitwise or. Should be a logical or, really. And || in code. BR, Jani. > However it generates: > error: comparison of constant ‘0’ with boolean expression is always true [-Werror=bool-compare] > inside the signedness check that max() does unless a '+ 0' is added. > It is a shame the compiler generates this warning for code that will > be optimised away. > > Change so that the extra '+ 0' can be removed. > > Signed-off-by: David Laight <david.laight@aculab.com> > --- > block/blk-settings.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/block/blk-settings.c b/block/blk-settings.c > index 06ea91e51b8b..9ca21fea039d 100644 > --- a/block/blk-settings.c > +++ b/block/blk-settings.c > @@ -688,7 +688,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, > b->max_secure_erase_sectors); > t->zone_write_granularity = max(t->zone_write_granularity, > b->zone_write_granularity); > - t->zoned = max(t->zoned, b->zoned); > + t->zoned = t->zoned | b->zoned; > return ret; > } > EXPORT_SYMBOL(blk_stack_limits); -- Jani Nikula, Intel
From: Jani Nikula > Sent: 29 January 2024 09:08 > > On Sun, 28 Jan 2024, David Laight <David.Laight@ACULAB.COM> wrote: > > blk_stack_limits() contains: > > t->zoned = max(t->zoned, b->zoned); > > These are bool, so it is just a bitwise or. > > Should be a logical or, really. And || in code. Not really, bitwise is fine for bool (especially for 'or') and generates better code. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Mon, Jan 29, 2024 at 09:22:40AM +0000, David Laight wrote: > From: Jani Nikula > > Sent: 29 January 2024 09:08 > > > > On Sun, 28 Jan 2024, David Laight <David.Laight@ACULAB.COM> wrote: > > > blk_stack_limits() contains: > > > t->zoned = max(t->zoned, b->zoned); > > > These are bool, so it is just a bitwise or. > > > > Should be a logical or, really. And || in code. > > Not really, bitwise is fine for bool (especially for 'or') > and generates better code. For | vs || the type doesn't make a difference... It makes a difference for AND. "0x1 & 0x10" vs "0x1 && 0x10". regards, dan carpenter
On Mon, 29 Jan 2024, David Laight <David.Laight@ACULAB.COM> wrote: > From: Jani Nikula >> Sent: 29 January 2024 09:08 >> >> On Sun, 28 Jan 2024, David Laight <David.Laight@ACULAB.COM> wrote: >> > blk_stack_limits() contains: >> > t->zoned = max(t->zoned, b->zoned); >> > These are bool, so it is just a bitwise or. >> >> Should be a logical or, really. And || in code. > > Not really, bitwise is fine for bool (especially for 'or') > and generates better code. Logical operations for booleans are more readable for humans than bitwise. And semantically correct. With a = b || c you know what happens regardless of the types in question. a = b | c you have to look up the types to know what's going on. To me, better code only matters if it's a hotpath. That said, not my are of maintenance, so *shrug*. BR, Jani. -- Jani Nikula, Intel
On Sun, 28 Jan 2024 at 11:36, David Laight <David.Laight@aculab.com> wrote:
>
> However it generates:
> error: comparison of constant ‘0’ with boolean expression is always true [-Werror=bool-compare]
> inside the signedness check that max() does unless a '+ 0' is added.
Please fix your locale. You have random garbage characters there,
presumably because you have some incorrect locale setting somewhere in
your toolchain.
Linus
From: Linus Torvalds > Sent: 28 January 2024 19:59 > > On Sun, 28 Jan 2024 at 11:36, David Laight <David.Laight@aculab.com> wrote: > > > > However it generates: > > error: comparison of constant ‘0’ with boolean expression is always true [-Werror=bool-compare] > > inside the signedness check that max() does unless a '+ 0' is added. > > Please fix your locale. You have random garbage characters there, > presumably because you have some incorrect locale setting somewhere in > your toolchain. Hmmmm blame gcc :-) The error message displays as '0' but is e2:80:98 30 e2:80:99 I HATE UTF-8, it wouldn't be as bad if it were a bijection. Lets see if adding 'LANG=C' in the shell script I use to do kernel builds is enough. I also managed to send parts 1 to 6 without deleting the RE: (I have to cut&paste from wordpad into a 'reply-all' of the first message I send. Work uses mimecast and it has started bouncing my copy of every message I send to the lists.) Maybe I should start using telnet to send raw SMTP :-) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
On Sun, 28 Jan 2024 at 14:22, David Laight <David.Laight@aculab.com> wrote:
>
> Hmmmm blame gcc :-)
I do agree that the gcc warning quoting is unnecessarily ugly (even
just visually), but..
> The error message displays as '0' but is e2:80:98 30 e2:80:99
> I HATE UTF-8, it wouldn't be as bad if it were a bijection.
No, that's not the problem. The UTF-8 that gcc emits is fine.
And your email was also UTF-8:
Content-Type: text/plain; charset=UTF-8
The problem is that you clearly then used some other tool in between
that took the UTF-8 byte stream, and used it as (presumably) Latin1,
which is bogus.
If you just make everything use and stay as UTF-8, it all works out
beautifully. But I suspect you have an editor or a MUA that is fixed
in some 1980s mindset, and when you cut-and-pasted the UTF-8, it
treated it as Latin1.
Just make all your environment be utf-8, like it should be. It's not
the 80s any more. We don't do mullets, and we don't do Latin1, ok?
Linus
© 2016 - 2025 Red Hat, Inc.