mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-26 00:21:17 +00:00
can: provide library functions for skb allocation
This patch makes the private functions alloc_can_skb() and alloc_can_err_skb() of the at91_can driver public and adapts all drivers to use these. While making the patch I realized, that the skb's are *not* setup consistently. It's now done as shown below: skb->protocol = htons(ETH_P_CAN); skb->pkt_type = PACKET_BROADCAST; skb->ip_summed = CHECKSUM_UNNECESSARY; *cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame)); memset(*cf, 0, sizeof(struct can_frame)); The frame is zeroed out to avoid uninitialized data to be passed to user space. Some drivers or library code did not set "pkt_type" or "ip_summed". Also, "__constant_htons()" should not be used for runtime invocations, as pointed out by David Miller. Signed-off-by: Wolfgang Grandegger <wg@grandegger.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
0eae750e60
commit
7b6856a029
6 changed files with 47 additions and 76 deletions
|
@ -366,17 +366,12 @@ void can_restart(unsigned long data)
|
|||
can_flush_echo_skb(dev);
|
||||
|
||||
/* send restart message upstream */
|
||||
skb = dev_alloc_skb(sizeof(struct can_frame));
|
||||
skb = alloc_can_err_skb(dev, &cf);
|
||||
if (skb == NULL) {
|
||||
err = -ENOMEM;
|
||||
goto restart;
|
||||
}
|
||||
skb->dev = dev;
|
||||
skb->protocol = htons(ETH_P_CAN);
|
||||
cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
|
||||
memset(cf, 0, sizeof(struct can_frame));
|
||||
cf->can_id = CAN_ERR_FLAG | CAN_ERR_RESTARTED;
|
||||
cf->can_dlc = CAN_ERR_DLC;
|
||||
cf->can_id |= CAN_ERR_RESTARTED;
|
||||
|
||||
netif_rx(skb);
|
||||
|
||||
|
@ -449,6 +444,39 @@ static void can_setup(struct net_device *dev)
|
|||
dev->features = NETIF_F_NO_CSUM;
|
||||
}
|
||||
|
||||
struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
|
||||
skb = netdev_alloc_skb(dev, sizeof(struct can_frame));
|
||||
if (unlikely(!skb))
|
||||
return NULL;
|
||||
|
||||
skb->protocol = htons(ETH_P_CAN);
|
||||
skb->pkt_type = PACKET_BROADCAST;
|
||||
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
||||
*cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
|
||||
memset(*cf, 0, sizeof(struct can_frame));
|
||||
|
||||
return skb;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(alloc_can_skb);
|
||||
|
||||
struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
|
||||
skb = alloc_can_skb(dev, cf);
|
||||
if (unlikely(!skb))
|
||||
return NULL;
|
||||
|
||||
(*cf)->can_id = CAN_ERR_FLAG;
|
||||
(*cf)->can_dlc = CAN_ERR_DLC;
|
||||
|
||||
return skb;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(alloc_can_err_skb);
|
||||
|
||||
/*
|
||||
* Allocate and setup space for the CAN network device
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue