mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] samples/bpf: Remove unneeded variable
       [not found] ` <cf01ff5fafd7d95c604e6413fb590e65@208suo.com>
@ 2023-06-13 11:44   ` Jesper Dangaard Brouer
  0 siblings, 0 replies; only message in thread
From: Jesper Dangaard Brouer @ 2023-06-13 11:44 UTC (permalink / raw)
  To: baomingtong001, ast, daniel, davem, kuba, hawk, john.fastabend,
	andrii, martin.lau, song, yhs, kpsingh, sdf, haoluo, jolsa
  Cc: brouer, linux-kernel, netdev, bpf



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";


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-13 11:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20230613091309.40755-1-luojianhong@cdjrlc.com>
     [not found] ` <cf01ff5fafd7d95c604e6413fb590e65@208suo.com>
2023-06-13 11:44   ` [PATCH] samples/bpf: Remove unneeded variable Jesper Dangaard Brouer

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®