diff options
author | Wolfgang Grandegger <wg@grandegger.com> | 2009-10-20 03:08:01 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-10-20 03:08:01 -0400 |
commit | 7b6856a0296a8f187bb88ba31fa83a08abba7966 (patch) | |
tree | 0afbcc9291eeb368e4e4616b6eed9062df646de0 /drivers/net/can/usb | |
parent | 0eae750e6019a93643063924209c1daf9cb9b4a7 (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/usb')
-rw-r--r-- | drivers/net/can/usb/ems_usb.c | 16 |
1 files changed, 2 insertions, 14 deletions
diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c index a65f56a9cd3d..3685f3e42d12 100644 --- a/drivers/net/can/usb/ems_usb.c +++ b/drivers/net/can/usb/ems_usb.c | |||
@@ -311,14 +311,10 @@ static void ems_usb_rx_can_msg(struct ems_usb *dev, struct ems_cpc_msg *msg) | |||
311 | int i; | 311 | int i; |
312 | struct net_device_stats *stats = &dev->netdev->stats; | 312 | struct net_device_stats *stats = &dev->netdev->stats; |
313 | 313 | ||
314 | skb = netdev_alloc_skb(dev->netdev, sizeof(struct can_frame)); | 314 | skb = alloc_can_skb(dev->netdev, &cf); |
315 | if (skb == NULL) | 315 | if (skb == NULL) |
316 | return; | 316 | return; |
317 | 317 | ||
318 | skb->protocol = htons(ETH_P_CAN); | ||
319 | |||
320 | cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame)); | ||
321 | |||
322 | cf->can_id = msg->msg.can_msg.id; | 318 | cf->can_id = msg->msg.can_msg.id; |
323 | cf->can_dlc = min_t(u8, msg->msg.can_msg.length, 8); | 319 | cf->can_dlc = min_t(u8, msg->msg.can_msg.length, 8); |
324 | 320 | ||
@@ -346,18 +342,10 @@ static void ems_usb_rx_err(struct ems_usb *dev, struct ems_cpc_msg *msg) | |||
346 | struct sk_buff *skb; | 342 | struct sk_buff *skb; |
347 | struct net_device_stats *stats = &dev->netdev->stats; | 343 | struct net_device_stats *stats = &dev->netdev->stats; |
348 | 344 | ||
349 | skb = netdev_alloc_skb(dev->netdev, sizeof(struct can_frame)); | 345 | skb = alloc_can_err_skb(dev->netdev, &cf); |
350 | if (skb == NULL) | 346 | if (skb == NULL) |
351 | return; | 347 | return; |
352 | 348 | ||
353 | skb->protocol = htons(ETH_P_CAN); | ||
354 | |||
355 | cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame)); | ||
356 | memset(cf, 0, sizeof(struct can_frame)); | ||
357 | |||
358 | cf->can_id = CAN_ERR_FLAG; | ||
359 | cf->can_dlc = CAN_ERR_DLC; | ||
360 | |||
361 | if (msg->type == CPC_MSG_TYPE_CAN_STATE) { | 349 | if (msg->type == CPC_MSG_TYPE_CAN_STATE) { |
362 | u8 state = msg->msg.can_state; | 350 | u8 state = msg->msg.can_state; |
363 | 351 | ||