c205779
From 1717b6b8b1de95ed4ca53b74d2ccb563fae9b898 Mon Sep 17 00:00:00 2001
c205779
From: Josh Boyer <jwboyer@redhat.com>
c205779
Date: Tue, 2 Aug 2011 08:09:56 -0400
c205779
Subject: [PATCH] usbnet/cdc_ncm: Don't use stack variables for DMA buffers
c205779
c205779
The cdc_ncm driver still has a few places where stack variables are passed
c205779
to the cdc_ncm_do_request function.  This triggers a stack trace in
c205779
lib/dma-debug.c if the CONFIG_DEBUG_DMA_API option is set.
c205779
c205779
Adjust these calls to pass parameters that have been allocated with kzalloc.
c205779
c205779
Signed-off-by: Josh Boyer <jwboyer@redhat.com>
c205779
---
c205779
 drivers/net/usb/cdc_ncm.c |   54 +++++++++++++++++++++++++++++++++++----------
c205779
 1 files changed, 42 insertions(+), 12 deletions(-)
c205779
c205779
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
c205779
index fd622a6..bbcb133 100644
c205779
--- a/drivers/net/usb/cdc_ncm.c
c205779
+++ b/drivers/net/usb/cdc_ncm.c
c205779
@@ -260,23 +260,39 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
c205779
 		req.wIndex = cpu_to_le16(iface_no);
c205779
 
c205779
 		if (flags & USB_CDC_NCM_NCAP_NTB_INPUT_SIZE) {
c205779
-			struct usb_cdc_ncm_ndp_input_size ndp_in_sz;
c205779
+			struct usb_cdc_ncm_ndp_input_size *ndp_in_sz;
c205779
+
c205779
+			ndp_in_sz = kzalloc(sizeof(*ndp_in_sz), GFP_KERNEL);
c205779
+			if (!ndp_in_sz) {
c205779
+				err = -ENOMEM;
c205779
+				goto size_err;
c205779
+			}
c205779
 
c205779
 			req.wLength = 8;
c205779
-			ndp_in_sz.dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
c205779
-			ndp_in_sz.wNtbInMaxDatagrams =
c205779
+			ndp_in_sz->dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
c205779
+			ndp_in_sz->wNtbInMaxDatagrams =
c205779
 					cpu_to_le16(CDC_NCM_DPT_DATAGRAMS_MAX);
c205779
-			ndp_in_sz.wReserved = 0;
c205779
-			err = cdc_ncm_do_request(ctx, &req, &ndp_in_sz, 0, NULL,
c205779
+			ndp_in_sz->wReserved = 0;
c205779
+			err = cdc_ncm_do_request(ctx, &req, ndp_in_sz, 0, NULL,
c205779
 									1000);
c205779
+			kfree(ndp_in_sz);
c205779
 		} else {
c205779
-			__le32 dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
c205779
+			__le32 *dwNtbInMaxSize;
c205779
+			dwNtbInMaxSize = kzalloc(sizeof(*dwNtbInMaxSize),
c205779
+					GFP_KERNEL);
c205779
+			if (!dwNtbInMaxSize) {
c205779
+				err = -ENOMEM;
c205779
+				goto size_err;
c205779
+			}
c205779
+			*dwNtbInMaxSize = cpu_to_le32(ctx->rx_max);
c205779
 
c205779
 			req.wLength = 4;
c205779
-			err = cdc_ncm_do_request(ctx, &req, &dwNtbInMaxSize, 0,
c205779
+			err = cdc_ncm_do_request(ctx, &req, dwNtbInMaxSize, 0,
c205779
 								NULL, 1000);
c205779
+			kfree(dwNtbInMaxSize);
c205779
 		}
c205779
 
c205779
+size_err:
c205779
 		if (err)
c205779
 			pr_debug("Setting NTB Input Size failed\n");
c205779
 	}
c205779
@@ -362,9 +378,16 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
c205779
 
c205779
 	/* set Max Datagram Size (MTU) */
c205779
 	if (flags & USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE) {
c205779
-		__le16 max_datagram_size;
c205779
+		__le16 *max_datagram_size;
c205779
 		u16 eth_max_sz = le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
c205779
 
c205779
+		max_datagram_size = kzalloc(sizeof(*max_datagram_size),
c205779
+				GFP_KERNEL);
c205779
+		if (!max_datagram_size) {
c205779
+			err = -ENOMEM;
c205779
+			goto max_dgram_err;
c205779
+		}
c205779
+
c205779
 		req.bmRequestType = USB_TYPE_CLASS | USB_DIR_IN |
c205779
 							USB_RECIP_INTERFACE;
c205779
 		req.bNotificationType = USB_CDC_GET_MAX_DATAGRAM_SIZE;
c205779
@@ -372,13 +395,17 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
c205779
 		req.wIndex = cpu_to_le16(iface_no);
c205779
 		req.wLength = cpu_to_le16(2);
c205779
 
c205779
-		err = cdc_ncm_do_request(ctx, &req, &max_datagram_size, 0, NULL,
c205779
+		err = cdc_ncm_do_request(ctx, &req, max_datagram_size, 0, NULL,
c205779
 									1000);
c205779
+
c205779
 		if (err) {
c205779
 			pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
c205779
 						CDC_NCM_MIN_DATAGRAM_SIZE);
c205779
+			kfree(max_datagram_size);
c205779
 		} else {
c205779
-			ctx->max_datagram_size = le16_to_cpu(max_datagram_size);
c205779
+			ctx->max_datagram_size =
c205779
+				le16_to_cpu(*max_datagram_size);
c205779
+
c205779
 			/* Check Eth descriptor value */
c205779
 			if (eth_max_sz < CDC_NCM_MAX_DATAGRAM_SIZE) {
c205779
 				if (ctx->max_datagram_size > eth_max_sz)
c205779
@@ -401,10 +428,13 @@ static u8 cdc_ncm_setup(struct cdc_ncm_ctx *ctx)
c205779
 			req.wValue = 0;
c205779
 			req.wIndex = cpu_to_le16(iface_no);
c205779
 			req.wLength = 2;
c205779
-			max_datagram_size = cpu_to_le16(ctx->max_datagram_size);
c205779
+			*max_datagram_size =
c205779
+				cpu_to_le16(ctx->max_datagram_size);
c205779
 
c205779
-			err = cdc_ncm_do_request(ctx, &req, &max_datagram_size,
c205779
+			err = cdc_ncm_do_request(ctx, &req, max_datagram_size,
c205779
 								0, NULL, 1000);
c205779
+			kfree(max_datagram_size);
c205779
+max_dgram_err:
c205779
 			if (err)
c205779
 				pr_debug("SET_MAX_DATAGRAM_SIZE failed\n");
c205779
 		}
c205779
-- 
c205779
1.7.6
c205779