This commit moves the kfree_skb() call on queue full event from the
ipv4/ipv6 caller into __udp_enqueue_schedule_skb(), cleaning up the
code and avoid referencing the skb after that __udp_enqueue_schedule_skb()
completes, so that we can modify the skb ptr itself into the latter
function.

Signed-off-by: Paolo Abeni <pab...@redhat.com>
---
 net/ipv4/udp.c | 2 +-
 net/ipv6/udp.c | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 24b5c59b1c53..3fb0fbf4977d 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1341,6 +1341,7 @@ int __udp_enqueue_schedule_skb(struct sock *sk, struct 
sk_buff *skb)
 drop:
        atomic_inc(&sk->sk_drops);
        busylock_release(busy);
+       kfree_skb(skb);
        return err;
 }
 EXPORT_SYMBOL_GPL(__udp_enqueue_schedule_skb);
@@ -1802,7 +1803,6 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct 
sk_buff *skb)
                        UDP_INC_STATS(sock_net(sk), UDP_MIB_RCVBUFERRORS,
                                        is_udplite);
                UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
-               kfree_skb(skb);
                trace_udp_fail_queue_rcv_skb(rc, sk);
                return -1;
        }
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 6861ed479469..c113222f7670 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -532,7 +532,6 @@ static int __udpv6_queue_rcv_skb(struct sock *sk, struct 
sk_buff *skb)
                        UDP6_INC_STATS(sock_net(sk),
                                         UDP_MIB_RCVBUFERRORS, is_udplite);
                UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
-               kfree_skb(skb);
                return -1;
        }
 
-- 
2.14.3

Reply via email to