firewire: net: fix memory leaks

a) fwnet_transmit_packet_done used to poison ptask->pt_link by list_del.
If fwnet_send_packet checked later whether it was responsible to clean
up (in the border case that the TX soft IRQ was outpaced by the AT-req
tasklet on another CPU), it missed this because ptask->pt_link was no
longer shown as empty.

b) If fwnet_write_complete got an rcode other than RCODE_COMPLETE, we
missed to free the skb and ptask entirely.

Also, count stats.tx_dropped and stats.tx_errors when rcode != 0.

Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>

+31 -4
+31 -4
drivers/firewire/net.c
··· 916 916 917 917 /* Check whether we or the networking TX soft-IRQ is last user. */ 918 918 free = (ptask->outstanding_pkts == 0 && !list_empty(&ptask->pt_link)); 919 + if (free) 920 + list_del(&ptask->pt_link); 919 921 920 922 if (ptask->outstanding_pkts == 0) { 921 - list_del(&ptask->pt_link); 922 923 dev->netdev->stats.tx_packets++; 923 924 dev->netdev->stats.tx_bytes += skb->len; 924 925 } ··· 974 973 fwnet_free_ptask(ptask); 975 974 } 976 975 976 + static void fwnet_transmit_packet_failed(struct fwnet_packet_task *ptask) 977 + { 978 + struct fwnet_device *dev = ptask->dev; 979 + unsigned long flags; 980 + bool free; 981 + 982 + spin_lock_irqsave(&dev->lock, flags); 983 + 984 + /* One fragment failed; don't try to send remaining fragments. */ 985 + ptask->outstanding_pkts = 0; 986 + 987 + /* Check whether we or the networking TX soft-IRQ is last user. */ 988 + free = !list_empty(&ptask->pt_link); 989 + if (free) 990 + list_del(&ptask->pt_link); 991 + 992 + dev->netdev->stats.tx_dropped++; 993 + dev->netdev->stats.tx_errors++; 994 + 995 + spin_unlock_irqrestore(&dev->lock, flags); 996 + 997 + if (free) 998 + fwnet_free_ptask(ptask); 999 + } 1000 + 977 1001 static void fwnet_write_complete(struct fw_card *card, int rcode, 978 1002 void *payload, size_t length, void *data) 979 1003 { ··· 1006 980 1007 981 ptask = data; 1008 982 1009 - if (rcode == RCODE_COMPLETE) 983 + if (rcode == RCODE_COMPLETE) { 1010 984 fwnet_transmit_packet_done(ptask); 1011 - else 985 + } else { 1012 986 fw_error("fwnet_write_complete: failed: %x\n", rcode); 1013 - /* ??? error recovery */ 987 + fwnet_transmit_packet_failed(ptask); 988 + } 1014 989 } 1015 990 1016 991 static int fwnet_send_packet(struct fwnet_packet_task *ptask)