Skip to contentSkip to conversation

net/usb: hso: allocate URB setup_packets as separate buffers

PATCH In review Jussi Kivilinna 3 participants 4 messages Aug 7, 2013 1 message not in the archive

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

PATCH 1/2 net/usb: hso: allocate URB setup_packets as separate buffers

URB setup packets must not be allocated as part of larger structure because DMA coherence issues.

Patch changes hso to allocate ctrl_req_[tr]x members of 'struct hso_serial' as separate buffers.

Patch is only compile tested.

---
 drivers/net/usb/hso.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/net/usb/hso.c +14 -4
index cba1d46..fc082c0 100644
@@ -237,8 +237,8 @@ struct hso_serial {
 	u16 tx_data_length;	/* should contain allocated length */
 	u16 tx_data_count;
 	u16 tx_buffer_count;
-	struct usb_ctrlrequest ctrl_req_tx;
-	struct usb_ctrlrequest ctrl_req_rx;
+	struct usb_ctrlrequest *ctrl_req_tx;
+	struct usb_ctrlrequest *ctrl_req_rx;
 
 	struct usb_endpoint_descriptor *in_endp;
 	struct usb_endpoint_descriptor *out_endp;
@@ -1847,7 +1847,7 @@ static int hso_mux_serial_read(struct hso_serial *serial)
 				  USB_CDC_GET_ENCAPSULATED_RESPONSE,
 				  serial->parent->port_spec & HSO_PORT_MASK,
 				  serial->rx_urb[0],
-				  &serial->ctrl_req_rx,
+				  serial->ctrl_req_rx,
 				  serial->rx_data[0], serial->rx_data_length);
 }
 
@@ -1916,7 +1916,7 @@ static int hso_mux_serial_write_data(struct hso_serial *serial)
 				  USB_CDC_SEND_ENCAPSULATED_COMMAND,
 				  serial->parent->port_spec & HSO_PORT_MASK,
 				  serial->tx_urb,
-				  &serial->ctrl_req_tx,
+				  serial->ctrl_req_tx,
 				  serial->tx_data, serial->tx_data_count);
 }
 
@@ -2264,6 +2264,10 @@ static void hso_serial_common_free(struct hso_serial *serial)
 	usb_free_urb(serial->tx_urb);
 	kfree(serial->tx_data);
 	tty_port_destroy(&serial->port);
+
+	/* free control URB setup packet buffers */
+	kfree(serial->ctrl_req_tx);
+	kfree(serial->ctrl_req_rx);
 }
 
 static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
@@ -2292,6 +2296,12 @@ static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
 	spin_lock_init(&serial->serial_lock);
 	serial->num_rx_urbs = num_urbs;
 
+	/* allocate control URB setup packet buffers */
+	serial->ctrl_req_tx = kzalloc(sizeof(*serial->ctrl_req_tx), GFP_KERNEL);
+	serial->ctrl_req_rx = kzalloc(sizeof(*serial->ctrl_req_rx), GFP_KERNEL);
+	if (!serial->ctrl_req_tx || !serial->ctrl_req_rx)
+		goto exit;
+
 	/* RX, allocate urb and initialize */
 
 	/* prepare our RX buffer */

A message that is not in the archive (sent off-list or not yet received): 20130807132902.14451.37517.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org

#2 lore raw

PATCH 2/2 net/usb: hso: allocate serial_state_notification as separate buffer

URB transfer_buffers must not be allocated as part of larger structure because DMA coherence issues.

Patch changes hso to allocate serial_state_notification member of 'struct hso_tiocmget' as separate buffer.

Patch is only compile tested.

---
 drivers/net/usb/hso.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/net/usb/hso.c +14 -4
index fc082c0..21ffa6f 100644
@@ -211,7 +211,7 @@ struct hso_tiocmget {
 	int    intr_completed;
 	struct usb_endpoint_descriptor *endp;
 	struct urb *urb;
-	struct hso_serial_state_notification serial_state_notification;
+	struct hso_serial_state_notification *serial_state_notification;
 	u16    prev_UART_state_bitmap;
 	struct uart_icount icount;
 };
