Skip to contentSkip to conversation

staging: vt6656: use off stack for out buffer USB transfers.

PATCH In review Malcolm Priestley 2 participants 3 messages Apr 22, 2017 – Apr 28, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 staging: vt6656: use off stack for out buffer USB transfers.

Since 4.9 mandated USB buffers be heap allocated this causes the driver to fail.

Since there is a wide range of buffer sizes use kmemdup to create allocated buffer.

---
 drivers/staging/vt6656/usbpipe.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/staging/vt6656/usbpipe.c +12 -2
index 9ad8503d2589..ea5a7c65ad1b 100644
@@ -47,15 +47,25 @@ int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
 		     u16 index, u16 length, u8 *buffer)
 {
 	int status = 0;
+	u8 *usb_buffer;
 
 	if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
 		return STATUS_FAILURE;
 
 	mutex_lock(&priv->usb_lock);
 
+	usb_buffer = kmemdup(buffer, length, GFP_KERNEL);
+	if (!usb_buffer) {
+		mutex_unlock(&priv->usb_lock);
+		return -ENOMEM;
+	}
+
 	status = usb_control_msg(priv->usb,
-		usb_sndctrlpipe(priv->usb, 0), request, 0x40, value,
-			index, buffer, length, USB_CTL_WAIT);
+				 usb_sndctrlpipe(priv->usb, 0),
+				 request, 0x40, value,
+				 index, usb_buffer, length, USB_CTL_WAIT);
+
+	kfree(usb_buffer);
 
 	mutex_unlock(&priv->usb_lock);
 
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/2 staging: vt6656: use off stack for in buffer USB transfers.

Since 4.9 mandated USB buffers to be heap allocated. This causes the driver to fail.

Create buffer for USB transfers.

---
 drivers/staging/vt6656/usbpipe.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/staging/vt6656/usbpipe.c +15 -2
index ea5a7c65ad1b..dc11a05be8c4 100644
@@ -85,15 +85,28 @@ int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
 		    u16 index, u16 length, u8 *buffer)
 {
 	int status;
+	u8 *usb_buffer;
 
 	if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
 		return STATUS_FAILURE;
 
 	mutex_lock(&priv->usb_lock);
 
+	usb_buffer = kmalloc(length, GFP_KERNEL);
+	if (!usb_buffer) {
+		mutex_unlock(&priv->usb_lock);
+		return -ENOMEM;
+	}
+
 	status = usb_control_msg(priv->usb,
-				usb_rcvctrlpipe(priv->usb, 0), request, 0xc0,
-				value, index, buffer, length, USB_CTL_WAIT);
+				 usb_rcvctrlpipe(priv->usb, 0),
+				 request, 0xc0, value,
+				 index, usb_buffer, length, USB_CTL_WAIT);
+
+	if (status == length)
+		memcpy(buffer, usb_buffer, length);
+
+	kfree(usb_buffer);
 
 	mutex_unlock(&priv->usb_lock);
 
Signature · 1 line
2.11.0
maintainer
#2 lore raw
In reply to Malcolm Priestley
Quoted 2 lines · Malcolm Priestley

Since 4.9 mandated USB buffers be heap allocated this causes the driver to fail.

It's really been a requirement since the 2.2 days, it's just that not many people ran USB drivers on the platforms that required it :)

thanks,

greg k-h