diff options
Diffstat (limited to 'drivers/usb/gadget/u_ether.c')
-rw-r--r-- | drivers/usb/gadget/u_ether.c | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index a0aa721d8b21..4b76124ce96b 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c | |||
@@ -50,7 +50,6 @@ | |||
50 | 50 | ||
51 | struct eth_dev { | 51 | struct eth_dev { |
52 | /* lock is held while accessing port_usb | 52 | /* lock is held while accessing port_usb |
53 | * or updating its backlink port_usb->ioport | ||
54 | */ | 53 | */ |
55 | spinlock_t lock; | 54 | spinlock_t lock; |
56 | struct gether *port_usb; | 55 | struct gether *port_usb; |
@@ -729,8 +728,6 @@ static int get_ether_addr(const char *str, u8 *dev_addr) | |||
729 | return 1; | 728 | return 1; |
730 | } | 729 | } |
731 | 730 | ||
732 | static struct eth_dev *the_dev; | ||
733 | |||
734 | static const struct net_device_ops eth_netdev_ops = { | 731 | static const struct net_device_ops eth_netdev_ops = { |
735 | .ndo_open = eth_open, | 732 | .ndo_open = eth_open, |
736 | .ndo_stop = eth_stop, | 733 | .ndo_stop = eth_stop, |
@@ -758,19 +755,16 @@ static struct device_type gadget_type = { | |||
758 | * | 755 | * |
759 | * Returns negative errno, or zero on success | 756 | * Returns negative errno, or zero on success |
760 | */ | 757 | */ |
761 | int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | 758 | struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], |
762 | const char *netname) | 759 | const char *netname) |
763 | { | 760 | { |
764 | struct eth_dev *dev; | 761 | struct eth_dev *dev; |
765 | struct net_device *net; | 762 | struct net_device *net; |
766 | int status; | 763 | int status; |
767 | 764 | ||
768 | if (the_dev) | ||
769 | return -EBUSY; | ||
770 | |||
771 | net = alloc_etherdev(sizeof *dev); | 765 | net = alloc_etherdev(sizeof *dev); |
772 | if (!net) | 766 | if (!net) |
773 | return -ENOMEM; | 767 | return ERR_PTR(-ENOMEM); |
774 | 768 | ||
775 | dev = netdev_priv(net); | 769 | dev = netdev_priv(net); |
776 | spin_lock_init(&dev->lock); | 770 | spin_lock_init(&dev->lock); |
@@ -807,12 +801,11 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | |||
807 | if (status < 0) { | 801 | if (status < 0) { |
808 | dev_dbg(&g->dev, "register_netdev failed, %d\n", status); | 802 | dev_dbg(&g->dev, "register_netdev failed, %d\n", status); |
809 | free_netdev(net); | 803 | free_netdev(net); |
804 | dev = ERR_PTR(status); | ||
810 | } else { | 805 | } else { |
811 | INFO(dev, "MAC %pM\n", net->dev_addr); | 806 | INFO(dev, "MAC %pM\n", net->dev_addr); |
812 | INFO(dev, "HOST MAC %pM\n", dev->host_mac); | 807 | INFO(dev, "HOST MAC %pM\n", dev->host_mac); |
813 | 808 | ||
814 | the_dev = dev; | ||
815 | |||
816 | /* two kinds of host-initiated state changes: | 809 | /* two kinds of host-initiated state changes: |
817 | * - iff DATA transfer is active, carrier is "on" | 810 | * - iff DATA transfer is active, carrier is "on" |
818 | * - tx queueing enabled if open *and* carrier is "on" | 811 | * - tx queueing enabled if open *and* carrier is "on" |
@@ -820,7 +813,7 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | |||
820 | netif_carrier_off(net); | 813 | netif_carrier_off(net); |
821 | } | 814 | } |
822 | 815 | ||
823 | return status; | 816 | return dev; |
824 | } | 817 | } |
825 | 818 | ||
826 | /** | 819 | /** |
@@ -829,19 +822,16 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], | |||
829 | * | 822 | * |
830 | * This is called to free all resources allocated by @gether_setup(). | 823 | * This is called to free all resources allocated by @gether_setup(). |
831 | */ | 824 | */ |
832 | void gether_cleanup(void) | 825 | void gether_cleanup(struct eth_dev *dev) |
833 | { | 826 | { |
834 | if (!the_dev) | 827 | if (!dev) |
835 | return; | 828 | return; |
836 | 829 | ||
837 | unregister_netdev(the_dev->net); | 830 | unregister_netdev(dev->net); |
838 | flush_work(&the_dev->work); | 831 | flush_work(&dev->work); |
839 | free_netdev(the_dev->net); | 832 | free_netdev(dev->net); |
840 | |||
841 | the_dev = NULL; | ||
842 | } | 833 | } |
843 | 834 | ||
844 | |||
845 | /** | 835 | /** |
846 | * gether_connect - notify network layer that USB link is active | 836 | * gether_connect - notify network layer that USB link is active |
847 | * @link: the USB link, set up with endpoints, descriptors matching | 837 | * @link: the USB link, set up with endpoints, descriptors matching |
@@ -860,7 +850,7 @@ void gether_cleanup(void) | |||
860 | */ | 850 | */ |
861 | struct net_device *gether_connect(struct gether *link) | 851 | struct net_device *gether_connect(struct gether *link) |
862 | { | 852 | { |
863 | struct eth_dev *dev = the_dev; | 853 | struct eth_dev *dev = link->ioport; |
864 | int result = 0; | 854 | int result = 0; |
865 | 855 | ||
866 | if (!dev) | 856 | if (!dev) |
@@ -895,7 +885,6 @@ struct net_device *gether_connect(struct gether *link) | |||
895 | 885 | ||
896 | spin_lock(&dev->lock); | 886 | spin_lock(&dev->lock); |
897 | dev->port_usb = link; | 887 | dev->port_usb = link; |
898 | link->ioport = dev; | ||
899 | if (netif_running(dev->net)) { | 888 | if (netif_running(dev->net)) { |
900 | if (link->open) | 889 | if (link->open) |
901 | link->open(link); | 890 | link->open(link); |
@@ -989,6 +978,5 @@ void gether_disconnect(struct gether *link) | |||
989 | 978 | ||
990 | spin_lock(&dev->lock); | 979 | spin_lock(&dev->lock); |
991 | dev->port_usb = NULL; | 980 | dev->port_usb = NULL; |
992 | link->ioport = NULL; | ||
993 | spin_unlock(&dev->lock); | 981 | spin_unlock(&dev->lock); |
994 | } | 982 | } |