[PATCH master 19/23] usb: hub: use DMA-capable memory in usb_hub_configure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



usb_hub_configure does a lot of control transfers to `buffer', a
stack-allocated variable. Switch it to a suitably aligned buffer
allocated with dma_alloc() instead.

The cleanup on error intentionally doesn't touch `hub'. Errors should
probably invalidate this, but that's out-of-scope for this DMA fix.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 drivers/usb/core/hub.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 9776fd72a5a4..bef428f7fbd3 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -443,12 +443,16 @@ static int usb_device_list_scan(void)
 
 static int usb_hub_configure(struct usb_device *dev)
 {
-	unsigned char buffer[USB_BUFSIZ], *bitmap;
+	unsigned char *buffer, *bitmap;
 	struct usb_hub_descriptor *descriptor;
 	struct usb_hub_status *hubsts;
 	int i, ret;
 	struct usb_hub_device *hub;
 
+	buffer = dma_alloc(USB_BUFSIZ);
+	if (!buffer)
+		return -ENOMEM;
+
 	hub = xzalloc(sizeof (*hub));
 	dev->hub = hub;
 
@@ -457,7 +461,8 @@ static int usb_hub_configure(struct usb_device *dev)
 	if (usb_get_hub_descriptor(dev, buffer, 4) < 0) {
 		dev_dbg(&dev->dev, "%s: failed to get hub " \
 				   "descriptor, giving up %lX\n", __func__, dev->status);
-		return -1;
+		ret = -1;
+		goto out;
 	}
 	descriptor = (struct usb_hub_descriptor *)buffer;
 
@@ -467,13 +472,15 @@ static int usb_hub_configure(struct usb_device *dev)
 		dev_dbg(&dev->dev, "%s: failed to get hub " \
 				"descriptor - too long: %d\n", __func__,
 				descriptor->bLength);
-		return -1;
+		ret = -1;
+		goto out;
 	}
 
 	if (usb_get_hub_descriptor(dev, buffer, descriptor->bLength) < 0) {
 		dev_dbg(&dev->dev, "%s: failed to get hub " \
 				"descriptor 2nd giving up %lX\n", __func__, dev->status);
-		return -1;
+		ret = -1;
+		goto out;
 	}
 	memcpy((unsigned char *)&hub->desc, buffer, descriptor->bLength);
 	/* adjust 16bit values */
@@ -589,13 +596,15 @@ static int usb_hub_configure(struct usb_device *dev)
 	if (sizeof(struct usb_hub_status) > USB_BUFSIZ) {
 		dev_dbg(&dev->dev, "%s: failed to get Status - " \
 				"too long: %d\n", __func__, descriptor->bLength);
-		return -1;
+		ret = -1;
+		goto out;
 	}
 
 	if (usb_get_hub_status(dev, buffer) < 0) {
 		dev_dbg(&dev->dev, "%s: failed to get Status %lX\n", __func__,
 				dev->status);
-		return -1;
+		ret = -1;
+		goto out;
 	}
 
 	hubsts = (struct usb_hub_status *)buffer;
@@ -610,16 +619,12 @@ static int usb_hub_configure(struct usb_device *dev)
 		"" : "no ");
 
 	if (dev->host->update_hub_device) {
-		int ret;
-
 		ret = dev->host->update_hub_device(dev);
 		if (ret)
-			return ret;
+			goto out;
 	}
 
 	if (!usb_hub_is_root_hub(dev) && usb_hub_is_superspeed(dev)) {
-		int ret;
-
 		/*
 		* This request sets the value that the hub uses to
 		* determine the index into the 'route string index'
@@ -629,13 +634,16 @@ static int usb_hub_configure(struct usb_device *dev)
 		if (ret < 0) {
 			dev_dbg(&dev->dev, "failed to set hub depth (0x%08lx)\n",
 				dev->status);
-			return ret;
+			goto out;
 		}
 	}
 
 	usb_hub_power_on(hub);
 
-	return 0;
+	ret = 0;
+out:
+	dma_free(buffer);
+	return ret;
 }
 
 static int usb_hub_configure_ports(struct usb_device *dev)
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux