can: rework skb reserved data handling
authorOliver Hartkopp <socketcan@hartkopp.net>
Mon, 28 Jan 2013 08:33:33 +0000 (08:33 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2013 23:17:25 +0000 (18:17 -0500)
Added accessor and skb_reserve helpers for struct can_skb_priv.
Removed pointless skb_headroom() check.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
CC: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/can/dev.c
drivers/net/can/slcan.c
include/linux/can/skb.h
net/can/bcm.c
net/can/gw.c
net/can/raw.c

index 59ada082a9946cca3facebc3afd5693f5935b1cf..f9cba4123c663084b66c2dbdaac5885a579278fd 100644 (file)
@@ -512,8 +512,8 @@ struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)
        skb->pkt_type = PACKET_BROADCAST;
        skb->ip_summed = CHECKSUM_UNNECESSARY;
 
-       skb_reserve(skb, sizeof(struct can_skb_priv));
-       ((struct can_skb_priv *)(skb->head))->ifindex = dev->ifindex;
+       can_skb_reserve(skb);
+       can_skb_prv(skb)->ifindex = dev->ifindex;
 
        *cf = (struct can_frame *)skb_put(skb, sizeof(struct can_frame));
        memset(*cf, 0, sizeof(struct can_frame));
index e79a8d10e0fc0a4b751efa8153e1af3ee1c47c31..06b7e097d36e5ed3117e9d1dc8258ee74d51c6be 100644 (file)
@@ -195,8 +195,8 @@ static void slc_bump(struct slcan *sl)
        skb->pkt_type = PACKET_BROADCAST;
        skb->ip_summed = CHECKSUM_UNNECESSARY;
 
-       skb_reserve(skb, sizeof(struct can_skb_priv));
-       ((struct can_skb_priv *)(skb->head))->ifindex = sl->dev->ifindex;
+       can_skb_reserve(skb);
+       can_skb_prv(skb)->ifindex = sl->dev->ifindex;
 
        memcpy(skb_put(skb, sizeof(struct can_frame)),
               &cf, sizeof(struct can_frame));
index 4b0f24d3a8780811ffb5a2041e205b4e416339af..2f0543f7510c65aa71c5b5de43315da8d64c51aa 100644 (file)
@@ -32,4 +32,14 @@ struct can_skb_priv {
        struct can_frame cf[0];
 };
 
+static inline struct can_skb_priv *can_skb_prv(struct sk_buff *skb)
+{
+       return (struct can_skb_priv *)(skb->head);
+}
+
+static inline void can_skb_reserve(struct sk_buff *skb)
+{
+       skb_reserve(skb, sizeof(struct can_skb_priv));
+}
+
 #endif /* CAN_SKB_H */
index ccc27b9e8384f710777d2f207d18817a39bb01f2..28e12d18f0f147b592ee5e4975f4cecf3c5b7c2f 100644 (file)
@@ -261,8 +261,8 @@ static void bcm_can_tx(struct bcm_op *op)
        if (!skb)
                goto out;
 
-       skb_reserve(skb, sizeof(struct can_skb_priv));
-       ((struct can_skb_priv *)(skb->head))->ifindex = dev->ifindex;
+       can_skb_reserve(skb);
+       can_skb_prv(skb)->ifindex = dev->ifindex;
 
        memcpy(skb_put(skb, CFSIZ), cf, CFSIZ);
 
@@ -1207,7 +1207,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)
        if (!skb)
                return -ENOMEM;
 
-       skb_reserve(skb, sizeof(struct can_skb_priv));
+       can_skb_reserve(skb);
 
        err = memcpy_fromiovec(skb_put(skb, CFSIZ), msg->msg_iov, CFSIZ);
        if (err < 0) {
@@ -1221,7 +1221,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)
                return -ENODEV;
        }
 
-       ((struct can_skb_priv *)(skb->head))->ifindex = dev->ifindex;
+       can_skb_prv(skb)->ifindex = dev->ifindex;
        skb->dev = dev;
        skb->sk  = sk;
        err = can_send(skb, 1); /* send with loopback */
index acdd4656cc3bef2d7e6f2b73436b6fd019b2cc66..c185fcd5e828b5b7fe0dddd9db237b2f172b50c9 100644 (file)
@@ -381,9 +381,7 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)
 
        /* is sending the skb back to the incoming interface not allowed? */
        if (!(gwj->flags & CGW_FLAGS_CAN_IIF_TX_OK) &&
-           skb_headroom(skb) == sizeof(struct can_skb_priv) &&
-           (((struct can_skb_priv *)(skb->head))->ifindex ==
-            gwj->dst.dev->ifindex))
+           can_skb_prv(skb)->ifindex == gwj->dst.dev->ifindex)
                return;
 
        /*
index 5d860e8dcc522bf9e77ab4bc35d5aaa21536d547..c1764e41ddaf924fed4e31972b938a84bb87b6f7 100644 (file)
@@ -705,8 +705,8 @@ static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
        if (!skb)
                goto put_dev;
 
-       skb_reserve(skb, sizeof(struct can_skb_priv));
-       ((struct can_skb_priv *)(skb->head))->ifindex = dev->ifindex;
+       can_skb_reserve(skb);
+       can_skb_prv(skb)->ifindex = dev->ifindex;
 
        err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
        if (err < 0)