Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/20220610143009.323579-7-mailhol.vincent@wanadoo.fr
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Reported-by: kernel test robot <lkp@intel.com>
Acked-by: Max Staudt <max@enpas.org>
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Vincent Mailhol and committed by
Marc Kleine-Budde
ccd8a935 d7786af5

+59 -58
+58
drivers/net/can/dev/skb.c
··· 259 259 return skb; 260 260 } 261 261 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);
+1 -58
include/linux/can/skb.h
··· 31 31 struct canfd_frame **cfd); 32 32 struct sk_buff *alloc_can_err_skb(struct net_device *dev, 33 33 struct can_frame **cf); 34 + bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb); 34 35 35 36 /* 36 37 * The struct can_skb_priv is used to transport additional information along ··· 95 94 can_skb_set_owner(nskb, skb->sk); 96 95 consume_skb(skb); 97 96 return nskb; 98 - } 99 - 100 - /* Check for outgoing skbs that have not been created by the CAN subsystem */ 101 - static inline bool can_skb_headroom_valid(struct net_device *dev, 102 - struct sk_buff *skb) 103 - { 104 - /* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */ 105 - if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv))) 106 - return false; 107 - 108 - /* af_packet does not apply CAN skb specific settings */ 109 - if (skb->ip_summed == CHECKSUM_NONE) { 110 - /* init headroom */ 111 - can_skb_prv(skb)->ifindex = dev->ifindex; 112 - can_skb_prv(skb)->skbcnt = 0; 113 - 114 - skb->ip_summed = CHECKSUM_UNNECESSARY; 115 - 116 - /* perform proper loopback on capable devices */ 117 - if (dev->flags & IFF_ECHO) 118 - skb->pkt_type = PACKET_LOOPBACK; 119 - else 120 - skb->pkt_type = PACKET_HOST; 121 - 122 - skb_reset_mac_header(skb); 123 - skb_reset_network_header(skb); 124 - skb_reset_transport_header(skb); 125 - } 126 - 127 - return true; 128 - } 129 - 130 - /* Drop a given socketbuffer if it does not contain a valid CAN frame. */ 131 - static inline bool can_dropped_invalid_skb(struct net_device *dev, 132 - struct sk_buff *skb) 133 - { 134 - const struct canfd_frame *cfd = (struct canfd_frame *)skb->data; 135 - 136 - if (skb->protocol == htons(ETH_P_CAN)) { 137 - if (unlikely(skb->len != CAN_MTU || 138 - cfd->len > CAN_MAX_DLEN)) 139 - goto inval_skb; 140 - } else if (skb->protocol == htons(ETH_P_CANFD)) { 141 - if (unlikely(skb->len != CANFD_MTU || 142 - cfd->len > CANFD_MAX_DLEN)) 143 - goto inval_skb; 144 - } else 145 - goto inval_skb; 146 - 147 - if (!can_skb_headroom_valid(dev, skb)) 148 - goto inval_skb; 149 - 150 - return false; 151 - 152 - inval_skb: 153 - kfree_skb(skb); 154 - dev->stats.tx_dropped++; 155 - return true; 156 97 } 157 98 158 99 static inline bool can_is_canfd_skb(const struct sk_buff *skb)