mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <jbrouer@redhat.com>
To: baomingtong001@208suo.com, ast@kernel.org, daniel@iogearbox.net,
	davem@davemloft.net, kuba@kernel.org, hawk@kernel.org,
	john.fastabend@gmail.com, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
	kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
	jolsa@kernel.org
Cc: brouer@redhat.com, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH] samples/bpf: Remove unneeded variable
Date: Tue, 13 Jun 2023 13:44:23 +0200	[thread overview]
Message-ID: <42972a52-81c0-1abb-68b8-b7609c8b2a5b@redhat.com> (raw)
In-Reply-To: <cf01ff5fafd7d95c604e6413fb590e65@208suo.com>



On 13/06/2023 11.18, baomingtong001@208suo.com wrote:
> Fix the following coccicheck warning:
> 
> samples/bpf/xdp1_kern.c:50: Unneeded variable: "rc".
> 
> Signed-off-by: Mingtong Bao <baomingtong001@208suo.com>
> ---
>   samples/bpf/xdp1_kern.c | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/samples/bpf/xdp1_kern.c b/samples/bpf/xdp1_kern.c
> index d91f27cbcfa9..d426df4a9d6b 100644
> --- a/samples/bpf/xdp1_kern.c
> +++ b/samples/bpf/xdp1_kern.c
> @@ -47,18 +47,17 @@ int xdp_prog1(struct xdp_md *ctx)
>       void *data_end = &pkt[XDPBUFSIZE-1];
>       void *data = pkt;
>       struct ethhdr *eth = data;
> -    int rc = XDP_DROP;
>       long *value;
>       u16 h_proto;
>       u64 nh_off;
>       u32 ipproto;
> 
>       if (bpf_xdp_load_bytes(ctx, 0, pkt, sizeof(pkt)))
> -        return rc;
> +        return XDP_DROP;

IMHO for these error cases, we should return XDP_ABORTED instead.
This will make is easier to debug, e.g. with xdpdump[1] or xdp-monitor[2].

Reminder that drivers (usually) have a tracepoint for XDP_ABORTED
(code see trace_xdp_exception).

  [1] https://github.com/xdp-project/xdp-tools/tree/master/xdp-dump
  [2] https://github.com/xdp-project/xdp-tools/tree/master/xdp-monitor

> 
>       nh_off = sizeof(*eth);
>       if (data + nh_off > data_end)
> -        return rc;
> +        return XDP_DROP;
> 
>       h_proto = eth->h_proto;
> 
> @@ -69,7 +68,7 @@ int xdp_prog1(struct xdp_md *ctx)
>           vhdr = data + nh_off;
>           nh_off += sizeof(struct vlan_hdr);
>           if (data + nh_off > data_end)
> -            return rc;
> +            return XDP_DROP;

Use XDP_ABORTED

>           h_proto = vhdr->h_vlan_encapsulated_proto;
>       }
>       /* Handle double VLAN tagged packet */
> @@ -79,7 +78,7 @@ int xdp_prog1(struct xdp_md *ctx)
>           vhdr = data + nh_off;
>           nh_off += sizeof(struct vlan_hdr);
>           if (data + nh_off > data_end)
> -            return rc;
> +            return XDP_DROP;

Use XDP_ABORTED

>           h_proto = vhdr->h_vlan_encapsulated_proto;
>       }
> 
> @@ -94,7 +93,7 @@ int xdp_prog1(struct xdp_md *ctx)
>       if (value)
>           *value += 1;
> 
> -    return rc;
> +    return XDP_DROP;

This is correct.  Here use XDP_DROP.

>   }
> 
>   char _license[] SEC("license") = "GPL";


           reply	other threads:[~2023-06-13 11:45 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <cf01ff5fafd7d95c604e6413fb590e65@208suo.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42972a52-81c0-1abb-68b8-b7609c8b2a5b@redhat.com \
    --to=jbrouer@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=baomingtong001@208suo.com \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=haoluo@google.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®