RE: [PATCH 03/10] net/tap: clarify TUN/TAP flag assignment

Morten Brørup
2026-02-15T21:45:59Z

> Replace a ternary expression that relied on operator precedence
> between '?:' and '|' with an explicit if/else. No functional change.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> drivers/net/tap/rte_eth_tap.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/tap/rte_eth_tap.c
> b/drivers/net/tap/rte_eth_tap.c
> index aa236cf967..31c8c185e9 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -154,8 +154,11 @@ tun_alloc(struct pmd_internals *pmd, int
> is_keepalive, int persistent)
> * Do not set IFF_NO_PI as packet information header will be
> needed
> * to check if a received packet has been truncated.
> */
> - ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
> - IFF_TAP : IFF_TUN | IFF_POINTOPOINT;

For unconditional assignment, I prefer ternary expression over if/else.
If you want to improve readability instead of relying on operator precedence, suggest:

ifr.ifr_flags = (pmd->type == ETH_TUNTAP_TYPE_TAP) ?
IFF_TAP : (IFF_TUN | IFF_POINTOPOINT);

> + if (pmd->type == ETH_TUNTAP_TYPE_TAP)
> + ifr.ifr_flags = IFF_TAP;
> + else
> + ifr.ifr_flags = IFF_TUN | IFF_POINTOPOINT;
> +
> strlcpy(ifr.ifr_name, pmd->name, IFNAMSIZ);
>
> fd = open(TUN_TAP_DEV_PATH, O_RDWR);
> --
> 2.51.0