2023-06-29 13:32:50

by David Laight

[permalink] [raw]
Subject: RE: [PATCH] wifi:mac80211: Replace the tern ary conditional operator with max()

From: Ping-Ke Shih
> Sent: 28 June 2023 02:49
>
> > -----Original Message-----
> > From: You Kangren <[email protected]>
> > Sent: Monday, June 26, 2023 6:48 PM
> > To: Johannes Berg <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet
> > <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; open
> > list:MAC80211 <[email protected]>; open list:NETWORKING [GENERAL]
> <[email protected]>;
> > open list <[email protected]>
> > Cc: [email protected]; [email protected]
> > Subject: [PATCH] wifi:mac80211: Replace the ternary conditional operator with max()
>
> The semicolon of "wifi:" is different from others.
>
> >
> > Replace the ternary conditional operator with max() to make the code clean
> >
> > Signed-off-by: You Kangren <[email protected]>
> > ---
> > net/mac80211/tdls.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
> > index a4af3b7675ef..9f8b0842a616 100644
> > --- a/net/mac80211/tdls.c
> > +++ b/net/mac80211/tdls.c
> > @@ -946,7 +946,7 @@ ieee80211_tdls_build_mgmt_packet_data(struct ieee80211_sub_if_data *sdata,
> > int ret;
> > struct ieee80211_link_data *link;
> >
> > - link_id = link_id >= 0 ? link_id : 0;
> > + link_id = max(link_id, 0);
>
> Original logic means "if link_id < 0, then use default link (0)" instead of
> "always use link_id larger than or equal to 0". So, I think max(link_id, 0) could
> cause misunderstanding.

The clearest is probably:
if (link_id < 0)
link_id = 0;

The compiler could easily generate the same code (compare and conditional
move).

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


2023-07-03 08:28:12

by Ping-Ke Shih

[permalink] [raw]
Subject: RE: [PATCH] wifi:mac80211: Replace the tern ary conditional operator with max()



> -----Original Message-----
> From: David Laight <[email protected]>
> Sent: Thursday, June 29, 2023 9:28 PM
> To: Ping-Ke Shih <[email protected]>; You Kangren <[email protected]>; Johannes Berg
> <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>;
> Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; open list:MAC80211
> <[email protected]>; open list:NETWORKING [GENERAL] <[email protected]>; open list
> <[email protected]>
> Cc: [email protected]
> Subject: RE: [PATCH] wifi:mac80211: Replace the ternary conditional operator with max()
>
> From: Ping-Ke Shih
> > Sent: 28 June 2023 02:49
> >
> > > -----Original Message-----
> > > From: You Kangren <[email protected]>
> > > Sent: Monday, June 26, 2023 6:48 PM
> > > To: Johannes Berg <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet
> > > <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; open
> > > list:MAC80211 <[email protected]>; open list:NETWORKING [GENERAL]
> > <[email protected]>;
> > > open list <[email protected]>
> > > Cc: [email protected]; [email protected]
> > > Subject: [PATCH] wifi:mac80211: Replace the ternary conditional operator with max()
> >
> > The semicolon of "wifi:" is different from others.
> >
> > >
> > > Replace the ternary conditional operator with max() to make the code clean
> > >
> > > Signed-off-by: You Kangren <[email protected]>
> > > ---
> > > net/mac80211/tdls.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/net/mac80211/tdls.c b/net/mac80211/tdls.c
> > > index a4af3b7675ef..9f8b0842a616 100644
> > > --- a/net/mac80211/tdls.c
> > > +++ b/net/mac80211/tdls.c
> > > @@ -946,7 +946,7 @@ ieee80211_tdls_build_mgmt_packet_data(struct ieee80211_sub_if_data *sdata,
> > > int ret;
> > > struct ieee80211_link_data *link;
> > >
> > > - link_id = link_id >= 0 ? link_id : 0;
> > > + link_id = max(link_id, 0);
> >
> > Original logic means "if link_id < 0, then use default link (0)" instead of
> > "always use link_id larger than or equal to 0". So, I think max(link_id, 0) could
> > cause misunderstanding.
>
> The clearest is probably:
> if (link_id < 0)
> link_id = 0;
>
> The compiler could easily generate the same code (compare and conditional
> move).
>

They would be the same, but personally I prefer original single one line statement
that is clear to me.