Skip to content

Commit

Permalink
can: rework skb reserved data handling
Browse files Browse the repository at this point in the history
Added accessor and skb_reserve helpers for struct can_skb_priv.
Removed pointless skb_headroom() check.

Signed-off-by: Oliver Hartkopp <[email protected]>
CC: Marc Kleine-Budde <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
hartkopp authored and davem330 committed Jan 28, 2013
1 parent cef401d commit 2bf3440
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions drivers/net/can/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/can/slcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 10 additions & 0 deletions include/linux/can/skb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
8 changes: 4 additions & 4 deletions net/can/bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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 */
Expand Down
4 changes: 1 addition & 3 deletions net/can/gw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
Expand Down
4 changes: 2 additions & 2 deletions net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2bf3440

Please sign in to comment.