[PATCH 03/10] net/tap: clarify TUN/TAP flag assignment
Morten Brørup
mb at smartsharesystems.com
Mon Feb 16 06:56:54 CET 2026
> From: Stephen Hemminger [mailto:stephen at networkplumber.org]
> Sent: Monday, 16 February 2026 01.48
>
> On Sun, 15 Feb 2026 22:45:53 +0100
> Morten Brørup <mb at smartsharesystems.com> wrote:
>
> > >
> > > Signed-off-by: Stephen Hemminger <stephen at 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);
>
>
> I was pre-conditioned by MS style guide lines that always called out
> excessive use of ternary as confusing
Just tested on Godbolt; GCC, Clang and MSVC emits similar code for ternary and if/else, so it's only a matter of preference.
Since it's an unconditional assignment, I prefer ternary.
Ternary also works when initializing a variable with its declaration. And with assigning field values to structures.
Well... it's your code, so I'll leave you with the decision. ;-)
More information about the dev
mailing list