netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] net/usb: catc: allocate URB setup_packet as separate buffer
@ 2013-08-07 13:26 Jussi Kivilinna
  2013-08-07 13:26 ` [PATCH 2/2] net/usb: catc: allocate URB transfer_buffers as separate buffers Jussi Kivilinna
       [not found] ` <20130807132629.14001.2370.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Jussi Kivilinna @ 2013-08-07 13:26 UTC (permalink / raw)
  To: netdev-u79uwXL29TY76Z2rM5mHXA
  Cc: Greg Kroah-Hartman, linux-usb-u79uwXL29TY76Z2rM5mHXA,
	David S. Miller

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

Patch changes catc to allocate ctrl_dr member as separate buffer.

Patch is only compile tested.

Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna-X3B1VOXEql0@public.gmane.org>
---
 drivers/net/usb/catc.c |   40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/drivers/net/usb/catc.c b/drivers/net/usb/catc.c
index 8d5cac2..a7d3c1b 100644
--- a/drivers/net/usb/catc.c
+++ b/drivers/net/usb/catc.c
@@ -173,7 +173,7 @@ struct catc {
 	u8 rx_buf[RX_MAX_BURST * (PKT_SZ + 2)];
 	u8 irq_buf[2];
 	u8 ctrl_buf[64];
-	struct usb_ctrlrequest ctrl_dr;
+	struct usb_ctrlrequest *ctrl_dr;
 
 	struct timer_list timer;
 	u8 stats_buf[8];
@@ -485,7 +485,7 @@ static void catc_ctrl_run(struct catc *catc)
 	struct ctrl_queue *q = catc->ctrl_queue + catc->ctrl_tail;
 	struct usb_device *usbdev = catc->usbdev;
 	struct urb *urb = catc->ctrl_urb;
-	struct usb_ctrlrequest *dr = &catc->ctrl_dr;
+	struct usb_ctrlrequest *dr = catc->ctrl_dr;
 	int status;
 
 	dr->bRequest = q->request;
@@ -779,7 +779,7 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
 	struct net_device *netdev;
 	struct catc *catc;
 	u8 broadcast[6];
-	int i, pktsz;
+	int i, pktsz, err;
 
 	if (usb_set_interface(usbdev,
 			intf->altsetting->desc.bInterfaceNumber, 1)) {
@@ -793,6 +793,12 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
 
 	catc = netdev_priv(netdev);
 
+	catc->ctrl_dr = kzalloc(sizeof(*catc->ctrl_dr), GFP_KERNEL);
+	if (!catc->ctrl_dr) {
+		err = -ENOMEM;
+		goto err_free_dev;
+	}
+
 	netdev->netdev_ops = &catc_netdev_ops;
 	netdev->watchdog_timeo = TX_TIMEOUT;
 	SET_ETHTOOL_OPS(netdev, &ops);
@@ -814,12 +820,8 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
 	if ((!catc->ctrl_urb) || (!catc->tx_urb) || 
 	    (!catc->rx_urb) || (!catc->irq_urb)) {
 		dev_err(&intf->dev, "No free urbs available.\n");
-		usb_free_urb(catc->ctrl_urb);
-		usb_free_urb(catc->tx_urb);
-		usb_free_urb(catc->rx_urb);
-		usb_free_urb(catc->irq_urb);
-		free_netdev(netdev);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto err_free;
 	}
 
 	/* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
@@ -918,14 +920,21 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
 	SET_NETDEV_DEV(netdev, &intf->dev);
 	if (register_netdev(netdev) != 0) {
 		usb_set_intfdata(intf, NULL);
-		usb_free_urb(catc->ctrl_urb);
-		usb_free_urb(catc->tx_urb);
-		usb_free_urb(catc->rx_urb);
-		usb_free_urb(catc->irq_urb);
-		free_netdev(netdev);
-		return -EIO;
+		err = -EIO;
+		goto err_free;
 	}
 	return 0;
+
+err_free:
+	usb_free_urb(catc->ctrl_urb);
+	usb_free_urb(catc->tx_urb);
+	usb_free_urb(catc->rx_urb);
+	usb_free_urb(catc->irq_urb);
+	kfree(catc->ctrl_dr);
+err_free_dev:
+	free_netdev(netdev);
+
+	return err;
 }
 
 static void catc_disconnect(struct usb_interface *intf)
@@ -939,6 +948,7 @@ static void catc_disconnect(struct usb_interface *intf)
 		usb_free_urb(catc->tx_urb);
 		usb_free_urb(catc->rx_urb);
 		usb_free_urb(catc->irq_urb);
+		kfree(catc->ctrl_dr);
 		free_netdev(catc->netdev);
 	}
 }

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] net/usb: catc: allocate URB transfer_buffers as separate buffers
  2013-08-07 13:26 [PATCH 1/2] net/usb: catc: allocate URB setup_packet as separate buffer Jussi Kivilinna
@ 2013-08-07 13:26 ` Jussi Kivilinna
       [not found] ` <20130807132629.14001.2370.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Jussi Kivilinna @ 2013-08-07 13:26 UTC (permalink / raw)
  To: netdev; +Cc: Greg Kroah-Hartman, linux-usb, David S. Miller

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

Patch changes catc to allocate tx_buf, rx_buf, irq_buf and ctrl_buf members
as separate buffers.

Patch is only compile tested.

Cc: <stable@vger.kernel.org>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
---
 drivers/net/usb/catc.c |   30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/drivers/net/usb/catc.c b/drivers/net/usb/catc.c
index a7d3c1b..26039d6 100644
--- a/drivers/net/usb/catc.c
+++ b/drivers/net/usb/catc.c
@@ -169,10 +169,10 @@ struct catc {
 	unsigned int ctrl_head, ctrl_tail;
 	spinlock_t tx_lock, ctrl_lock;
 
-	u8 tx_buf[2][TX_MAX_BURST * (PKT_SZ + 2)];
-	u8 rx_buf[RX_MAX_BURST * (PKT_SZ + 2)];
-	u8 irq_buf[2];
-	u8 ctrl_buf[64];
+	u8 *tx_buf[2];
+	u8 *rx_buf;
+	u8 *irq_buf;
+	u8 *ctrl_buf;
 	struct usb_ctrlrequest *ctrl_dr;
 
 	struct timer_list timer;
@@ -794,9 +794,15 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
 	catc = netdev_priv(netdev);
 
 	catc->ctrl_dr = kzalloc(sizeof(*catc->ctrl_dr), GFP_KERNEL);
-	if (!catc->ctrl_dr) {
+	catc->tx_buf[0] = kzalloc(TX_MAX_BURST * (PKT_SZ + 2), GFP_KERNEL);
+	catc->tx_buf[1] = kzalloc(TX_MAX_BURST * (PKT_SZ + 2), GFP_KERNEL);
+	catc->rx_buf = kzalloc(RX_MAX_BURST * (PKT_SZ + 2), GFP_KERNEL);
+	catc->irq_buf = kzalloc(2, GFP_KERNEL);
+	catc->ctrl_buf = kzalloc(64, GFP_KERNEL);
+	if (!catc->ctrl_dr || !catc->ctrl_buf || !catc->tx_buf[0] ||
+	    !catc->tx_buf[1] || !catc->rx_buf || !catc->irq_buf) {
 		err = -ENOMEM;
-		goto err_free_dev;
+		goto err_free_buf;
 	}
 
 	netdev->netdev_ops = &catc_netdev_ops;
@@ -930,8 +936,13 @@ err_free:
 	usb_free_urb(catc->tx_urb);
 	usb_free_urb(catc->rx_urb);
 	usb_free_urb(catc->irq_urb);
+err_free_buf:
+	kfree(catc->ctrl_buf);
+	kfree(catc->irq_buf);
+	kfree(catc->rx_buf);
+	kfree(catc->tx_buf[1]);
+	kfree(catc->tx_buf[0]);
 	kfree(catc->ctrl_dr);
-err_free_dev:
 	free_netdev(netdev);
 
 	return err;
@@ -948,6 +959,11 @@ static void catc_disconnect(struct usb_interface *intf)
 		usb_free_urb(catc->tx_urb);
 		usb_free_urb(catc->rx_urb);
 		usb_free_urb(catc->irq_urb);
+		kfree(catc->ctrl_buf);
+		kfree(catc->irq_buf);
+		kfree(catc->rx_buf);
+		kfree(catc->tx_buf[1]);
+		kfree(catc->tx_buf[0]);
 		kfree(catc->ctrl_dr);
 		free_netdev(catc->netdev);
 	}

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] net/usb: catc: allocate URB setup_packet as separate buffer
       [not found] ` <20130807132629.14001.2370.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
@ 2013-08-09 20:42   ` David Miller
  2013-08-10  7:31     ` Jussi Kivilinna
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2013-08-09 20:42 UTC (permalink / raw)
  To: jussi.kivilinna-X3B1VOXEql0
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA,
	gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r,
	linux-usb-u79uwXL29TY76Z2rM5mHXA

From: Jussi Kivilinna <jussi.kivilinna-X3B1VOXEql0@public.gmane.org>
Date: Wed, 07 Aug 2013 16:26:29 +0300

> URB setup packet must not be allocated as part of larger structure
> because DMA coherence issues.
> 
> Patch changes catc to allocate ctrl_dr member as separate buffer.
> 
> Patch is only compile tested.
> 
> Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
> Signed-off-by: Jussi Kivilinna <jussi.kivilinna-X3B1VOXEql0@public.gmane.org>

I absolutely do not agree with your adding the stable CC: tag for
a patch which has only been compile tested.

This applies to all of your other patches you submitted in this
cluster too.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] net/usb: catc: allocate URB setup_packet as separate buffer
  2013-08-09 20:42   ` [PATCH 1/2] net/usb: catc: allocate URB setup_packet as separate buffer David Miller
@ 2013-08-10  7:31     ` Jussi Kivilinna
  0 siblings, 0 replies; 4+ messages in thread
From: Jussi Kivilinna @ 2013-08-10  7:31 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, gregkh, linux-usb

On 09.08.2013 23:42, David Miller wrote:
> From: Jussi Kivilinna <jussi.kivilinna@iki.fi>
> Date: Wed, 07 Aug 2013 16:26:29 +0300
> 
>> URB setup packet must not be allocated as part of larger structure
>> because DMA coherence issues.
>>
>> Patch changes catc to allocate ctrl_dr member as separate buffer.
>>
>> Patch is only compile tested.
>>
>> Cc: <stable@vger.kernel.org>
>> Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
> 
> I absolutely do not agree with your adding the stable CC: tag for
> a patch which has only been compile tested.

Agreed, this was not brightest of ideas. I won't do it again.

-Jussi

> 
> This applies to all of your other patches you submitted in this
> cluster too.
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-08-10  7:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-07 13:26 [PATCH 1/2] net/usb: catc: allocate URB setup_packet as separate buffer Jussi Kivilinna
2013-08-07 13:26 ` [PATCH 2/2] net/usb: catc: allocate URB transfer_buffers as separate buffers Jussi Kivilinna
     [not found] ` <20130807132629.14001.2370.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
2013-08-09 20:42   ` [PATCH 1/2] net/usb: catc: allocate URB setup_packet as separate buffer David Miller
2013-08-10  7:31     ` Jussi Kivilinna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).