From: Joe Perches <joe@perches.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>, Jiri Slaby <jslaby@suse.cz>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
the arch/x86 maintainers <x86@kernel.org>
Subject: Re: [GIT pull] core/urgent for v5.4-rc7
Date: Sun, 10 Nov 2019 17:50:32 -0800 [thread overview]
Message-ID: <56f05dfb50dfc506a9cab539e522e8f80c738a4b.camel@perches.com> (raw)
In-Reply-To: <CAHk-=wiwhMFo6GFUAg3CZJMix4TJo59NBaSDciQxW23RHR8Zbg@mail.gmail.com>
On Sun, 2019-11-10 at 14:35 -0800, Linus Torvalds wrote:
> On Sun, Nov 10, 2019 at 2:01 PM Joe Perches <joe@perches.com> wrote:
> > trivia:
> >
> > This idiom '!!(logical test)' is odd and redundant.
> > Logical test result is already 0 or 1, no !! is unnecessary.
>
> You are of course correct.
>
> I have to say, I personally have always disliked the idiomatic C "!!"
> pattern. I don't think it reads well, although that's probably "C
> cultural" - once you are used to the pattern, you don't think of it as
> anything else.
>
> Personally, I prefer "x != 0" over "!!x" since it reads much better to
> a human, and is equally legible whether you're used to the !! pattern
> or not.
>
> C is not perl, the Obfuscated C contest not-withstanding.
>
> And since modern C has bool, if you really want to use a cast-to-bool
> instead of "x != 0", I think doing exactly that is preferable to "!!".
>
> So I think both "x != 0" and "(bool)x" are preferable to "!!x", and
> would also have made it obvious how odd and redundant the test was in
> this case.
>
> But "!!x" is shorter, of course. And it you learnt C with that pattern
> it looks obvious.
The !! logical usage is not particularly common in the kernel.
There seems to be only a couple/few dozen.
$ git grep -P '\!\!\s*\([^\)]+[\!=]=.*\);'
drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c: info->realtek_eDPToLVDS = !!(lvds->dplvdsrxid == eDP_TO_LVDS_REALTEK_ID);
drivers/iio/resolver/ad2s1200.c: gpiod_set_value(st->rdvel, !!(chan->type == IIO_ANGL));
drivers/infiniband/hw/mlx5/mr.c: MLX5_SET(mkc, mkc, en_rinval, !!((type == IB_MW_TYPE_2)));
drivers/leds/leds-max77693.c: *state = !!(*state && (led->strobing_sub_led_id == sub_led->fled_id));
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: return !!(mfw_val == DCBX_APP_SF_IEEE_ETHTYPE);
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: return !!(mfw_val == type || mfw_val == DCBX_APP_SF_IEEE_TCP_UDP_PORT);
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: return !!(ethtype && (proto_id == QED_ETH_TYPE_DEFAULT));
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: return !!(port && (proto_id == QED_TCP_PORT_ISCSI));
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: return !!(ethtype && (proto_id == QED_ETH_TYPE_FCOE));
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: return !!(ethtype && (proto_id == QED_ETH_TYPE_ROCE));
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: return !!(port && (proto_id == QED_UDP_PORT_TYPE_ROCE_V2));
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
drivers/net/ethernet/qlogic/qed/qed_dcbx.c: ethtype = !!(idtype == DCB_APP_IDTYPE_ETHTYPE);
drivers/net/wireless/ath/ath9k/recv.c: is_40 = !!(rxs->bw == RATE_INFO_BW_40);
drivers/pci/controller/pcie-iproc.c: return !!(reg_offset == IPROC_PCIE_REG_INVALID);
drivers/pci/controller/pcie-iproc.c: return !!(ib_map->type == type);
drivers/pci/hotplug/pnv_php.c: added = !!(presence == OPAL_PCI_SLOT_PRESENT);
drivers/platform/x86/asus-wmi.c: ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK);
drivers/scsi/hisi_sas/hisi_sas_main.c: bool do_port_check = !!(_sas_port != sas_port);
fs/ocfs2/reservations.c: return !!(resv->r_len == 0);
fs/ubifs/journal.c: int last_reference = !!(deletion && inode->i_nlink == 0);
fs/ubifs/journal.c: int last_reference = !!(new_inode && new_inode->i_nlink == 0);
sound/firewire/amdtp-stream.c: !!(params->header_length == 0 && params->payload_length == 0);
tools/perf/util/time-utils.c: num += !!(*cp == ',');
next prev parent reply other threads:[~2019-11-11 1:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-10 10:21 Thomas Gleixner
2019-11-10 10:21 ` [GIT pull] sched/urgent " Thomas Gleixner
2019-11-10 21:00 ` pr-tracker-bot
2019-11-10 10:21 ` [GIT pull] perf/urgent " Thomas Gleixner
2019-11-10 21:00 ` pr-tracker-bot
2019-11-10 10:21 ` [GIT pull] irq/urgent " Thomas Gleixner
2019-11-10 21:00 ` pr-tracker-bot
2019-11-10 10:21 ` [GIT pull] timers/urgent " Thomas Gleixner
2019-11-10 21:00 ` pr-tracker-bot
2019-11-10 10:21 ` [GIT pull] x86/urgent " Thomas Gleixner
2019-11-10 21:00 ` pr-tracker-bot
2019-11-10 21:00 ` [GIT pull] core/urgent " pr-tracker-bot
2019-11-10 22:00 ` Joe Perches
2019-11-10 22:35 ` Linus Torvalds
2019-11-11 1:50 ` Joe Perches [this message]
2019-11-11 17:12 ` Linus Torvalds
2019-11-12 1:37 ` Joe Perches
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=56f05dfb50dfc506a9cab539e522e8f80c738a4b.camel@perches.com \
--to=joe@perches.com \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@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®