From: Johannes Berg <johannes@sipsolutions.net>
To: Jeff Johnson <quic_jjohnson@quicinc.com>,
Veerendranath Jakkam <quic_vjakkam@quicinc.com>
Cc: linux-wireless@vger.kernel.org
Subject: Re: [RFC v2] cfg80211: Indicate MLO connection info in connect and roam callbacks
Date: Wed, 08 Jun 2022 09:23:23 +0200 [thread overview]
Message-ID: <43dc2cc68300070b3727f63ea796fc327664174d.camel@sipsolutions.net> (raw)
In-Reply-To: <25ed0281-0880-1e8f-154c-53ee056e8879@quicinc.com>
On Tue, 2022-06-07 at 17:24 -0700, Jeff Johnson wrote:
> > + struct nlattr *nested;
> > +
> > + nested = nla_nest_start(msg, NL80211_ATTR_MLO_LINKS);
> > + if (!nested)
> > + goto nla_put_failure;
> > +
> > + for_each_valid_link(cr, link) {
> > + struct nlattr *nested_mlo_links;
> > + const u8 *bssid = cr->links[link].bss ?
> > + cr->links[link].bss->bssid :
> > + cr->links[link].bssid;
> > +
> > + nested_mlo_links = nla_nest_start(msg, i + 1);
>
> why i+1?
> if you don't want to use 0 for the first entry (why not?) then init i to 1
>
> alternately since this is the only place i is used, use ++i or i++ as
> you see fit and remove the i++ later
>
> ultimately we should only need to calculate i+1 once
>
> these comments apply to nl80211_send_roamed() as well
>
> (BTW I do see this pattern in some of the existing code, but I also see
> 0 being used for the first record)
>
Yeah, we're not very consistent with this ...
The background is that this ends up being an attribute, so the structure
is
NL80211_ATTR_MLO_LINKS = {
1 = {
NL80211_ATTR_MLO_LINK_ID = <integer>,
...
},
...
}
so the "1" there is an attribute. Netlink says that attribute number 0
is invalid, and that's enforced if you were to try nla_parse_nested() or
so on the data of the NL80211_ATTR_MLO_LINKS attribute.
Now, nla_for_each_nested() doesn't care, and that's almost certainly
what gets used in the parser side of this, since the attribute number
doesn't even matter.
(We could use the link ID as the attribute number, but 0 is a valid link
ID and technically documented to not be a valid attribute number, so
...)
So I can see where this is coming from, and I don't really think it
matters. The compiler will almost certainly emit the same code anyway,
or at least I'd hope so :)
We probably have this pattern a few times ...
If we ignore the documentation further, we could even always use 0 for
the number, nla_for_each_nested() still won't care... but then we _try_
to do the right thing, except sometimes probably get it wrong with 0 vs.
1 starting.
Anyway, I guess it makes sense to just write it as
int i = 1;
...
nla_nest_start(msg, i);
instead, and we need a [PATCH] resubmit of this anyway I guess.
johannes
next prev parent reply other threads:[~2022-06-08 7:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-06 17:31 [RFC v2] cfg80211: Indicate MLO connection info in connect and roam callbacks Veerendranath Jakkam
2022-06-08 0:24 ` Jeff Johnson
2022-06-08 7:23 ` Johannes Berg [this message]
2022-06-08 7:28 ` Veerendranath Jakkam
2022-06-08 7:31 ` Johannes Berg
2022-06-08 7:45 ` Veerendranath Jakkam
2022-06-08 7:59 ` Johannes Berg
2022-06-08 8:10 ` Veerendranath Jakkam
2022-06-08 8:11 ` Johannes Berg
2022-06-08 9:57 ` Veerendranath Jakkam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43dc2cc68300070b3727f63ea796fc327664174d.camel@sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=quic_jjohnson@quicinc.com \
--cc=quic_vjakkam@quicinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox