Skip to content

Commit eb9672f

Browse files
Daniel Borkmanndavem330
authored andcommitted
net: filter: misc/various cleanups
This contains only some minor misc cleanpus. We can spare us the extra variable declaration in __skb_get_pay_offset(), the cast in __get_random_u32() is rather unnecessary and in __sk_migrate_realloc() we can remove the memcpy() and do a direct assignment of the structs. Latter was suggested by Fengguang Wu found with coccinelle. Also, remaining pointer casts of long should be unsigned long instead. Suggested-by: Fengguang Wu <fengguang.wu@intel.com> Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Acked-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3074383 commit eb9672f

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

‎net/core/filter.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
7878
ptr = skb_network_header(skb) + k - SKF_NET_OFF;
7979
else if (k >= SKF_LL_OFF)
8080
ptr = skb_mac_header(skb) + k - SKF_LL_OFF;
81-
8281
if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb))
8382
return ptr;
83+
8484
return NULL;
8585
}
8686

@@ -89,6 +89,7 @@ static inline void *load_pointer(const struct sk_buff *skb, int k,
8989
{
9090
if (k >= 0)
9191
return skb_header_pointer(skb, k, size, buffer);
92+
9293
return bpf_internal_load_pointer_neg_helper(skb, k, size);
9394
}
9495

@@ -598,14 +599,12 @@ static unsigned int pkt_type_offset(void)
598599

599600
static u64 __skb_get_pay_offset(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
600601
{
601-
struct sk_buff *skb = (struct sk_buff *)(long) ctx;
602-
603-
return __skb_get_poff(skb);
602+
return __skb_get_poff((struct sk_buff *)(unsigned long) ctx);
604603
}
605604

606605
static u64 __skb_get_nlattr(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
607606
{
608-
struct sk_buff *skb = (struct sk_buff *)(long) ctx;
607+
struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
609608
struct nlattr *nla;
610609

611610
if (skb_is_nonlinear(skb))
@@ -626,7 +625,7 @@ static u64 __skb_get_nlattr(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
626625

627626
static u64 __skb_get_nlattr_nest(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
628627
{
629-
struct sk_buff *skb = (struct sk_buff *)(long) ctx;
628+
struct sk_buff *skb = (struct sk_buff *)(unsigned long) ctx;
630629
struct nlattr *nla;
631630

632631
if (skb_is_nonlinear(skb))
@@ -657,7 +656,7 @@ static u64 __get_raw_cpu_id(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
657656
/* note that this only generates 32-bit random numbers */
658657
static u64 __get_random_u32(u64 ctx, u64 a, u64 x, u64 r4, u64 r5)
659658
{
660-
return (u64)prandom_u32();
659+
return prandom_u32();
661660
}
662661

663662
static bool convert_bpf_extensions(struct sock_filter *fp,
@@ -1475,7 +1474,7 @@ static struct sk_filter *__sk_migrate_realloc(struct sk_filter *fp,
14751474

14761475
fp_new = sock_kmalloc(sk, len, GFP_KERNEL);
14771476
if (fp_new) {
1478-
memcpy(fp_new, fp, sizeof(struct sk_filter));
1477+
*fp_new = *fp;
14791478
/* As we're kepping orig_prog in fp_new along,
14801479
* we need to make sure we're not evicting it
14811480
* from the old fp.

0 commit comments

Comments
 (0)