Messages in this thread | | | Date | Wed, 11 Apr 2018 19:00:49 +0200 | From | Peter Zijlstra <> | Subject | Re: [PATCH] checkpatch: Add a --strict test for structs with bool member definitions |
| |
On Wed, Apr 11, 2018 at 09:29:59AM -0700, Andrew Morton wrote: > > OK. I guess. But I'm not really seeing some snappy description which > helps people understand why checkpatch is warning about this.
"Results in architecture dependent layout."
is the best short sentence I can come up with.
> We already have some 500 bools-in-structs and the owners of that code > will be wondering whether they should change them, and whether they > should apply those remove-bool-in-struct patches which someone sent > them.
I still have room in my /dev/null mailbox for pure checkpatch patches.
> (ooh, https://lkml.org/lkml/2017/11/21/384 is working this morning)
Yes, we really should not use lkml.org for references. Sadly google displays it very prominently when you search for something.
> hm, Linus suggests that instead of using > > bool mybool; > > we should use > > unsigned mybool:1; > > However that introduces the risk that alterations of mybool will use > nonatomic rmw operations. > > unsigned myboolA:1; > unsigned myboolB:1; > > so > > foo->myboolA = 1; > > could scribble on concurrent alterations of foo->myboolB. I think.
So that is true of u8 on Alpha <EV56 too. If you want concurrent, you had better know what you're doing.
> I guess that risk is also present if myboolA and myboolB were `bool', > too. The compiler could do any old thing with them including, perhaps, > using a single-bit bitfield(?).
The smallest addressable type in C is a byte, so while _Bool may be larger than a byte, it cannot be smaller. Otherwise we could not write:
_Bool var; _Boll *ptr = &var;
Which is something that comes apart with bitfields.
| |