aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/can/sja1000
diff options
context:
space:
mode:
authorWolfgang Grandegger <wg@grandegger.com>2009-10-20 03:08:01 -0400
committerDavid S. Miller <davem@davemloft.net>2009-10-20 03:08:01 -0400
commit7b6856a0296a8f187bb88ba31fa83a08abba7966 (patch)
tree0afbcc9291eeb368e4e4616b6eed9062df646de0 /drivers/net/can/sja1000
parent0eae750e6019a93643063924209c1daf9cb9b4a7 (diff)
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>
Diffstat (limited to 'drivers/net/can/sja1000')
-rw-r--r--drivers/net/can/sja1000/sja1000.c12
1 files changed, 2 insertions, 10 deletions
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 96d8be4253f8..1a9c5958bbd7 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -296,11 +296,9 @@ static void sja1000_rx(struct net_device *dev)
296 uint8_t dlc; 296 uint8_t dlc;
297 int i; 297 int i;
298 298
299 skb = dev_alloc_skb(sizeof(struct can_frame)); 299 skb = alloc_can_skb(dev, &cf);
300 if (skb == NULL) 300 if (skb == NULL)
301 return; 301 return;
302 skb->dev = dev;
303 skb->protocol = htons(ETH_P_CAN);
304 302
305 fi = priv->read_reg(priv, REG_FI); 303 fi = priv->read_reg(priv, REG_FI);
306 dlc = fi & 0x0F; 304 dlc = fi & 0x0F;
@@ -351,15 +349,9 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status)
351 enum can_state state = priv->can.state; 349 enum can_state state = priv->can.state;
352 uint8_t ecc, alc; 350 uint8_t ecc, alc;
353 351
354 skb = dev_alloc_skb(sizeof(struct can_frame)); 352 skb = alloc_can_err_skb(dev, &cf);
355 if (skb == NULL) 353 if (skb == NULL)
356 return -ENOMEM; 354 return -ENOMEM;
357 skb->dev = dev;
358 skb->protocol = htons(ETH_P_CAN);
359 cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
360 memset(cf, 0, sizeof(struct can_frame));
361 cf->can_id = CAN_ERR_FLAG;
362 cf->can_dlc = CAN_ERR_DLC;
363 355
364 if (isrc & IRQ_DOI) { 356 if (isrc & IRQ_DOI) {
365 /* data overrun interrupt */ 357 /* data overrun interrupt */