Commit 9f10374b authored by Oliver Hartkopp's avatar Oliver Hartkopp Committed by Paolo Abeni
Browse files

can: remove private CAN skb headroom infrastructure



This patch removes struct can_skb_priv which was stored at skb->head and
the can_skb_reserve() helper which was used to shift skb->head.

Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: default avatarOliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20260201-can_skb_ext-v8-5-3635d790fe8b@hartkopp.net


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent d2d91797
Loading
Loading
Loading
Loading
+9 −22
Original line number Diff line number Diff line
@@ -206,16 +206,10 @@ void can_free_echo_skb(struct net_device *dev, unsigned int idx,
EXPORT_SYMBOL_GPL(can_free_echo_skb);

/* fill common values for CAN sk_buffs */
static void init_can_skb_reserve(struct sk_buff *skb)
static void init_can_skb(struct sk_buff *skb)
{
	skb->pkt_type = PACKET_BROADCAST;
	skb->ip_summed = CHECKSUM_UNNECESSARY;

	skb_reset_mac_header(skb);
	skb_reset_network_header(skb);
	skb_reset_transport_header(skb);

	can_skb_reserve(skb);
}

struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)
@@ -223,8 +217,7 @@ struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)
	struct sk_buff *skb;
	struct can_skb_ext *csx;

	skb = netdev_alloc_skb(dev, sizeof(struct can_skb_priv) +
			       sizeof(struct can_frame));
	skb = netdev_alloc_skb(dev, sizeof(struct can_frame));
	if (unlikely(!skb))
		goto out_error_cc;

@@ -235,7 +228,7 @@ struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)
	}

	skb->protocol = htons(ETH_P_CAN);
	init_can_skb_reserve(skb);
	init_can_skb(skb);
	csx->can_iif = dev->ifindex;

	*cf = skb_put_zero(skb, sizeof(struct can_frame));
@@ -255,8 +248,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev,
	struct sk_buff *skb;
	struct can_skb_ext *csx;

	skb = netdev_alloc_skb(dev, sizeof(struct can_skb_priv) +
			       sizeof(struct canfd_frame));
	skb = netdev_alloc_skb(dev, sizeof(struct canfd_frame));
	if (unlikely(!skb))
		goto out_error_fd;

@@ -267,7 +259,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev,
	}

	skb->protocol = htons(ETH_P_CANFD);
	init_can_skb_reserve(skb);
	init_can_skb(skb);
	csx->can_iif = dev->ifindex;

	*cfd = skb_put_zero(skb, sizeof(struct canfd_frame));
@@ -294,8 +286,7 @@ struct sk_buff *alloc_canxl_skb(struct net_device *dev,
	if (data_len < CANXL_MIN_DLEN || data_len > CANXL_MAX_DLEN)
		goto out_error_xl;

	skb = netdev_alloc_skb(dev, sizeof(struct can_skb_priv) +
			       CANXL_HDR_SIZE + data_len);
	skb = netdev_alloc_skb(dev, CANXL_HDR_SIZE + data_len);
	if (unlikely(!skb))
		goto out_error_xl;

@@ -306,7 +297,7 @@ struct sk_buff *alloc_canxl_skb(struct net_device *dev,
	}

	skb->protocol = htons(ETH_P_CANXL);
	init_can_skb_reserve(skb);
	init_can_skb(skb);
	csx->can_iif = dev->ifindex;

	*cxl = skb_put_zero(skb, CANXL_HDR_SIZE + data_len);
@@ -340,14 +331,10 @@ struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf)
EXPORT_SYMBOL_GPL(alloc_can_err_skb);

/* Check for outgoing skbs that have not been created by the CAN subsystem */
static bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb)
static bool can_skb_init_valid(struct net_device *dev, struct sk_buff *skb)
{
	struct can_skb_ext *csx = can_skb_ext_find(skb);

	/* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */
	if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv)))
		return false;

	/* af_packet does not apply CAN skb specific settings */
	if (skb->ip_summed == CHECKSUM_NONE || !csx) {
		/* init CAN skb content */
@@ -405,7 +392,7 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb)
		goto inval_skb;
	}

	if (!can_skb_headroom_valid(dev, skb))
	if (!can_skb_init_valid(dev, skb))
		goto inval_skb;

	return false;
+0 −31
Original line number Diff line number Diff line
@@ -38,37 +38,6 @@ struct sk_buff *alloc_can_err_skb(struct net_device *dev,
				  struct can_frame **cf);
bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb);

