mirror of
https://github.com/torvalds/linux.git
synced 2024-12-30 14:52:05 +00:00
net: dsa: sja1105: Fix memory leak on meta state machine normal path
After a meta frame is received, it is associated with the cached
sp->data->stampable_skb from the DSA tagger private structure.
Cached means its refcount is incremented with skb_get() in order for
dsa_switch_rcv() to not free it when the tagger .rcv returns NULL.
The mistake is that skb_unref() is not the correct function to use. It
will correctly decrement the refcount (which will go back to zero) but
the skb memory will not be freed. That is the job of kfree_skb(), which
also calls skb_unref().
But it turns out that freeing the cached stampable_skb is in fact not
necessary. It is still a perfectly valid skb, and now it is even
annotated with the partial RX timestamp. So remove the skb_copy()
altogether and simply pass the stampable_skb with a refcount of 1
(incremented by us, decremented by dsa_switch_rcv) up the stack.
Fixes: f3097be21b
("net: dsa: sja1105: Add a state machine for RX timestamping")
Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
6cb0abbdf9
commit
f163fed276
@ -211,17 +211,8 @@ static struct sk_buff
|
||||
* for further processing up the network stack.
|
||||
*/
|
||||
kfree_skb(skb);
|
||||
|
||||
skb = skb_copy(stampable_skb, GFP_ATOMIC);
|
||||
if (!skb) {
|
||||
dev_err_ratelimited(dp->ds->dev,
|
||||
"Failed to copy stampable skb\n");
|
||||
spin_unlock(&sp->data->meta_lock);
|
||||
return NULL;
|
||||
}
|
||||
skb = stampable_skb;
|
||||
sja1105_transfer_meta(skb, meta);
|
||||
/* The cached copy will be freed now */
|
||||
skb_unref(stampable_skb);
|
||||
|
||||
spin_unlock(&sp->data->meta_lock);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user