]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: always set reason in sk_filter_trim_cap()
authorEric Dumazet <edumazet@google.com>
Thu, 9 Apr 2026 14:56:21 +0000 (14:56 +0000)
committerJakub Kicinski <kuba@kernel.org>
Sun, 12 Apr 2026 21:30:25 +0000 (14:30 -0700)
sk_filter_trim_cap() will soon return the drop reason by value.

Make sure *reason is cleared when no error is returned,
to ease this conversion.

$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-7 (-7)
Function                                     old     new   delta
sk_filter_trim_cap                           889     882      -7
Total: Before=29722668, After=29722661, chg -0.00%

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260409145625.2306224-3-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/filter.c

index cf2113af4bc9ae7c976d7c55f3092643e1d875b6..5569d83b8be06dc1fe64ddff2ae338acd1622ed7 100644 (file)
@@ -121,7 +121,7 @@ EXPORT_SYMBOL_GPL(copy_bpf_fprog_from_user);
  *     @sk: sock associated with &sk_buff
  *     @skb: buffer to filter
  *     @cap: limit on how short the eBPF program may trim the packet
- *     @reason: record drop reason on errors (negative return value)
+ *     @reason: record drop reason
  *
  * Run the eBPF program and then cut skb->data to correct size returned by
  * the program. If pkt_len is 0 we toss packet. If skb->len is smaller
@@ -168,11 +168,10 @@ int sk_filter_trim_cap(struct sock *sk, struct sk_buff *skb,
                pkt_len = bpf_prog_run_save_cb(filter->prog, skb);
                skb->sk = save_sk;
                err = pkt_len ? pskb_trim(skb, max(cap, pkt_len)) : -EPERM;
-               if (err)
-                       *reason = SKB_DROP_REASON_SOCKET_FILTER;
        }
        rcu_read_unlock();
 
+       *reason = err ? SKB_DROP_REASON_SOCKET_FILTER : 0;
        return err;
 }
 EXPORT_SYMBOL(sk_filter_trim_cap);