netlink: reduce NLA_POLICY_NESTED{,_ARRAY} arguments
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>
This commit is contained in:
parent
752cfee90d
commit
23323289b1
|
@ -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) \
|
||||
|
|
|
@ -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_ATTR_MAX,
|
||||
nl80211_pmsr_attr_policy),
|
||||
NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
|
||||
[NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue