mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Joey Pabalinas <joeypabalinas@gmail.com>
Cc: linux-acpi@vger.kernel.org, Len Brown <lenb@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ACPI: prefer bool over int for predicates
Date: Wed, 02 May 2018 12:51:05 +0200	[thread overview]
Message-ID: <1824583.Oe7ze6gOva@aspire.rjw.lan> (raw)
In-Reply-To: <20180408084627.xignebybfxyds2t5@gmail.com>

On Sunday, April 8, 2018 10:46:27 AM CEST Joey Pabalinas wrote:
> 
> --dohnnvt2hwn6rmo4
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> Content-Transfer-Encoding: quoted-printable
> 
> Prefer bool over int for variables / returns which are
> predicate expressions to make it explicit that these
> expressions are evaluating simple "yes or no?" queries.

In new code - yes.

But changing old code just for this purpose is at least questionable.

> This makes it more obvious which expressions are _not_
> that simple and require more attention, e.g. an `int ret`
> meant to hold 0 or -ENOENT as a return value or an
> `unsigned nmemb` meant to refer to the number of valid
> members in some arbitrary array.
> 
> Change relevant variable / return types from int to bool and
> prefer a true / false value for predicate expressions versus
> a plain 1 / 0 value.

This makes a bunch of unrelated changes without a clear pattern
in many places and I'm not convinced that the reason is good enough.

> Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
> 
>  drivers/acpi/battery.c  |  4 ++--
>  drivers/acpi/ec.c       | 20 +++++++++-----------
>  drivers/acpi/pci_root.c | 17 ++++++-----------
>  drivers/acpi/scan.c     |  6 +++---
>  include/acpi/acpi_bus.h |  2 +-
>  5 files changed, 21 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index bdb24d636d9acc9c1a..f1a5fb5252969f0478 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -1416,7 +1416,7 @@ static int acpi_battery_add(struct acpi_device *devic=
> e)
>  	battery->pm_nb.notifier_call =3D battery_notify;
>  	register_pm_notifier(&battery->pm_nb);
> =20

Broken whitespace.

> -	device_init_wakeup(&device->dev, 1);
> +	device_init_wakeup(&device->dev, true);
> =20
>  	return result;
> =20
> @@ -1434,7 +1434,7 @@ static int acpi_battery_remove(struct acpi_device *de=
> vice)
> =20
>  	if (!device || !acpi_driver_data(device))
>  		return -EINVAL;
> -	device_init_wakeup(&device->dev, 0);
> +	device_init_wakeup(&device->dev, false);
>  	battery =3D acpi_driver_data(device);
>  	unregister_pm_notifier(&battery->pm_nb);
>  #ifdef CONFIG_ACPI_PROCFS_POWER
> diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
> index 30a5729565575f83cb..d4a564ab9cdd53046c 100644
> --- a/drivers/acpi/ec.c
> +++ b/drivers/acpi/ec.c
> @@ -350,7 +350,7 @@ static inline bool acpi_ec_is_gpe_raised(struct acpi_ec=
>  *ec)
>  	acpi_event_status gpe_status =3D 0;
> =20
>  	(void)acpi_get_gpe_status(NULL, ec->gpe, &gpe_status);
> -	return (gpe_status & ACPI_EVENT_FLAG_STATUS_SET) ? true : false;
> +	return gpe_status & ACPI_EVENT_FLAG_STATUS_SET;

And this isn't entirely correct even.

You should apply !! to the expression to get the same result really.

Thanks,
Rafael

      reply	other threads:[~2018-05-02 10:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-08  8:46 Joey Pabalinas
2018-05-02 10:51 ` Rafael J. Wysocki [this message]

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=1824583.Oe7ze6gOva@aspire.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=joeypabalinas@gmail.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.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

all inboxes | Powered by JetHome®