linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] netlink: reduce NLA_POLICY_NESTED{,_ARRAY} arguments
@ 2019-01-25  9:08 Johannes Berg
  2019-01-25 19:04 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2019-01-25  9:08 UTC (permalink / raw)
  To: linux-wireless, netdev; +Cc: Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

In typical cases, there's no need to pass both the maxattr
and the policy array pointer, as the maxattr should just be
ARRAY_SIZE(policy) - 1. Therefore, to be less error prone,
just remove the maxattr argument from the default macros
and deduce the size accordingly.

Leave the original macros with a leading underscore to use
here and in case somebody needs to pass a policy pointer
where the policy isn't declared in the same place and thus
ARRAY_SIZE() cannot be used.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
Dave, it looks like we're the only users of this right now,
so let me know if you'd prefer I take it through my tree.
Also, this conflicts with the fix I just made to the place
where I got it wrong, but obviously the resolution is to
just take the version without the maxattr argument.
---
 include/net/netlink.h  |  8 ++++++--
 net/wireless/nl80211.c | 15 +++++----------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/include/net/netlink.h b/include/net/netlink.h
index 4c1e99303b5a..23f27b0b3cef 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -306,10 +306,14 @@ struct nla_policy {
 #define NLA_POLICY_ETH_ADDR		NLA_POLICY_EXACT_LEN(ETH_ALEN)
 #define NLA_POLICY_ETH_ADDR_COMPAT	NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN)
 
-#define NLA_POLICY_NESTED(maxattr, policy) \
+#define _NLA_POLICY_NESTED(maxattr, policy) \
 	{ .type = NLA_NESTED, .validation_data = policy, .len = maxattr }
-#define NLA_POLICY_NESTED_ARRAY(maxattr, policy) \
+#define _NLA_POLICY_NESTED_ARRAY(maxattr, policy) \
 	{ .type = NLA_NESTED_ARRAY, .validation_data = policy, .len = maxattr }
+#define NLA_POLICY_NESTED(policy) \
+	_NLA_POLICY_NESTED(ARRAY_SIZE(policy) - 1, policy)
+#define NLA_POLICY_NESTED_ARRAY(policy) \
+	_NLA_POLICY_NESTED_ARRAY(ARRAY_SIZE(policy) - 1, policy)
 
 #define __NLA_ENSURE(condition) BUILD_BUG_ON_ZERO(!(condition))
 #define NLA_ENSURE_INT_TYPE(tp)				\
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index e5f9c9ceb6c9..dde03ec279e6 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -259,15 +259,13 @@ nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = {
 static const struct nla_policy
 nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
 	[NL80211_PMSR_TYPE_FTM] =
-		NLA_POLICY_NESTED(NL80211_PMSR_FTM_REQ_ATTR_MAX,
-				  nl80211_pmsr_ftm_req_attr_policy),
+		NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
 };
 
 static const struct nla_policy
 nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
 	[NL80211_PMSR_REQ_ATTR_DATA] =
-		NLA_POLICY_NESTED(NL80211_PMSR_TYPE_MAX,
-				  nl80211_pmsr_req_data_policy),
+		NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
 	[NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
 };
 
@@ -280,8 +278,7 @@ nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
 	 */
 	[NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED },
 	[NL80211_PMSR_PEER_ATTR_REQ] =
-		NLA_POLICY_NESTED(NL80211_PMSR_REQ_ATTR_MAX,
-				  nl80211_pmsr_req_attr_policy),
+		NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
 	[NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
 };
 
@@ -292,8 +289,7 @@ nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
 	[NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
 	[NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
 	[NL80211_PMSR_ATTR_PEERS] =
-		NLA_POLICY_NESTED_ARRAY(NL80211_PMSR_PEER_ATTR_MAX,
-					nl80211_psmr_peer_attr_policy),
+		NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy),
 };
 
 const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
@@ -555,8 +551,7 @@ const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
 	},
 	[NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
 	[NL80211_ATTR_PEER_MEASUREMENTS] =
-		NLA_POLICY_NESTED(NL80211_PMSR_FTM_REQ_ATTR_MAX,
-				  nl80211_pmsr_attr_policy),
+		NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
 	[NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
 };
 
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] netlink: reduce NLA_POLICY_NESTED{,_ARRAY} arguments
  2019-01-25  9:08 [PATCH net-next] netlink: reduce NLA_POLICY_NESTED{,_ARRAY} arguments Johannes Berg
