can: add destructor for self generated skbs
Self generated skbuffs in net/can/bcm.c are setting a skb->sk reference but
no explicit destructor which is enforced since Linux 3.11 with commit
376c7311bd (net: add a temporary sanity check in skb_orphan()).
This patch adds some helper functions to make sure that a destructor is
properly defined when a sock reference is assigned to a CAN related skb.
To create an unshared skb owned by the original sock a common helper function
has been introduced to replace open coded functions to create CAN echo skbs.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Andre Naujoks <nautsch2@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
920a0fde5a
commit
0ae89beb28
@@ -46,6 +46,7 @@
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/can.h>
|
||||
#include <linux/can/dev.h>
|
||||
#include <linux/can/skb.h>
|
||||
#include <linux/slab.h>
|
||||
#include <net/rtnetlink.h>
|
||||
|
||||
@@ -109,25 +110,23 @@ static netdev_tx_t vcan_tx(struct sk_buff *skb, struct net_device *dev)
|
||||
stats->rx_packets++;
|
||||
stats->rx_bytes += cfd->len;
|
||||
}
|
||||
kfree_skb(skb);
|
||||
consume_skb(skb);
|
||||
return NETDEV_TX_OK;
|
||||
}
|
||||
|
||||
/* perform standard echo handling for CAN network interfaces */
|
||||
|
||||
if (loop) {
|
||||
struct sock *srcsk = skb->sk;
|
||||
|
||||
skb = skb_share_check(skb, GFP_ATOMIC);
|
||||
skb = can_create_echo_skb(skb);
|
||||
if (!skb)
|
||||
return NETDEV_TX_OK;
|
||||
|
||||
/* receive with packet counting */
|
||||
skb->sk = srcsk;
|
||||
vcan_rx(skb, dev);
|
||||
} else {
|
||||
/* no looped packets => no counting */
|
||||
kfree_skb(skb);
|
||||
consume_skb(skb);
|
||||
}
|
||||
return NETDEV_TX_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user