@@ -1465,7 +1465,7 @@ static int tiocmget_submit_urb(struct hso_serial *serial,
 			 usb_rcvintpipe(usb,
 					tiocmget->endp->
 					bEndpointAddress & 0x7F),
-			 &tiocmget->serial_state_notification,
+			 tiocmget->serial_state_notification,
 			 sizeof(struct hso_serial_state_notification),
 			 tiocmget_intr_callback, serial,
 			 tiocmget->endp->bInterval);
@@ -1499,7 +1499,7 @@ static void tiocmget_intr_callback(struct urb *urb)
 	if (!tiocmget)
 		return;
 	usb = serial->parent->usb;
-	serial_state_notification = &tiocmget->serial_state_notification;
+	serial_state_notification = tiocmget->serial_state_notification;
 	if (serial_state_notification->bmRequestType != BM_REQUEST_TYPE ||
 	    serial_state_notification->bNotification != B_NOTIFICATION ||
 	    le16_to_cpu(serial_state_notification->wValue) != W_VALUE ||
@@ -2608,6 +2608,7 @@ static void hso_free_tiomget(struct hso_serial *serial)
 		usb_free_urb(tiocmget->urb);
 		tiocmget->urb = NULL;
 		serial->tiocmget = NULL;
+		kfree(tiocmget->serial_state_notification);
 		kfree(tiocmget);
 	}
 }
@@ -2664,6 +2665,13 @@ static struct hso_device *hso_create_bulk_serial_device(
 		 */
 		if (serial->tiocmget) {
 			tiocmget = serial->tiocmget;
+
+			tiocmget->serial_state_notification = kzalloc(
+				sizeof(struct hso_serial_state_notification),
+				GFP_KERNEL);
+			if (!tiocmget->serial_state_notification)
+				goto tiocmget_fail;
+
 			tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL);
 			if (tiocmget->urb) {
 				mutex_init(&tiocmget->mutex);
@@ -2672,8 +2680,10 @@ static struct hso_device *hso_create_bulk_serial_device(
 					interface,
 					USB_ENDPOINT_XFER_INT,
 					USB_DIR_IN);
-			} else
+			} else {
+tiocmget_fail:
 				hso_free_tiomget(serial);
+			}
 		}
 	}
 	else

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Tested-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] net/usb: hso: allocate serial_state_notification as separate buffer

Quoted 7 lines · Jussi Kivilinna

URB transfer_buffers must not be allocated as part of larger structure because DMA coherence issues.

Patch changes hso to allocate serial_state_notification member of 'struct hso_tiocmget' as separate buffer.

Patch is only compile tested.

Quoted 76 lines
---
 drivers/net/usb/hso.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/net/usb/hso.c +14 -5
index fc082c0..21ffa6f 100644
@@ -211,7 +211,7 @@ struct hso_tiocmget {
 	int    intr_completed;
 	struct usb_endpoint_descriptor *endp;
 	struct urb *urb;
-	struct hso_serial_state_notification serial_state_notification;
+	struct hso_serial_state_notification *serial_state_notification;
 	u16    prev_UART_state_bitmap;
 	struct uart_icount icount;
 };
@@ -1465,7 +1465,7 @@ static int tiocmget_submit_urb(struct hso_serial *serial,
 			 usb_rcvintpipe(usb,
 					tiocmget->endp->
 					bEndpointAddress & 0x7F),
-			 &tiocmget->serial_state_notification,
+			 tiocmget->serial_state_notification,
 			 sizeof(struct hso_serial_state_notification),
 			 tiocmget_intr_callback, serial,
 			 tiocmget->endp->bInterval);
@@ -1499,7 +1499,7 @@ static void tiocmget_intr_callback(struct urb *urb)
 	if (!tiocmget)
 		return;
 	usb = serial->parent->usb;
-	serial_state_notification = &tiocmget->serial_state_notification;
+	serial_state_notification = tiocmget->serial_state_notification;
 	if (serial_state_notification->bmRequestType != BM_REQUEST_TYPE ||
 	    serial_state_notification->bNotification != B_NOTIFICATION ||
 	    le16_to_cpu(serial_state_notification->wValue) != W_VALUE ||
@@ -2608,6 +2608,7 @@ static void hso_free_tiomget(struct hso_serial *serial)
 		usb_free_urb(tiocmget->urb);
 		tiocmget->urb = NULL;
 		serial->tiocmget = NULL;
+		kfree(tiocmget->serial_state_notification);
 		kfree(tiocmget);
 	}
 }
