Skip to content

Commit f5083d0

Browse files
Xie Hedavem330
authored andcommitted
drivers/net/wan/hdlc_fr: Improvements to the code of pvc_xmit
1. Keep the code for the normal (non-error) flow at the lowest indentation level. And use "goto drop" for all error handling. 2. Replace code that pads short Ethernet frames with a "__skb_pad" call. 3. Change "dev_kfree_skb" to "kfree_skb" in error handling code. "kfree_skb" is the correct function to call when dropping an skb due to an error. "dev_kfree_skb", which is an alias of "consume_skb", is for dropping skbs normally (not due to an error). Cc: Krzysztof Halasa <[email protected]> Cc: Stephen Hemminger <[email protected]> Signed-off-by: Xie He <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3e233ca commit f5083d0

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

drivers/net/wan/hdlc_fr.c

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -416,38 +416,36 @@ static netdev_tx_t pvc_xmit(struct sk_buff *skb, struct net_device *dev)
416416
{
417417
struct pvc_device *pvc = dev->ml_priv;
418418

419-
if (pvc->state.active) {
420-
if (dev->type == ARPHRD_ETHER) {
421-
int pad = ETH_ZLEN - skb->len;
422-
if (pad > 0) { /* Pad the frame with zeros */
423-
int len = skb->len;
424-
if (skb_tailroom(skb) < pad)
425-
if (pskb_expand_head(skb, 0, pad,
426-
GFP_ATOMIC)) {
427-
dev->stats.tx_dropped++;
428-
dev_kfree_skb(skb);
429-
return NETDEV_TX_OK;
430-
}
431-
skb_put(skb, pad);
432-
memset(skb->data + len, 0, pad);
433-
}
434-
}
435-
skb->dev = dev;
436-
if (!fr_hard_header(&skb, pvc->dlci)) {
437-
dev->stats.tx_bytes += skb->len;
438-
dev->stats.tx_packets++;
439-
if (pvc->state.fecn) /* TX Congestion counter */
440-
dev->stats.tx_compressed++;
441-
skb->dev = pvc->frad;
442-
skb->protocol = htons(ETH_P_HDLC);
443-
skb_reset_network_header(skb);
444-
dev_queue_xmit(skb);
445-
return NETDEV_TX_OK;
419+
if (!pvc->state.active)
420+
goto drop;
421+
422+
if (dev->type == ARPHRD_ETHER) {
423+
int pad = ETH_ZLEN - skb->len;
424+
425+
if (pad > 0) { /* Pad the frame with zeros */
426+
if (__skb_pad(skb, pad, false))
427+
goto drop;
428+
skb_put(skb, pad);
446429
}
447430
}
448431

432+
skb->dev = dev;
433+
if (fr_hard_header(&skb, pvc->dlci))
434+
goto drop;
435+
436+
dev->stats.tx_bytes += skb->len;
437+
dev->stats.tx_packets++;
438+
if (pvc->state.fecn) /* TX Congestion counter */
439+
dev->stats.tx_compressed++;
440+
skb->dev = pvc->frad;
441+
skb->protocol = htons(ETH_P_HDLC);
442+
skb_reset_network_header(skb);
443+
dev_queue_xmit(skb);
444+
return NETDEV_TX_OK;
445+
446+
drop:
449447
dev->stats.tx_dropped++;
450-
dev_kfree_skb(skb);
448+
kfree_skb(skb);
451449
return NETDEV_TX_OK;
452450
}
453451

0 commit comments

Comments
 (0)