@ 2019-01-25 19:04 ` David Miller
  2019-01-25 19:34   ` Johannes Berg
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2019-01-25 19:04 UTC (permalink / raw)
  To: johannes; +Cc: linux-wireless, netdev, johannes.berg

From: Johannes Berg <johannes@sipsolutions.net>
Date: Fri, 25 Jan 2019 10:08:28 +0100

> From: Johannes Berg <johannes.berg@intel.com>
> 
> In typical cases, there's no need to pass both the maxattr
> and the policy array pointer, as the maxattr should just be
> ARRAY_SIZE(policy) - 1. Therefore, to be less error prone,
> just remove the maxattr argument from the default macros
> and deduce the size accordingly.
> 
> Leave the original macros with a leading underscore to use
> here and in case somebody needs to pass a policy pointer
> where the policy isn't declared in the same place and thus
> ARRAY_SIZE() cannot be used.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> ---
> Dave, it looks like we're the only users of this right now,
> so let me know if you'd prefer I take it through my tree.
> Also, this conflicts with the fix I just made to the place
> where I got it wrong, but obviously the resolution is to
> just take the version without the maxattr argument.

Please take it through your tree in that case.  It'll probably
be the more painless way to merge this.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] netlink: reduce NLA_POLICY_NESTED{,_ARRAY} arguments
  2019-01-25 19:04 ` David Miller
@ 2019-01-25 19:34   ` Johannes Berg
  2019-01-25 19:36     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2019-01-25 19:34 UTC (permalink / raw)
  To: David Miller; +Cc: linux-wireless, netdev

On Fri, 2019-01-25 at 11:04 -0800, David Miller wrote:
> 
> > Dave, it looks like we're the only users of this right now,
> > so let me know if you'd prefer I take it through my tree.
> > Also, this conflicts with the fix I just made to the place
> > where I got it wrong, but obviously the resolution is to
> > just take the version without the maxattr argument.
> 
> Please take it through your tree in that case.  It'll probably
> be the more painless way to merge this.

Will do. The most painless would be if you'd merge net into net-next,
then I could pull net-next into mac80211-next and resolve the conflict
before I even apply the patch. In fact, I think either way I'll just
wait until you do that, I suppose you will eventually anyway?

johannes


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next] netlink: reduce NLA_POLICY_NESTED{,_ARRAY} arguments
  2019-01-25 19:34   ` Johannes Berg
@ 2019-01-25 19:36     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-01-25 19:36 UTC (permalink / raw)
  To: johannes; +Cc: linux-wireless, netdev

From: Johannes Berg <johannes@sipsolutions.net>
Date: Fri, 25 Jan 2019 20:34:57 +0100

> On Fri, 2019-01-25 at 11:04 -0800, David Miller wrote:
>> 
>> > Dave, it looks like we're the only users of this right now,
>> > so let me know if you'd prefer I take it through my tree.
>> > Also, this conflicts with the fix I just made to the place
>> > where I got it wrong, but obviously the resolution is to
>> > just take the version without the maxattr argument.
>> 
>> Please take it through your tree in that case.  It'll probably
>> be the more painless way to merge this.
> 
> Will do. The most painless would be if you'd merge net into net-next,
> then I could pull net-next into mac80211-next and resolve the conflict
> before I even apply the patch. In fact, I think either way I'll just
> wait until you do that, I suppose you will eventually anyway?

Yeah I will probably send Linus a pull request today which means the
net --> net-next merge should occur in the next 24 hours.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-25 19:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-25  9:08 [PATCH net-next] netlink: reduce NLA_POLICY_NESTED{,_ARRAY} arguments Johannes Berg
2019-01-25 19:04 ` David Miller
2019-01-25 19:34   ` Johannes Berg
2019-01-25 19:36     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).