Re: [PATCH] wifi:mac80211: Replace the ternary conditional operator with max()

From: Nicolas Escande
Date: Wed Jun 28 2023 - 04:07:47 EST


On Wed Jun 28, 2023 at 3:48 AM CEST, Ping-Ke Shih wrote:
>
>
> > -----Original Message-----
> > From: You Kangren <youkangren@xxxxxxxx>
> > Sent: Monday, June 26, 2023 6:48 PM
> > To: Johannes Berg <johannes@xxxxxxxxxxxxxxxx>; David S. Miller <davem@xxxxxxxxxxxxx>; Eric Dumazet
> > <edumazet@xxxxxxxxxx>; Jakub Kicinski <kuba@xxxxxxxxxx>; Paolo Abeni <pabeni@xxxxxxxxxx>; open
> > list:MAC80211 <linux-wireless@xxxxxxxxxxxxxxx>; open list:NETWORKING [GENERAL] <netdev@xxxxxxxxxxxxxxx>;
> > open list <linux-kernel@xxxxxxxxxxxxxxx>
> > Cc: opensource.kernel@xxxxxxxx; youkangren@xxxxxxxx
> > 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 <youkangren@xxxxxxxx>
> > ---
> > 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.

I feel the same way, max() implies we want the 'highest' link whereas for me the
actual code really means 'prefer the non default' (zero) link.

>
> > rcu_read_lock();
> > link = rcu_dereference(sdata->link[link_id]);
> > if (WARN_ON(!link))
> > --
> > 2.39.0
> >
> >
> > ------Please consider the environment before printing this e-mail.