]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
net: cdc_ncm: Fix TX zero padding
authorJim Baxter <jim_baxter@mentor.com>
Mon, 8 May 2017 12:49:57 +0000 (13:49 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 May 2017 20:01:10 +0000 (16:01 -0400)
The zero padding that is added to NTB's does
not zero the memory correctly.
This is because the skb_put modifies the value
of skb_out->len which results in the memset
command not setting any memory to zero as
(ctx->tx_max - skb_out->len) == 0.

I have resolved this by storing the size of
the memory to be zeroed before the skb_put
and using this in the memset call.

Signed-off-by: Jim Baxter <jim_baxter@mentor.com>
Reviewed-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/usb/cdc_ncm.c

index bb3f71f9fbde06ef1a8d514dbb856c8aa7ff5130..b5cec1824a7875842abaead1a888494e282f1741 100644 (file)
@@ -1088,6 +1088,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
        u16 n = 0, index, ndplen;
        u8 ready2send = 0;
        u32 delayed_ndp_size;
+       size_t padding_count;
 
        /* When our NDP gets written in cdc_ncm_ndp(), then skb_out->len gets updated
         * accordingly. Otherwise, we should check here.
@@ -1244,11 +1245,13 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
         * a ZLP after full sized NTBs.
         */
        if (!(dev->driver_info->flags & FLAG_SEND_ZLP) &&
-           skb_out->len > ctx->min_tx_pkt)
-               memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
-                      ctx->tx_max - skb_out->len);
-       else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
+           skb_out->len > ctx->min_tx_pkt) {
+               padding_count = ctx->tx_max - skb_out->len;
+               memset(skb_put(skb_out, padding_count), 0, padding_count);
+       } else if (skb_out->len < ctx->tx_max &&
+                  (skb_out->len % dev->maxpacket) == 0) {
                *skb_put(skb_out, 1) = 0;       /* force short packet */
+       }
 
        /* set final frame length */
        nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data;