usbnet: misc cleanup
Subsystems (6)
cover usbnet: misc cleanup
This patchset does some cleanup on usbnet.
drivers/net/usb/cdc-phonet.c | 4 +-- drivers/net/usb/pegasus.c | 4 --- drivers/net/usb/usbnet.c | 81 +++++++++++++++++++----------------------- include/linux/usb/usbnet.h | 4 +-- 4 files changed, 38 insertions(+), 55 deletions(-)
Thanks,
--
Ming Lei
--
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
A message that is not in the archive (sent off-list or not yet received): 1339463985-9006-1-git-send-email-tom.leiming-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 2/7 usbnet:pegasus: remove usb_get/put_dev in .probe and .disconnect
usb_device is parent device of usb_interface in the view of driver model, so its reference count is always held during .probe/.disconnect of usb_interface instance.
This patch just removes the unnecessay usb_get/put_dev.
--- drivers/net/usb/pegasus.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/usb/pegasus.c +0 -1
@@ -1329,8 +1329,6 @@ static int pegasus_probe(struct usb_interface *intf, } pegasus_count++; -usb_get_dev (dev);
PATCH 4/7 usbnet: remove EVENT_DEV_OPEN flag
In reply to a message not in the archiveEVENT_DEV_OPEN is introduced to mark if the interface is opened or not, but we already have IFF_UP to handle it, so just remove the flag and use IFF_UP.
Also the patch may fix one bug in failure path of usbnet_open:
it may return failure but EVENT_DEV_OPEN is not cleared. After this convering, dev->net->flags & IFF_UP always return consistent status of the interface.
--- drivers/net/usb/usbnet.c | 6 ++---- include/linux/usb/usbnet.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-)
drivers/net/usb/usbnet.c +2 -4
@@ -686,7 +686,6 @@ int usbnet_stop (struct net_device *net)struct driver_info *info = dev->driver_info;int retval; -clear_bit (EVENT_DEV_OPEN , &dev->flags);netif_stop_queue (net); netif_info(dev, ifdown, dev->net,
@@ -778,7 +777,6 @@ int usbnet_open (struct net_device *net) } } -set_bit (EVENT_DEV_OPEN , &dev->flags);netif_start_queue (net); netif_info(dev, ifup, dev->net, "open: enable queueing (rx %d, tx %d) mtu %d %s framing\n",
@@ -1542,7 +1540,7 @@ int usbnet_resume (struct usb_interface *intf)if (!--dev->suspend_count) {/* resume interrupt URBs */ -if (dev->interrupt &&test_bit (EVENT_DEV_OPEN , &dev->flags)) +if (dev->interrupt && (dev->net->flags &IFF_UP ))usb_submit_urb (dev->interrupt,GFP_NOIO );spin_lock_irq (&dev->txq.lock);
@@ -1564,7 +1562,7 @@ int usbnet_resume (struct usb_interface *intf)clear_bit (EVENT_DEV_ASLEEP , &dev->flags);spin_unlock_irq (&dev->txq.lock); -if (test_bit (EVENT_DEV_OPEN , &dev->flags)) { +if (dev->net->flags &IFF_UP ) {if (!(dev->txq.qlen >=TX_QLEN (dev)))netif_tx_wake_all_queues (dev->net);tasklet_schedule (&dev->bh);
include/linux/usb/usbnet.h +0 -1
@@ -68,7 +68,6 @@ struct usbnet {# define EVENT_RX_PAUSED 5# define EVENT_DEV_WAKING 6# define EVENT_DEV_ASLEEP 7 -# define EVENT_DEV_OPEN 8 };static inline struct usb_driver *driver_of (struct usb_interface *intf)
Signature · 6 lines
1.7.9.5 -- 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
A message that is not in the archive (sent off-list or not yet received): 1339463985-9006-5-git-send-email-tom.leiming-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 4/7] usbnet: remove EVENT_DEV_OPEN flag
Am Dienstag, 12. Juni 2012, 03:19:42 schrieb Ming Lei:
Quoted 3 lines
EVENT_DEV_OPENis introduced to mark if the interface is opened or not, but we already haveIFF_UPto handle it, so just remove the flag and useIFF_UP.
When is IFF_UP cleared? The flag is tested in usbnet_resume(), so it must be cleared before usbnet_stop() is called.
Regards
Oliver
--
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
Re: [PATCH 4/7] usbnet: remove EVENT_DEV_OPEN flag
Quoted 6 lines · Oliver Neukum
Am Dienstag, 12. Juni 2012, 03:19:42 schrieb Ming Lei:
Quoted 3 lines
EVENT_DEV_OPENis introduced to mark if the interface is opened or not, but we already haveIFF_UPto handle it, so just remove the flag and useIFF_UP.When is
IFF_UPcleared? The flag is tested inusbnet_resume(),
The flag is cleared just after usbnet_stop completes.
Quoted 1 line
so it must be cleared before
usbnet_stop()is called.
Yes, I see, otherwise system or runtime resume may happen at the same time with usbnet_stop.
Thanking you for point it out.
Thanks,
Signature · 1 line
Ming Lei
Re: [PATCH 4/7] usbnet: remove EVENT_DEV_OPEN flag
Quoted 9 lines · Ming Lei
Quoted 6 lines · Oliver Neukum
Am Dienstag, 12. Juni 2012, 03:19:42 schrieb Ming Lei:
Quoted 3 lines
EVENT_DEV_OPENis introduced to mark if the interface is opened or not, but we already haveIFF_UPto handle it, so just remove the flag and useIFF_UP.When is
IFF_UPcleared? The flag is tested inusbnet_resume(),The flag is cleared just after
usbnet_stopcompletes.
Looks we can use the below to replace EVENT_DEV_OPEN:
(netif_running((dev)->net) && ((dev)->net->flags & IFF_UP))
Thanks,
Signature · 1 line
Ming Lei
Re: [PATCH 4/7] usbnet: remove EVENT_DEV_OPEN flag
Am Mittwoch, 13. Juni 2012, 06:47:18 schrieb Ming Lei:
Quoted 7 lines · Ming Lei
Quoted 6 lines · Oliver Neukum
Quoted 5 lines
Am Dienstag, 12. Juni 2012, 03:19:42 schrieb Ming Lei:
Quoted 3 lines
EVENT_DEV_OPENis introduced to mark if the interface is opened or not, but we already haveIFF_UPto handle it, so just remove the flag and useIFF_UP.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
When is
IFF_UPcleared? The flag is tested inusbnet_resume(),The flag is cleared just after
usbnet_stopcompletes.Looks we can use the below to replace
EVENT_DEV_OPEN:(netif_running((dev)->net) && ((dev)->net->flags & IFF_UP))
That goes down a bit into the interna of the network code. If we do this, please encapsulated and with a big fat comment.
Regards
Oliver
A message that is not in the archive (sent off-list or not yet received): 201206130940.54817.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org
Re: [PATCH 4/7] usbnet: remove EVENT_DEV_OPEN flag
Quoted 10 lines · Oliver Neukum
Am Mittwoch, 13. Juni 2012, 06:47:18 schrieb Ming Lei:
Quoted 9 lines · Ming Lei
Quoted 8 lines · Oliver Neukum
Quoted 6 lines
Am Dienstag, 12. Juni 2012, 03:19:42 schrieb Ming Lei:
Quoted 3 lines
EVENT_DEV_OPENis introduced to mark if the interface is opened or not, but we already haveIFF_UPto handle it, so just remove the flag and useIFF_UP.When is
IFF_UPcleared? The flag is tested inusbnet_resume(),
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
The flag is cleared just after
usbnet_stopcompletes.Looks we can use the below to replace
EVENT_DEV_OPEN:(netif_running((dev)->net) && ((dev)->net->flags & IFF_UP))That goes down a bit into the interna of the network code. If we do this, please encapsulated and with a big fat comment.
There are already plenty of places in usbnet.c where netif_running(dev->net) is tested instead of EVENT_DEV_OPEN. Why should the test in usbnet_resume be any different?
The only reason I see is that some devices might want to keep interrupts running without the netdev being up, but the current code doesn't support that anyway. So better implement it when there is a device and driver needing it.
BTW, does the "&& (dev->net->flags & IFF_UP)" really make any difference, or could the test be simplified to
(netif_running(dev->net))
Bjørn
--
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
A message that is not in the archive (sent off-list or not yet received): 87r4tjlio1.fsf-lbf33ChDnrE/[email protected]
Re: [PATCH 4/7] usbnet: remove EVENT_DEV_OPEN flag
Quoted 5 lines · Bjørn Mork
BTW, does the "&& (
dev->net->flags&IFF_UP)" really make any difference, or could the test be simplified to(netif_running(dev->net))
Neither netif_running(dev->net) nor (dev->net->flags & IFF_UP) is enough.
In the start of usbnet_open(), the usb device may be waken up and usbnet_resume will see netif_running(dev->net) in the situation, so may cause problem since the interface hasn't been UP yet.
If just checking on (dev->net->flags & IFF_UP), it still may cause problem in usbnet_resume as pointed by Oliver.
So looks only checking on both netif_running(dev->net) and (dev->net->flags & IFF_UP) is OK.
Thanks,
Signature · 5 lines
Ming Lei -- 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
PATCH 6/7 usbnet: remove declaration for intr_complete
In reply to a message not in the archiveRemove declaration for intr_complete so that ctags may be happy to decrease duplicated symbols, also decrease one line code.
--- drivers/net/usb/usbnet.c | 72 ++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 37 deletions(-)
drivers/net/usb/usbnet.c +35 -36
@@ -180,7 +180,41 @@ int usbnet_get_ethernet_addr(struct usbnet *dev, int iMACAddress) }EXPORT_SYMBOL_GPL (usbnet_get_ethernet_addr); -static void intr_complete (struct urb *urb); +static void intr_complete (struct urb *urb) +{ +struct usbnet *dev = urb->context; +int status = urb->status; + +switch (status) { +/* success */ +case 0 : + dev->driver_info->status (dev, urb); +break ; + +/* software-driven interface shutdown */ +case -ENOENT :/* urb killed */ +case -ESHUTDOWN :/* hardware gone */ +netif_dbg (dev, ifdown, dev->net, +"intr shutdown, code %d\n" , status); +return ; + +/* NOTE: not throttling like RX/TX, since this endpoint +* already polls infrequently +*/ +default : +netdev_dbg (dev->net,"intr status %d\n" , status); +break ; + } + +if (!netif_running (dev->net)) +return ; + +memset (urb->transfer_buffer,0 , urb->transfer_buffer_length); + status =usb_submit_urb (urb,GFP_ATOMIC ); +if (status !=0 ) +netif_err (dev, timer, dev->net, +"intr resubmit --> %d\n" , status); +}static int init_status (struct usbnet *dev,struct usb_interface *intf) {
@@ -519,42 +553,6 @@ block:netif_dbg (dev, rx_err, dev->net,"no read resubmitted\n" ); } -static void intr_complete (struct urb *urb) -{ -struct usbnet *dev = urb->context; -int status = urb->status; - -switch (status) { -/* success */ -case 0 : - dev->driver_info->status (dev, urb); -break ; - -/* software-driven interface shutdown */ -case -ENOENT :/* urb killed */ -case -ESHUTDOWN :/* hardware gone */ -netif_dbg (dev, ifdown, dev->net, -"intr shutdown, code %d\n" , status); -return ; - -/* NOTE: not throttling like RX/TX, since this endpoint -* already polls infrequently -*/ -default : -netdev_dbg (dev->net,"intr status %d\n" , status); -break ; - } - -if (!netif_running (dev->net)) -return ; - -memset (urb->transfer_buffer,0 , urb->transfer_buffer_length); - status =usb_submit_urb (urb,GFP_ATOMIC ); -if (status !=0 ) -netif_err (dev, timer, dev->net, -"intr resubmit --> %d\n" , status); -}
PATCH 7/7 usbnet: don't initialize transfer buffer before submit status URB
In reply to a message not in the archiveThe line below in intr_complete isn't needed,
memset(urb->transfer_buffer, 0, urb->transfer_buffer_length);
so just remove it.
--- drivers/net/usb/usbnet.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/usb/usbnet.c +0 -1
@@ -209,7 +209,6 @@ static void intr_complete (struct urb *urb)if (!netif_running (dev->net))return ; -memset (urb->transfer_buffer,0 , urb->transfer_buffer_length); status =usb_submit_urb (urb,GFP_ATOMIC );if (status !=0 ) netif_err(dev, timer, dev->net,
Signature · 6 lines
1.7.9.5 -- 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
From: Ming Lei <[email protected]>
Date: Tue, 12 Jun 2012 09:19:38 +0800
Quoted 1 line
This patchset does some cleanup on usbnet.
I've applied all of these patches except the EVENT_DEV_OPEN removal which still needs some discussion.
--
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
PATCH 1/7 usbnet: remove usb_get/put_dev in .probe and .disconnect
In reply to Ming Leiusb_device is parent device of usb_interface in the view of driver model, so its reference count is always held during .probe/.disconnect of usb_interface instance.
This patch just removes the unnecessay usb_get/put_dev.
--- drivers/net/usb/usbnet.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/usb/usbnet.c +0 -4
@@ -1307,7 +1307,6 @@ void usbnet_disconnect (struct usb_interface *intf)usb_free_urb (dev->interrupt);free_netdev (net); -usb_put_dev (xdev); }EXPORT_SYMBOL_GPL (usbnet_disconnect);
@@ -1363,8 +1362,6 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) xdev =interface_to_usbdev (udev); interface = udev->cur_altsetting; -usb_get_dev (xdev); - status = -ENOMEM ;// set up our own records
@@ -1493,7 +1490,6 @@ out3: out1:free_netdev (net); out: -usb_put_dev (xdev);return status; }EXPORT_SYMBOL_GPL (usbnet_probe);
Signature · 1 line
1.7.9.5
PATCH 3/7 usbnet:cdc-phonet: remove usb_get/put_dev in .probe and .disconnect
In reply to Ming Leiusb_device is parent device of usb_interface in the view of driver model, so its reference count is always held during .probe/.disconnect of usb_interface instance.
This patch just removes the unnecessay usb_get/put_dev.
--- drivers/net/usb/cdc-phonet.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/usb/cdc-phonet.c +1 -3
@@ -394,7 +394,7 @@ int usbpn_probe(struct usb_interface *intf, const struct usb_device_id *id)SET_NETDEV_DEV (dev, &intf->dev); pnd->dev = dev; - pnd->usb =usb_get_dev (usbdev); + pnd->usb = usbdev; pnd->intf = intf; pnd->data_intf = data_intf;spin_lock_init (&pnd->tx_lock);
@@ -440,7 +440,6 @@ out:static void usbpn_disconnect (struct usb_interface *intf) {struct usbpn_dev *pnd =usb_get_intfdata (intf); -struct usb_device *usb = pnd->usb;if (pnd->disconnected)return ;
@@ -449,7 +448,6 @@ static void usbpn_disconnect(struct usb_interface *intf)usb_driver_release_interface (&usbpn_driver, (pnd->intf == intf) ? pnd->data_intf : pnd->intf);unregister_netdev (pnd->dev); -usb_put_dev (usb); }static struct usb_driver usbpn_driver = {
Signature · 1 line
1.7.9.5
PATCH 5/7 usbnet: remove flag of EVENT_DEV_WAKING
In reply to Ming LeiThe flag of EVENT_DEV_WAKING is not used any more, so just remove it.
--- include/linux/usb/usbnet.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/usb/usbnet.h +1 -2
@@ -66,8 +66,7 @@ struct usbnet {# define EVENT_STS_SPLIT 3# define EVENT_LINK_RESET 4# define EVENT_RX_PAUSED 5 -# define EVENT_DEV_WAKING 6 -# define EVENT_DEV_ASLEEP 7 +# define EVENT_DEV_ASLEEP 6 };static inline struct usb_driver *driver_of (struct usb_interface *intf)
Signature · 1 line
1.7.9.5