[bpf-next] bpf: switch to offsetofend in BPF_PROG_TEST_RUN
diff mbox series

Message ID 20191210191933.105321-1-sdf@google.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series
  • [bpf-next] bpf: switch to offsetofend in BPF_PROG_TEST_RUN
Related show

Commit Message

Stanislav Fomichev Dec. 10, 2019, 7:19 p.m. UTC
Switch existing pattern of "offsetof(..., member) + FIELD_SIZEOF(...,
member)' to "offsetofend(..., member)" which does exactly what
we need without all the copy-paste.

Suggested-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 net/bpf/test_run.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Comments

Andrii Nakryiko Dec. 10, 2019, 7:34 p.m. UTC | #1
On Tue, Dec 10, 2019 at 11:20 AM Stanislav Fomichev <sdf@google.com> wrote:
>
> Switch existing pattern of "offsetof(..., member) + FIELD_SIZEOF(...,
> member)' to "offsetofend(..., member)" which does exactly what
> we need without all the copy-paste.
>
> Suggested-by: Andrii Nakryiko <andriin@fb.com>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---

Awesome!

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  net/bpf/test_run.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
>

[...]
Daniel Borkmann Dec. 11, 2019, 1:57 p.m. UTC | #2
On Tue, Dec 10, 2019 at 11:19:33AM -0800, Stanislav Fomichev wrote:
> Switch existing pattern of "offsetof(..., member) + FIELD_SIZEOF(...,
> member)' to "offsetofend(..., member)" which does exactly what
> we need without all the copy-paste.
> 
> Suggested-by: Andrii Nakryiko <andriin@fb.com>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>

Applied, thanks!

Patch
diff mbox series

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 915c2d6f7fb9..85c8cbbada92 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -252,22 +252,19 @@  static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
 
 	/* priority is allowed */
 
-	if (!range_is_zero(__skb, offsetof(struct __sk_buff, priority) +
-			   FIELD_SIZEOF(struct __sk_buff, priority),
+	if (!range_is_zero(__skb, offsetofend(struct __sk_buff, priority),
 			   offsetof(struct __sk_buff, cb)))
 		return -EINVAL;
 
 	/* cb is allowed */
 
-	if (!range_is_zero(__skb, offsetof(struct __sk_buff, cb) +
-			   FIELD_SIZEOF(struct __sk_buff, cb),
+	if (!range_is_zero(__skb, offsetofend(struct __sk_buff, cb),
 			   offsetof(struct __sk_buff, tstamp)))
 		return -EINVAL;
 
 	/* tstamp is allowed */
 
-	if (!range_is_zero(__skb, offsetof(struct __sk_buff, tstamp) +
-			   FIELD_SIZEOF(struct __sk_buff, tstamp),
+	if (!range_is_zero(__skb, offsetofend(struct __sk_buff, tstamp),
 			   sizeof(struct __sk_buff)))
 		return -EINVAL;
 
@@ -437,8 +434,7 @@  static int verify_user_bpf_flow_keys(struct bpf_flow_keys *ctx)
 
 	/* flags is allowed */
 
-	if (!range_is_zero(ctx, offsetof(struct bpf_flow_keys, flags) +
-			   FIELD_SIZEOF(struct bpf_flow_keys, flags),
+	if (!range_is_zero(ctx, offsetofend(struct bpf_flow_keys, flags),
 			   sizeof(struct bpf_flow_keys)))
 		return -EINVAL;