imx6: fix redundant PROFILES overrides in image makefile
[librecmc/librecmc.git] / package / kernel / mac80211 / patches / 005-header-backport-nla_put_u64_64bit-and-nla_put_64bit.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Sat, 14 May 2016 16:40:16 +0200
3 Subject: [PATCH] header: backport nla_put_u64_64bit and nla_put_64bit
4
5 Signed-off-by: Felix Fietkau <nbd@nbd.name>
6 ---
7
8 --- a/backport-include/net/netlink.h
9 +++ b/backport-include/net/netlink.h
10 @@ -189,4 +189,148 @@ static inline __le64 nla_get_le64(const
11  }
12  #endif /* < 4.4 */
13  
14 +
15 +#if LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0)
16 +
17 +/**
18 + * nla_need_padding_for_64bit - test 64-bit alignment of the next attribute
19 + * @skb: socket buffer the message is stored in
20 + *
21 + * Return true if padding is needed to align the next attribute (nla_data()) to
22 + * a 64-bit aligned area.
23 + */
24 +static inline bool nla_need_padding_for_64bit(struct sk_buff *skb)
25 +{
26 +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
27 +       /* The nlattr header is 4 bytes in size, that's why we test
28 +        * if the skb->data _is_ aligned.  A NOP attribute, plus
29 +        * nlattr header for next attribute, will make nla_data()
30 +        * 8-byte aligned.
31 +        */
32 +       if (IS_ALIGNED((unsigned long)skb_tail_pointer(skb), 8))
33 +               return true;
34 +#endif
35 +       return false;
36 +}
37 +
38 +/**
39 + * nla_align_64bit - 64-bit align the nla_data() of next attribute
40 + * @skb: socket buffer the message is stored in
41 + * @padattr: attribute type for the padding
42 + *
43 + * Conditionally emit a padding netlink attribute in order to make
44 + * the next attribute we emit have a 64-bit aligned nla_data() area.
45 + * This will only be done in architectures which do not have
46 + * CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS defined.
47 + *
48 + * Returns zero on success or a negative error code.
49 + */
50 +static inline int nla_align_64bit(struct sk_buff *skb, int padattr)
51 +{
52 +       if (nla_need_padding_for_64bit(skb) &&
53 +           !nla_reserve(skb, padattr, 0))
54 +               return -EMSGSIZE;
55 +
56 +       return 0;
57 +}
58 +
59 +/**
60 + * __nla_reserve_64bit - reserve room for attribute on the skb and align it
61 + * @skb: socket buffer to reserve room on
62 + * @attrtype: attribute type
63 + * @attrlen: length of attribute payload
64 + * @padattr: attribute type for the padding
65 + *
66 + * Adds a netlink attribute header to a socket buffer and reserves
67 + * room for the payload but does not copy it. It also ensure that this
68 + * attribute will have a 64-bit aligned nla_data() area.
69 + *
70 + * The caller is responsible to ensure that the skb provides enough
71 + * tailroom for the attribute header and payload.
72 + */
73 +static inline struct nlattr *__nla_reserve_64bit(struct sk_buff *skb, int attrtype,
74 +                                                int attrlen, int padattr)
75 +{
76 +       if (nla_need_padding_for_64bit(skb))
77 +               nla_align_64bit(skb, padattr);
78 +
79 +       return __nla_reserve(skb, attrtype, attrlen);
80 +}
81 +
82 +/**
83 + * __nla_put_64bit - Add a netlink attribute to a socket buffer and align it
84 + * @skb: socket buffer to add attribute to
85 + * @attrtype: attribute type
86 + * @attrlen: length of attribute payload
87 + * @data: head of attribute payload
88 + * @padattr: attribute type for the padding
89 + *
90 + * The caller is responsible to ensure that the skb provides enough
91 + * tailroom for the attribute header and payload.
92 + */
93 +static inline void __nla_put_64bit(struct sk_buff *skb, int attrtype, int attrlen,
94 +                                  const void *data, int padattr)
95 +{
96 +       struct nlattr *nla;
97 +
98 +       nla = __nla_reserve_64bit(skb, attrtype, attrlen, padattr);
99 +       memcpy(nla_data(nla), data, attrlen);
100 +}
101 +
102 +/**
103 + * nla_total_size_64bit - total length of attribute including padding
104 + * @payload: length of payload
105 + */
106 +static inline int nla_total_size_64bit(int payload)
107 +{
108 +       return NLA_ALIGN(nla_attr_size(payload))
109 +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
110 +               + NLA_ALIGN(nla_attr_size(0))
111 +#endif
112 +               ;
113 +}
114 +
115 +/**
116 + * nla_put_64bit - Add a netlink attribute to a socket buffer and align it
117 + * @skb: socket buffer to add attribute to
118 + * @attrtype: attribute type
119 + * @attrlen: length of attribute payload
120 + * @data: head of attribute payload
121 + * @padattr: attribute type for the padding
122 + *
123 + * Returns -EMSGSIZE if the tailroom of the skb is insufficient to store
124 + * the attribute header and payload.
125 + */
126 +static inline int nla_put_64bit(struct sk_buff *skb, int attrtype, int attrlen,
127 +                               const void *data, int padattr)
128 +{
129 +       size_t len;
130 +
131 +       if (nla_need_padding_for_64bit(skb))
132 +               len = nla_total_size_64bit(attrlen);
133 +       else
134 +               len = nla_total_size(attrlen);
135 +       if (unlikely(skb_tailroom(skb) < len))
136 +               return -EMSGSIZE;
137 +
138 +       __nla_put_64bit(skb, attrtype, attrlen, data, padattr);
139 +       return 0;
140 +}
141 +
142 +/**
143 + * nla_put_u64_64bit - Add a u64 netlink attribute to a skb and align it
144 + * @skb: socket buffer to add attribute to
145 + * @attrtype: attribute type
146 + * @value: numeric value
147 + * @padattr: attribute type for the padding
148 + */
149 +static inline int nla_put_u64_64bit(struct sk_buff *skb, int attrtype,
150 +                                   u64 value, int padattr)
151 +{
152 +       return nla_put_64bit(skb, attrtype, sizeof(u64), &value, padattr);
153 +}
154 +
155 +
156 +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0) */
157 +
158  #endif /* __BACKPORT_NET_NETLINK_H */