public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: Mark Brown <broonie@kernel.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Matti Vaittinen <mazziesaccount@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 01/12] regmap-irq: Convert bool bitfields to unsigned int
Date: Fri, 24 Jun 2022 15:31:15 +0100	[thread overview]
Message-ID: <duS4BsAjcIRLiWV6ym9lJgPbPrOrefWf@localhost> (raw)
In-Reply-To: <ca26910886a765dd7edc4815ef90bedbd0f99a95.camel@perches.com>


Joe Perches <joe@perches.com> writes:

> On Fri, 2022-06-24 at 14:05 +0100, Aidan MacDonald wrote:
>> Joe Perches <joe@perches.com> writes:
>> 
>> > On Fri, 2022-06-24 at 13:11 +0100, Mark Brown wrote:
>> > > On Thu, Jun 23, 2022 at 11:26:10PM +0200, Andy Shevchenko wrote:
>> > > > On Thu, Jun 23, 2022 at 11:13 PM Aidan MacDonald
>> > > 
>> > > > > Use 'unsigned int' for bitfields for consistency with most other
>> > > > > kernel code.
>> > > 
>> > > > There is no point to convert the fields you are about to remove.
>> > > 
>> > > > So, either don't touch them or make this patch closer to the end of the series.
>> > > 
>> > > It costs us nothing to convert them, this isn't a difficult or hard to
>> > > understand refactoring - the patch is fine the way it is.
>> > 
>> > Modulo the defects that might be introduced if an overflow occurs.
>> > 
>> > struct foo {
>> > 	unsigned int a:1;
>> > 	bool b:1;
>> > }
>> > 
>> > Assign a non-zero int without bit 0 set to each and see if
>> > a and b differ.
>> 
>> Bool permits implicit pointer-to-bool conversions, so it isn't free
>> of pitfalls either.
>
> Care to describe some of those pitfalls?
> I can't think of any off the top of my head.
>

I just listed the pitfall. I don't consider silently converting a
pointer to a bool value desirable, outside of contexts where that
is made obvious, ie: while(...), if(...), and so on.

>> Overflow is probably more dangerous in general,
>> but here there's little chance of pointers or overflow getting involved.
>
> I don't know _this_ code at all, nor have I read it.
>
> If all the conversions are just deleted later, then of course
> it should not be converted at all.

Only _some_ of the flags are being removed, not all of them.

>
> I'm just commenting on the proposed refactoring.
>
> I'm trying to show that conversions of bool:1->unsigned int:1
> as being trivial are not so trivial after all.
>
> It's fairly common to have code like:
>
> 	[bool] foo.bar = some_value & SETTING;
>
> where some value is tested for a mask/bit and a non-zero is true.
>
> So conversions of foo.bar from bool:1 to unsigned int:1 are not
> wise unless all possible side effects are known.

Good point. I didn't take that into account, because I expect all
users are using literal true/false values.

Anyhow, Andy asked for the flags to be converted to unsigned int since
he thought bool was strange for a bitfield, and grepping showed it was
much less common than unsigned int. I personally don't mind either way,
so maybe it's better to leave them as bools.

  parent reply	other threads:[~2022-06-24 14:30 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 21:14 [PATCH v2 00/12] regmap-irq cleanups and refactoring Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 01/12] regmap-irq: Convert bool bitfields to unsigned int Aidan MacDonald
2022-06-23 21:26   ` Andy Shevchenko
2022-06-24 12:11     ` Mark Brown
2022-06-24 12:46       ` Joe Perches
2022-06-24 12:56         ` Mark Brown
2022-06-24 13:05         ` Aidan MacDonald
2022-06-24 13:45           ` Joe Perches
2022-06-24 14:28             ` David Laight
2022-06-24 14:31             ` Aidan MacDonald [this message]
2022-06-23 21:14 ` [PATCH v2 02/12] regmap-irq: Remove unused type_reg_stride field Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 03/12] regmap-irq: Cleanup sizeof(...) use in memory allocation Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 04/12] regmap-irq: Remove an unnecessary restriction on type_in_mask Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 05/12] regmap-irq: Remove inappropriate uses of regmap_irq_update_bits() Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 06/12] regmap-irq: Remove mask_writeonly and regmap_irq_update_bits() Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 07/12] regmap-irq: Refactor checks for status bulk read support Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 08/12] regmap-irq: Introduce config registers for irq types Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 09/12] regmap-irq: Deprecate type registers and virtual registers Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 10/12] regmap-irq: Fix inverted handling of unmask registers Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 11/12] regmap-irq: Add get_irq_reg() callback Aidan MacDonald
2022-07-01 16:33   ` Marek Szyprowski
2022-07-03 11:06     ` Aidan MacDonald
2022-06-23 21:14 ` [PATCH v2 12/12] regmap-irq: Deprecate the not_fixed_stride flag Aidan MacDonald
2022-06-30 17:27 ` [PATCH v2 00/12] regmap-irq cleanups and refactoring Mark Brown

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=duS4BsAjcIRLiWV6ym9lJgPbPrOrefWf@localhost \
    --to=aidanmacdonald.0x0@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=rafael@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox