mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
net: core: Specify skb_pad()/skb_put_padto() SKB freeing
Rename skb_pad() into __skb_pad() and make it take a third argument: free_on_error which controls whether kfree_skb() should be called or not, skb_pad() directly makes use of it and passes true to preserve its existing behavior. Do exactly the same thing with __skb_put_padto() and skb_put_padto(). Suggested-by: David Miller <davem@davemloft.net> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Woojung Huh <Woojung.Huh@microchip.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
013dae5dbc
commit
cd0a137acb
2 changed files with 51 additions and 15 deletions
|
@ -973,7 +973,23 @@ int __must_check skb_to_sgvec_nomark(struct sk_buff *skb, struct scatterlist *sg
|
|||
int __must_check skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg,
|
||||
int offset, int len);
|
||||
int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer);
|
||||
int skb_pad(struct sk_buff *skb, int pad);
|
||||
int __skb_pad(struct sk_buff *skb, int pad, bool free_on_error);
|
||||
|
||||
/**
|
||||
* skb_pad - zero pad the tail of an skb
|
||||
* @skb: buffer to pad
|
||||
* @pad: space to pad
|
||||
*
|
||||
* Ensure that a buffer is followed by a padding area that is zero
|
||||
* filled. Used by network drivers which may DMA or transfer data
|
||||
* beyond the buffer end onto the wire.
|
||||
*
|
||||
* May return error in out of memory cases. The skb is freed on error.
|
||||
*/
|
||||
static inline int skb_pad(struct sk_buff *skb, int pad)
|
||||
{
|
||||
return __skb_pad(skb, pad, true);
|
||||
}
|
||||
#define dev_kfree_skb(a) consume_skb(a)
|
||||
|
||||
int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
|
||||
|
@ -2821,6 +2837,31 @@ static inline int skb_padto(struct sk_buff *skb, unsigned int len)
|
|||
return skb_pad(skb, len - size);
|
||||
}
|
||||
|
||||
/**
|
||||
* skb_put_padto - increase size and pad an skbuff up to a minimal size
|
||||
* @skb: buffer to pad
|
||||
* @len: minimal length
|
||||
* @free_on_error: free buffer on error
|
||||
*
|
||||
* Pads up a buffer to ensure the trailing bytes exist and are
|
||||
* blanked. If the buffer already contains sufficient data it
|
||||
* is untouched. Otherwise it is extended. Returns zero on
|
||||
* success. The skb is freed on error if @free_on_error is true.
|
||||
*/
|
||||
static inline int __skb_put_padto(struct sk_buff *skb, unsigned int len,
|
||||
bool free_on_error)
|
||||
{
|
||||
unsigned int size = skb->len;
|
||||
|
||||
if (unlikely(size < len)) {
|
||||
len -= size;
|
||||
if (__skb_pad(skb, len, free_on_error))
|
||||
return -ENOMEM;
|
||||
__skb_put(skb, len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* skb_put_padto - increase size and pad an skbuff up to a minimal size
|
||||
* @skb: buffer to pad
|
||||
|
@ -2833,15 +2874,7 @@ static inline int skb_padto(struct sk_buff *skb, unsigned int len)
|
|||
*/
|
||||
static inline int skb_put_padto(struct sk_buff *skb, unsigned int len)
|
||||
{
|
||||
unsigned int size = skb->len;
|
||||
|
||||
if (unlikely(size < len)) {
|
||||
len -= size;
|
||||
if (skb_pad(skb, len))
|
||||
return -ENOMEM;
|
||||
__skb_put(skb, len);
|
||||
}
|
||||
return 0;
|
||||
return __skb_put_padto(skb, len, true);
|
||||
}
|
||||
|
||||
static inline int skb_add_data(struct sk_buff *skb,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue