]> git.ipfire.org Git - people/ms/linux.git/blame - net/rxrpc/skbuff.c
Merge branch 'arm/fixes' into arm/late
[people/ms/linux.git] / net / rxrpc / skbuff.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
17926a79
DH
2/* ar-skbuff.c: socket buffer destruction handling
3 *
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
17926a79
DH
6 */
7
9b6d5398
JP
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
17926a79
DH
10#include <linux/module.h>
11#include <linux/net.h>
12#include <linux/skbuff.h>
13#include <net/sock.h>
14#include <net/af_rxrpc.h>
15#include "ar-internal.h"
16
987db9f7
DH
17#define is_tx_skb(skb) (rxrpc_skb(skb)->rx_flags & RXRPC_SKB_TX_BUFFER)
18#define select_skb_count(skb) (is_tx_skb(skb) ? &rxrpc_n_tx_skbs : &rxrpc_n_rx_skbs)
71f3ca40 19
df844fd4 20/*
71f3ca40 21 * Note the allocation or reception of a socket buffer.
df844fd4 22 */
71f3ca40 23void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
df844fd4
DH
24{
25 const void *here = __builtin_return_address(0);
987db9f7 26 int n = atomic_inc_return(select_skb_count(skb));
d0d5c0cd
DH
27 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
28 rxrpc_skb(skb)->rx_flags, here);
df844fd4
DH
29}
30
31/*
32 * Note the re-emergence of a socket buffer from a queue or buffer.
33 */
71f3ca40 34void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
df844fd4
DH
35{
36 const void *here = __builtin_return_address(0);
37 if (skb) {
987db9f7 38 int n = atomic_read(select_skb_count(skb));
d0d5c0cd
DH
39 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
40 rxrpc_skb(skb)->rx_flags, here);
df844fd4
DH
41 }
42}
43
44/*
45 * Note the addition of a ref on a socket buffer.
46 */
71f3ca40 47void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
df844fd4
DH
48{
49 const void *here = __builtin_return_address(0);
987db9f7 50 int n = atomic_inc_return(select_skb_count(skb));
d0d5c0cd
DH
51 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
52 rxrpc_skb(skb)->rx_flags, here);
df844fd4
DH
53 skb_get(skb);
54}
55
d0d5c0cd
DH
56/*
57 * Note the dropping of a ref on a socket buffer by the core.
58 */
59void rxrpc_eaten_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
60{
61 const void *here = __builtin_return_address(0);
62 int n = atomic_inc_return(&rxrpc_n_rx_skbs);
63 trace_rxrpc_skb(skb, op, 0, n, 0, here);
64}
65
df844fd4
DH
66/*
67 * Note the destruction of a socket buffer.
68 */
71f3ca40 69void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
df844fd4
DH
70{
71 const void *here = __builtin_return_address(0);
72 if (skb) {
73 int n;
987db9f7 74 n = atomic_dec_return(select_skb_count(skb));
d0d5c0cd
DH
75 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n,
76 rxrpc_skb(skb)->rx_flags, here);
df844fd4
DH
77 kfree_skb(skb);
78 }
79}
80
81/*
82 * Clear a queue of socket buffers.
83 */
84void rxrpc_purge_queue(struct sk_buff_head *list)
85{
86 const void *here = __builtin_return_address(0);
87 struct sk_buff *skb;
88 while ((skb = skb_dequeue((list))) != NULL) {
987db9f7
DH
89 int n = atomic_dec_return(select_skb_count(skb));
90 trace_rxrpc_skb(skb, rxrpc_skb_purged,
d0d5c0cd
DH
91 refcount_read(&skb->users), n,
92 rxrpc_skb(skb)->rx_flags, here);
df844fd4
DH
93 kfree_skb(skb);
94 }
95}