@@ -2664,6 +2665,13 @@ static struct hso_device *hso_create_bulk_serial_device(
 		 */
 		if (serial->tiocmget) {
 			tiocmget = serial->tiocmget;
+
+			tiocmget->serial_state_notification = kzalloc(
+				sizeof(struct hso_serial_state_notification),
+				GFP_KERNEL);
+			if (!tiocmget->serial_state_notification)
+				goto tiocmget_fail;
+
 			tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL);
 			if (tiocmget->urb) {
 				mutex_init(&tiocmget->mutex);
@@ -2672,8 +2680,10 @@ static struct hso_device *hso_create_bulk_serial_device(
 					interface,
 					USB_ENDPOINT_XFER_INT,
 					USB_DIR_IN);
-			} else
+			} else {
+tiocmget_fail:
 				hso_free_tiomget(serial);
+			}
 		}
 	}
 	else
 
--

To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Tested-by on v1 1/2
#4 lore raw
In reply to Jussi Kivilinna
Quoted 7 lines · Jussi Kivilinna

URB setup packets must not be allocated as part of larger structure because DMA coherence issues.

Patch changes hso to allocate ctrl_req_[tr]x members of 'struct hso_serial' as separate buffers.

Patch is only compile tested.

Quoted 68 lines
---
 drivers/net/usb/hso.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/net/usb/hso.c +14 -5
index cba1d46..fc082c0 100644
@@ -237,8 +237,8 @@ struct hso_serial {
 	u16 tx_data_length;	/* should contain allocated length */
 	u16 tx_data_count;
 	u16 tx_buffer_count;
-	struct usb_ctrlrequest ctrl_req_tx;
-	struct usb_ctrlrequest ctrl_req_rx;
+	struct usb_ctrlrequest *ctrl_req_tx;
+	struct usb_ctrlrequest *ctrl_req_rx;
 
 	struct usb_endpoint_descriptor *in_endp;
 	struct usb_endpoint_descriptor *out_endp;
@@ -1847,7 +1847,7 @@ static int hso_mux_serial_read(struct hso_serial *serial)
 				  USB_CDC_GET_ENCAPSULATED_RESPONSE,
 				  serial->parent->port_spec & HSO_PORT_MASK,
 				  serial->rx_urb[0],
-				  &serial->ctrl_req_rx,
+				  serial->ctrl_req_rx,
 				  serial->rx_data[0], serial->rx_data_length);
 }
 
@@ -1916,7 +1916,7 @@ static int hso_mux_serial_write_data(struct hso_serial *serial)
 				  USB_CDC_SEND_ENCAPSULATED_COMMAND,
 				  serial->parent->port_spec & HSO_PORT_MASK,
 				  serial->tx_urb,
-				  &serial->ctrl_req_tx,
+				  serial->ctrl_req_tx,
 				  serial->tx_data, serial->tx_data_count);
 }
 
@@ -2264,6 +2264,10 @@ static void hso_serial_common_free(struct hso_serial *serial)
 	usb_free_urb(serial->tx_urb);
 	kfree(serial->tx_data);
 	tty_port_destroy(&serial->port);
+
+	/* free control URB setup packet buffers */
+	kfree(serial->ctrl_req_tx);
+	kfree(serial->ctrl_req_rx);
 }
 
 static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
@@ -2292,6 +2296,12 @@ static int hso_serial_common_create(struct hso_serial *serial, int num_urbs,
 	spin_lock_init(&serial->serial_lock);
 	serial->num_rx_urbs = num_urbs;
 
+	/* allocate control URB setup packet buffers */
+	serial->ctrl_req_tx = kzalloc(sizeof(*serial->ctrl_req_tx), GFP_KERNEL);
+	serial->ctrl_req_rx = kzalloc(sizeof(*serial->ctrl_req_rx), GFP_KERNEL);
+	if (!serial->ctrl_req_tx || !serial->ctrl_req_rx)
+		goto exit;
+
 	/* RX, allocate urb and initialize */
 
 	/* prepare our RX buffer */
 
--

To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html