lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190114172603.GF22875@mellanox.com>
Date:   Mon, 14 Jan 2019 17:26:10 +0000
From:   Jason Gunthorpe <jgg@...lanox.com>
To:     Matthew Wilcox <willy@...radead.org>
CC:     Joe Perches <joe@...ches.com>, Gal Pressman <galpress@...zon.com>,
        Bart Van Assche <bvanassche@....org>,
        Stephen Warren <swarren@...dotorg.org>,
        Tariq Toukan <tariqt@...lanox.com>,
        "xavier.huwei@...wei.com" <xavier.huwei@...wei.com>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        "linux-rdma@...r.kernel.org" <linux-rdma@...r.kernel.org>,
        Doug Ledford <dledford@...hat.com>,
        Stephen Warren <swarren@...dia.com>,
        Christoph Hellwig <hch@....de>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        "linux-doc@...r.kernel.org" <linux-doc@...r.kernel.org>,
        Jonathan Corbet <corbet@....net>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4] coding-style: Clarify the expectations around bool

On Sun, Jan 13, 2019 at 08:49:36AM -0800, Matthew Wilcox wrote:
> On Thu, Jan 10, 2019 at 11:48:13PM +0000, Jason Gunthorpe wrote:
> > +The Linux kernel bool type is an alias for the C99 _Bool type. bool values can
> > +only evaluate to 0 or 1, and implicit or explicit conversion to bool
> > +automatically converts the value to true or false. When using bool types the
> > +!! construction is not needed, which eliminates a class of bugs.
> > +
> > +When working with bool values the true and false definitions should be used
> > +instead of 0 and 1.
> > +
> > +bool function return types and stack variables are always fine to use whenever
> > +appropriate. Use of bool is encouraged to improve readability and is often a
> > +better option than 'int' for storing boolean values.
> 
> It's awkward to start a sentence with a lower case letter.  How about
> rephrasing this paragraph and the following one as:
> 
>   Using bool as the return type of a function or as a variable is always
>   fine when appropriate.  It often improves readability and is a better option
>   than int for storing boolean values.  Using bool in data structures is
>   more debatable; its size and alignment can vary between architectures.

This is more concise, but I think if the coding style is not going to
give a concrete advise then it should at least provide some general
information so the reader can try and make an informed choice.

That is why I had it expand on some of the rationals a little bit,
along with a concrete direction to not use bool in the cases Linus
specifically called out.

> > +Do not use bool if cache line layout or size of the value matters, its size
> > +and alignment varies based on the compiled architecture. Structures that are
> > +optimized for alignment and size should not use bool.
> > +
> > +If a structure has many true/false values, consider consolidating them into a
> > +bitfield with 1 bit members, or using an appropriate fixed width type, such as
> > +u8.

JAson

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