/*
 * The struct can_skb_priv is used to transport additional information along
 * with the stored struct can(fd)_frame that can not be contained in existing
 * struct sk_buff elements.
 * N.B. that this information must not be modified in cloned CAN sk_buffs.
 * To modify the CAN frame content or the struct can_skb_priv content
 * skb_copy() needs to be used instead of skb_clone().
 */

/**
 * struct can_skb_priv - private additional data inside CAN sk_buffs
 * @ifindex:	ifindex of the first interface the CAN frame appeared on
 * @frame_len:	length of CAN frame in data link layer
 * @cf:		align to the following CAN frame at skb->data
 */
struct can_skb_priv {
	int ifindex;
	unsigned int frame_len;
	struct can_frame cf[];
};

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));
}

static inline struct can_skb_ext *can_skb_ext_add(struct sk_buff *skb)
{
	struct can_skb_ext *csx = skb_ext_add(skb, SKB_EXT_CAN);
+2 −5
Original line number Diff line number Diff line
@@ -312,7 +312,7 @@ static void bcm_can_tx(struct bcm_op *op)
		return;
	}

	skb = alloc_skb(op->cfsiz + sizeof(struct can_skb_priv), gfp_any());
	skb = alloc_skb(op->cfsiz, gfp_any());
	if (!skb)
		goto out;

@@ -322,7 +322,6 @@ static void bcm_can_tx(struct bcm_op *op)
		goto out;
	}

	can_skb_reserve(skb);
	csx->can_iif = dev->ifindex;

	skb_put_data(skb, cf, op->cfsiz);
@@ -1333,7 +1332,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk,
	if (!ifindex)
		return -ENODEV;

	skb = alloc_skb(cfsiz + sizeof(struct can_skb_priv), GFP_KERNEL);
	skb = alloc_skb(cfsiz, GFP_KERNEL);
	if (!skb)
		return -ENOMEM;

@@ -1343,8 +1342,6 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk,
		return -ENOMEM;
	}

	can_skb_reserve(skb);

	err = memcpy_from_msg(skb_put(skb, cfsiz), msg, cfsiz);
	if (err < 0) {
		kfree_skb(skb);
+4 −8
Original line number Diff line number Diff line
@@ -220,7 +220,7 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
	struct isotp_sock *so = isotp_sk(sk);
	int can_send_ret;

	nskb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv), gfp_any());
	nskb = alloc_skb(so->ll.mtu, gfp_any());
	if (!nskb)
		return 1;

@@ -236,9 +236,7 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
		return 1;
	}

	can_skb_reserve(nskb);
	csx->can_iif = dev->ifindex;

	nskb->dev = dev;
	can_skb_set_owner(nskb, sk);
	ncf = (struct canfd_frame *)nskb->data;
@@ -780,7 +778,7 @@ static void isotp_send_cframe(struct isotp_sock *so)
	if (!dev)
		return;

	skb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv), GFP_ATOMIC);
	skb = alloc_skb(so->ll.mtu, GFP_ATOMIC);
	if (!skb) {
		dev_put(dev);
		return;
@@ -793,7 +791,6 @@ static void isotp_send_cframe(struct isotp_sock *so)
		return;
	}

	can_skb_reserve(skb);
	csx->can_iif = dev->ifindex;

	cf = (struct canfd_frame *)skb->data;
@@ -1015,8 +1012,8 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
		goto err_out_drop;
	}

	skb = sock_alloc_send_skb(sk, so->ll.mtu + sizeof(struct can_skb_priv),
				  msg->msg_flags & MSG_DONTWAIT, &err);
	skb = sock_alloc_send_skb(sk, so->ll.mtu, msg->msg_flags & MSG_DONTWAIT,
				  &err);
	if (!skb) {
		dev_put(dev);
		goto err_out_drop;
@@ -1030,7 +1027,6 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
		goto err_out_drop;
	}

	can_skb_reserve(skb);
	csx->can_iif = dev->ifindex;

	so->tx.len = size;
+1 −3
Original line number Diff line number Diff line
@@ -891,8 +891,7 @@ static struct sk_buff *j1939_sk_alloc_skb(struct net_device *ndev,
	skb = sock_alloc_send_skb(sk,
				  size +
				  sizeof(struct can_frame) -
				  sizeof(((struct can_frame *)NULL)->data) +
				  sizeof(struct can_skb_priv),
				  sizeof(((struct can_frame *)NULL)->data),
				  msg->msg_flags & MSG_DONTWAIT, &ret);
	if (!skb)
		goto failure;
@@ -904,7 +903,6 @@ static struct sk_buff *j1939_sk_alloc_skb(struct net_device *ndev,
		goto failure;
	}

	can_skb_reserve(skb);
	csx->can_iif = ndev->ifindex;
	skb_reserve(skb, offsetof(struct can_frame, data));

Loading