[PATCH v2] can: provide library functions for skb allocation

Previous thread: [net-next-2.6 PATCH 4/4 resent] TCPCT part 1d: initial SYN exchange with SYNACK data by William Allen Simpson on Sunday, October 18, 2009 - 9:28 am. (1 message)

Next thread: kernel panic in latest vanilla stable, while using nameif with "alive" pppoe interfaces by Denys Fedoryschenko on Sunday, October 18, 2009 - 2:02 pm. (34 messages)
From: Wolfgang Grandegger
Date: Sunday, October 18, 2009 - 11:45 am

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>
---
 drivers/net/can/at91_can.c        |   32 ----------------------------
 drivers/net/can/dev.c             |   42 +++++++++++++++++++++++++++++++-------
 drivers/net/can/sja1000/sja1000.c |   12 +---------
 drivers/net/can/ti_hecc.c         |   17 +++------------
 drivers/net/can/usb/ems_usb.c     |   16 +-------------
 5 files changed, 43 insertions(+), 76 deletions(-)

Index: net-next-2.6/drivers/net/can/dev.c
===================================================================
--- net-next-2.6.orig/drivers/net/can/dev.c
+++ net-next-2.6/drivers/net/can/dev.c
@@ -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 ...
From: David Miller
Date: Monday, October 19, 2009 - 9:54 pm

From: Wolfgang Grandegger <wg@grandegger.com>

Applied, thanks.
--

From: David Miller
Date: Monday, October 19, 2009 - 11:05 pm

From: David Miller <davem@davemloft.net>

Actually I have to back this out, you have to add an extern
declaration for these public functions to a header the CAN
drivers will see, or else there'll be build warnings and
errors.

I wonder if you actually did this, but forgot that part of
the change or lost it somehow while respinning this.

Please fix this up and resubmit, thanks.
--

From: Wolfgang Grandegger
Date: Monday, October 19, 2009 - 11:43 pm

Already the original patch was incomplete and I obviously forgot to
compile test it. I was sure that I did that already, but, well, sorry

Will resubmit in a second.

Thanks,

Wolfgang.

--

Previous thread: [net-next-2.6 PATCH 4/4 resent] TCPCT part 1d: initial SYN exchange with SYNACK data by William Allen Simpson on Sunday, October 18, 2009 - 9:28 am. (1 message)

Next thread: kernel panic in latest vanilla stable, while using nameif with "alive" pppoe interfaces by Denys Fedoryschenko on Sunday, October 18, 2009 - 2:02 pm. (34 messages)