On Mon, 05 Oct 2020 21:33:55 +0200 Johannes Berg wrote:
> > What I'm saying is that my preference would be:
> >
> > const struct nla_policy policy[OTHER_ATTR + 1] = {
> > [HEADER] = NLA_POLICY(...)
> > [OTHER_ATTR] = NLA_POLICY(...)
> > };
> >
> > extern const struct nla_policy policy[OTHER_ATTR + 1];
> >
> > op = {
> > .policy = policy,
> > .max_attr = ARRAY_SIZE(policy) - 1,
> > }
> >
> > Since it's harder to forget to update the op (you don't have to update
> > op, and compiler will complain about the extern out of sync).
>
> Yeah.
>
> I was thinking the third way ;-)
>
> const struct nla_policy policy[] = {
> [HEADER] = NLA_POLICY(...)
> [OTHER_ATTR] = NLA_POLICY(...)
> };
>
> op = {
> .policy = policy,
> .maxattr = ARRAY_SIZE(policy) - 1,
> };
>
>
> Now you can freely add any attributes, and, due to strict validation,
> anything not specified in the policy will be rejected, whether by being
> out of range (> maxattr) or not specified (NLA_UNSPEC).
100%, but in ethtool policy is defined in a different compilation unit
than the op array.