Skip to content

Commit ccd8a93

Browse files
vincent-mailholmarckleinebudde
authored andcommitted
can: skb: move can_dropped_invalid_skb() and can_skb_headroom_valid() to skb.c
The functions can_dropped_invalid_skb() and can_skb_headroom_valid() grew a lot over the years to a point which it does not make much sense to have them defined as static inline in header files. Move those two functions to the .c counterpart of skb.h. can_skb_headroom_valid()'s only caller being can_dropped_invalid_skb(), the declaration is removed from the header. Only can_dropped_invalid_skb() gets its symbol exported. While doing so, do a small cleanup: add brackets around the else block in can_dropped_invalid_skb(). Link: https://lore.kernel.org/all/[email protected] Signed-off-by: Vincent Mailhol <[email protected]> Reported-by: kernel test robot <[email protected]> Acked-by: Max Staudt <[email protected]> Tested-by: Oliver Hartkopp <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent d7786af commit ccd8a93

File tree

2 files changed

+59
-58
lines changed

2 files changed

+59
-58
lines changed

drivers/net/can/dev/skb.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,61 @@ struct sk_buff *alloc_can_err_skb(struct net_device *dev, struct can_frame **cf)
259259
return skb;
260260
}
261261
EXPORT_SYMBOL_GPL(alloc_can_err_skb);
262+
263+
/* Check for outgoing skbs that have not been created by the CAN subsystem */
264+
static bool can_skb_headroom_valid(struct net_device *dev, struct sk_buff *skb)
265+
{
266+
/* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */
267+
if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv)))
268+
return false;
269+
270+
/* af_packet does not apply CAN skb specific settings */
271+
if (skb->ip_summed == CHECKSUM_NONE) {
272+
/* init headroom */
273+
can_skb_prv(skb)->ifindex = dev->ifindex;
274+
can_skb_prv(skb)->skbcnt = 0;
275+
276+
skb->ip_summed = CHECKSUM_UNNECESSARY;
277+
278+
/* perform proper loopback on capable devices */
279+
if (dev->flags & IFF_ECHO)
280+
skb->pkt_type = PACKET_LOOPBACK;
281+
else
282+
skb->pkt_type = PACKET_HOST;
283+
284+
skb_reset_mac_header(skb);
285+
skb_reset_network_header(skb);
286+
skb_reset_transport_header(skb);
287+
}
288+
289+
return true;
290+
}
291+
292+
/* Drop a given socketbuffer if it does not contain a valid CAN frame. */
293+
bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb)
294+
{
295+
const struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
296+
297+
if (skb->protocol == htons(ETH_P_CAN)) {
298+
if (unlikely(skb->len != CAN_MTU ||
299+
cfd->len > CAN_MAX_DLEN))
300+
goto inval_skb;
301+
} else if (skb->protocol == htons(ETH_P_CANFD)) {
302+
if (unlikely(skb->len != CANFD_MTU ||
303+
cfd->len > CANFD_MAX_DLEN))
304+
goto inval_skb;
305+
} else {
306+
goto inval_skb;
307+
}
308+
309+
if (!can_skb_headroom_valid(dev, skb))
310+
goto inval_skb;
311+
312+
return false;
313+
314+
inval_skb:
315+
kfree_skb(skb);
316+
dev->stats.tx_dropped++;
317+
return true;
318+
}
319+
EXPORT_SYMBOL_GPL(can_dropped_invalid_skb);

include/linux/can/skb.h

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct sk_buff *alloc_canfd_skb(struct net_device *dev,
3131
struct canfd_frame **cfd);
3232
struct sk_buff *alloc_can_err_skb(struct net_device *dev,
3333
struct can_frame **cf);
34+
bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb);
3435

3536
/*
3637
* The struct can_skb_priv is used to transport additional information along
@@ -96,64 +97,6 @@ static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb)
9697
return nskb;
9798
}
9899

99-
/* Check for outgoing skbs that have not been created by the CAN subsystem */
100-
static inline bool can_skb_headroom_valid(struct net_device *dev,
101-
struct sk_buff *skb)
102-
{
103-
/* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */
104-
if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv)))
105-
return false;
106-
107-
/* af_packet does not apply CAN skb specific settings */
108-
if (skb->ip_summed == CHECKSUM_NONE) {
109-
/* init headroom */
110-
can_skb_prv(skb)->ifindex = dev->ifindex;
111-
can_skb_prv(skb)->skbcnt = 0;
112-
113-
skb->ip_summed = CHECKSUM_UNNECESSARY;
114-
115-
/* perform proper loopback on capable devices */
116-
if (dev->flags & IFF_ECHO)
117-
skb->pkt_type = PACKET_LOOPBACK;
118-
else
119-
skb->pkt_type = PACKET_HOST;
120-
121-
skb_reset_mac_header(skb);
122-
skb_reset_network_header(skb);
123-
skb_reset_transport_header(skb);
124-
}
125-
126-
return true;
127-
}
128-
129-
/* Drop a given socketbuffer if it does not contain a valid CAN frame. */
130-
static inline bool can_dropped_invalid_skb(struct net_device *dev,
131-
struct sk_buff *skb)
132-
{
133-
const struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
134-
135-
if (skb->protocol == htons(ETH_P_CAN)) {
136-
if (unlikely(skb->len != CAN_MTU ||
137-
cfd->len > CAN_MAX_DLEN))
138-
goto inval_skb;
139-
} else if (skb->protocol == htons(ETH_P_CANFD)) {
140-
if (unlikely(skb->len != CANFD_MTU ||
141-
cfd->len > CANFD_MAX_DLEN))
142-
goto inval_skb;
143-
} else
144-
goto inval_skb;
145-
146-
if (!can_skb_headroom_valid(dev, skb))
147-
goto inval_skb;
148-
149-
return false;
150-
151-
inval_skb:
152-
kfree_skb(skb);
153-
dev->stats.tx_dropped++;
154-
return true;
155-
}
156-
157100
static inline bool can_is_canfd_skb(const struct sk_buff *skb)
158101
{
159102
/* the CAN specific type of skb is identified by its data length */

0 commit comments

Comments
 (0)