@@ -54,6 +54,7 @@
#include <linux/kernel.h>
#include <linux/workqueue.h>
#include <linux/can.h>
+#include <linux/can/dev.h>
#include <linux/can/skb.h>
#include <linux/can/can-ml.h>
@@ -143,7 +144,7 @@ static struct net_device **slcan_devs;
static void slc_bump(struct slcan *sl)
{
struct sk_buff *skb;
- struct can_frame cf;
+ struct can_frame cf, *scf;
int i, tmp;
u32 tmpid;
char *cmd = sl->rbuff;
@@ -201,21 +202,11 @@ static void slc_bump(struct slcan *sl)
}
}
- skb = dev_alloc_skb(sizeof(struct can_frame) +
- sizeof(struct can_skb_priv));
- if (!skb)
+ skb = alloc_can_skb(sl->dev, &scf);
+ if (unlikely(!skb))
return;
- skb->dev = sl->dev;
- skb->protocol = htons(ETH_P_CAN);
- skb->pkt_type = PACKET_BROADCAST;
- skb->ip_summed = CHECKSUM_UNNECESSARY;
-
- can_skb_reserve(skb);
- can_skb_prv(skb)->ifindex = sl->dev->ifindex;
- can_skb_prv(skb)->skbcnt = 0;
-
- skb_put_data(skb, &cf, sizeof(struct can_frame));
+ memcpy(scf, &cf, sizeof(*scf));
sl->dev->stats.rx_packets++;
if (!(cf.can_id & CAN_RTR_FLAG))
It is used successfully by most (if not all) CAN device drivers. It allows to remove replicated code. Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> --- drivers/net/can/slcan.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)