Re: [GIT pull] core/urgent for v5.4-rc7

From: Joe Perches
Date: Sun Nov 10 2019 - 20:50:52 EST


On Sun, 2019-11-10 at 14:35 -0800, Linus Torvalds wrote:
> On Sun, Nov 10, 2019 at 2:01 PM Joe Perches <joe@xxxxxxxxxxx> 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 == ',');