]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
netlink: Add nla_memdup() to wrap kmemdup() use on nlattr
authorThomas Graf <tgraf@suug.ch>
Wed, 26 Oct 2016 08:53:16 +0000 (10:53 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sat, 29 Oct 2016 18:57:42 +0000 (14:57 -0400)
Wrap several common instances of:
kmemdup(nla_data(attr), nla_len(attr), GFP_KERNEL);

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Acked-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/netlink.h
net/sched/act_bpf.c
net/sched/cls_bpf.c
net/wireless/nl80211.c

index 254a0fc018006a773f31f41bc07e89e5b81528c2..a34f53acb6d62b8339ceb7da703823dd10dafc7c 100644 (file)
@@ -1190,6 +1190,16 @@ static inline struct in6_addr nla_get_in6_addr(const struct nlattr *nla)
        return tmp;
 }
 
+/**
+ * nla_memdup - duplicate attribute memory (kmemdup)
+ * @src: netlink attribute to duplicate from
+ * @gfp: GFP mask
+ */
+static inline void *nla_memdup(const struct nlattr *src, gfp_t gfp)
+{
+       return kmemdup(nla_data(src), nla_len(src), gfp);
+}
+
 /**
  * nla_nest_start - Start a new level of nested attributes
  * @skb: socket buffer to add attributes to
index 1d3960033f61d0f72d5039ba31ff1c8dc91d7cba..9ff06cfbcdec9756a42d8076710405c586b21f48 100644 (file)
@@ -226,9 +226,7 @@ static int tcf_bpf_init_from_efd(struct nlattr **tb, struct tcf_bpf_cfg *cfg)
                return PTR_ERR(fp);
 
        if (tb[TCA_ACT_BPF_NAME]) {
-               name = kmemdup(nla_data(tb[TCA_ACT_BPF_NAME]),
-                              nla_len(tb[TCA_ACT_BPF_NAME]),
-                              GFP_KERNEL);
+               name = nla_memdup(tb[TCA_ACT_BPF_NAME], GFP_KERNEL);
                if (!name) {
                        bpf_prog_put(fp);
                        return -ENOMEM;
index bb1d5a487081f21f80a3042cd424cf7caedf6b37..52dc85acca7d3ba2acb8a0c9213595da7d2a7aab 100644 (file)
@@ -369,9 +369,7 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog,
                return PTR_ERR(fp);
 
        if (tb[TCA_BPF_NAME]) {
-               name = kmemdup(nla_data(tb[TCA_BPF_NAME]),
-                              nla_len(tb[TCA_BPF_NAME]),
-                              GFP_KERNEL);
+               name = nla_memdup(tb[TCA_BPF_NAME], GFP_KERNEL);
                if (!name) {
                        bpf_prog_put(fp);
                        return -ENOMEM;
index 271707dacfea4ddedb85224ac5773fa909ce256f..0d3ab4bfeacf98f2ddcad18ee3f7354ba638fd75 100644 (file)
@@ -10625,8 +10625,7 @@ static int handle_nan_filter(struct nlattr *attr_filter,
 
        i = 0;
        nla_for_each_nested(attr, attr_filter, rem) {
-               filter[i].filter = kmemdup(nla_data(attr), nla_len(attr),
-                                          GFP_KERNEL);
+               filter[i].filter = nla_memdup(attr, GFP_KERNEL);
                filter[i].len = nla_len(attr);
                i++;
        }