[PATCH net-next 13/14] usbnet: kaweth: Use net_device_stats from struct net_device

2017-04-07 Thread Tobias Klauser
Instead of using a private copy of struct net_device_stats in struct
kaweth_device, use stats from struct net_device. Also remove the now
unnecessary .ndo_get_stats function.

Cc: linux-usb@vger.kernel.org
Signed-off-by: Tobias Klauser <tklau...@distanz.ch>
---
 drivers/net/usb/kaweth.c | 32 ++--
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index 876f02f4945e..3d8ea18df696 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -245,8 +245,6 @@ struct kaweth_device
__u16 packet_filter_bitmap;
 
struct kaweth_ethernet_configuration configuration;
-
-   struct net_device_stats stats;
 };
 
 /
@@ -598,7 +596,7 @@ static void kaweth_usb_receive(struct urb *urb)
struct sk_buff *skb;
 
if (unlikely(status == -EPIPE)) {
-   kaweth->stats.rx_errors++;
+   net->stats.rx_errors++;
kaweth->end = 1;
wake_up(>term_wait);
dev_dbg(dev, "Status was -EPIPE.\n");
@@ -613,12 +611,12 @@ static void kaweth_usb_receive(struct urb *urb)
}
if (unlikely(status == -EPROTO || status == -ETIME ||
 status == -EILSEQ)) {
-   kaweth->stats.rx_errors++;
+   net->stats.rx_errors++;
dev_dbg(dev, "Status was -EPROTO, -ETIME, or -EILSEQ.\n");
return;
}
if (unlikely(status == -EOVERFLOW)) {
-   kaweth->stats.rx_errors++;
+   net->stats.rx_errors++;
dev_dbg(dev, "Status was -EOVERFLOW.\n");
}
spin_lock(>device_lock);
@@ -663,8 +661,8 @@ static void kaweth_usb_receive(struct urb *urb)
 
netif_rx(skb);
 
-   kaweth->stats.rx_packets++;
-   kaweth->stats.rx_bytes += pkt_len;
+   net->stats.rx_packets++;
+   net->stats.rx_bytes += pkt_len;
}
 
kaweth_resubmit_rx_urb(kaweth, GFP_ATOMIC);
@@ -810,7 +808,7 @@ static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb,
dev_kfree_skb_irq(skb);
skb = copied_skb;
if (!copied_skb) {
-   kaweth->stats.tx_errors++;
+   net->stats.tx_errors++;
netif_start_queue(net);
spin_unlock_irq(>device_lock);
return NETDEV_TX_OK;
@@ -834,15 +832,15 @@ static netdev_tx_t kaweth_start_xmit(struct sk_buff *skb,
{
dev_warn(>dev, "kaweth failed tx_urb %d\n", res);
 skip:
-   kaweth->stats.tx_errors++;
+   net->stats.tx_errors++;
 
netif_start_queue(net);
dev_kfree_skb_irq(skb);
}
else
{
-   kaweth->stats.tx_packets++;
-   kaweth->stats.tx_bytes += skb->len;
+   net->stats.tx_packets++;
+   net->stats.tx_bytes += skb->len;
}
 
spin_unlock_irq(>device_lock);
@@ -912,15 +910,6 @@ static void kaweth_async_set_rx_mode(struct kaweth_device 
*kaweth)
 }
 
 /
- * kaweth_netdev_stats
- /
-static struct net_device_stats *kaweth_netdev_stats(struct net_device *dev)
-{
-   struct kaweth_device *kaweth = netdev_priv(dev);
-   return >stats;
-}
-
-/
  * kaweth_tx_timeout
  /
 static void kaweth_tx_timeout(struct net_device *net)
@@ -928,7 +917,7 @@ static void kaweth_tx_timeout(struct net_device *net)
struct kaweth_device *kaweth = netdev_priv(net);
 
dev_warn(>dev, "%s: Tx timed out. Resetting.\n", net->name);
-   kaweth->stats.tx_errors++;
+   net->stats.tx_errors++;
netif_trans_update(net);
 
usb_unlink_urb(kaweth->tx_urb);
@@ -981,7 +970,6 @@ static const struct net_device_ops kaweth_netdev_ops = {
.ndo_start_xmit =   kaweth_start_xmit,
.ndo_tx_timeout =   kaweth_tx_timeout,
.ndo_set_rx_mode =  kaweth_set_rx_mode,
-   .ndo_get_stats =kaweth_netdev_stats,
.ndo_set_mac_address =  eth_mac_addr,
.ndo_validate_addr =eth_validate_addr,
 };
-- 
2.12.2


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


[PATCH net-next 14/14] usbnet: pegasus: Use net_device_stats from struct net_device

2017-04-07 Thread Tobias Klauser
Instead of using a private copy of struct net_device_stats in struct
pegasus, use stats from struct net_device. Also remove the now
unnecessary .ndo_get_stats function.

Cc: Petko Manolov <pet...@nucleusys.com>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Tobias Klauser <tklau...@distanz.ch>
---
 drivers/net/usb/pegasus.c | 36 +++-
 drivers/net/usb/pegasus.h |  1 -
 2 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index 321e059e13ae..6514c86f043e 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -501,13 +501,13 @@ static void read_bulk_callback(struct urb *urb)
if (rx_status & 0x1e) {
netif_dbg(pegasus, rx_err, net,
  "RX packet error %x\n", rx_status);
-   pegasus->stats.rx_errors++;
+   net->stats.rx_errors++;
if (rx_status & 0x06)   /* long or runt */
-   pegasus->stats.rx_length_errors++;
+   net->stats.rx_length_errors++;
if (rx_status & 0x08)
-   pegasus->stats.rx_crc_errors++;
+   net->stats.rx_crc_errors++;
if (rx_status & 0x10)   /* extra bits   */
-   pegasus->stats.rx_frame_errors++;
+   net->stats.rx_frame_errors++;
goto goon;
}
if (pegasus->chip == 0x8513) {
@@ -535,8 +535,8 @@ static void read_bulk_callback(struct urb *urb)
skb_put(pegasus->rx_skb, pkt_len);
pegasus->rx_skb->protocol = eth_type_trans(pegasus->rx_skb, net);
netif_rx(pegasus->rx_skb);
-   pegasus->stats.rx_packets++;
-   pegasus->stats.rx_bytes += pkt_len;
+   net->stats.rx_packets++;
+   net->stats.rx_bytes += pkt_len;
 
if (pegasus->flags & PEGASUS_UNPLUG)
return;
@@ -670,13 +670,13 @@ static void intr_callback(struct urb *urb)
/* byte 0 == tx_status1, reg 2B */
if (d[0] & (TX_UNDERRUN|EXCESSIVE_COL
|LATE_COL|JABBER_TIMEOUT)) {
-   pegasus->stats.tx_errors++;
+   net->stats.tx_errors++;
if (d[0] & TX_UNDERRUN)
-   pegasus->stats.tx_fifo_errors++;
+   net->stats.tx_fifo_errors++;
if (d[0] & (EXCESSIVE_COL | JABBER_TIMEOUT))
-   pegasus->stats.tx_aborted_errors++;
+   net->stats.tx_aborted_errors++;
if (d[0] & LATE_COL)
-   pegasus->stats.tx_window_errors++;
+   net->stats.tx_window_errors++;
}
 
/* d[5].LINK_STATUS lies on some adapters.
@@ -685,7 +685,7 @@ static void intr_callback(struct urb *urb)
 */
 
/* bytes 3-4 == rx_lostpkt, reg 2E/2F */
-   pegasus->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
+   net->stats.rx_missed_errors += ((d[3] & 0x7f) << 8) | d[4];
}
 
res = usb_submit_urb(urb, GFP_ATOMIC);
@@ -701,7 +701,7 @@ static void pegasus_tx_timeout(struct net_device *net)
pegasus_t *pegasus = netdev_priv(net);
netif_warn(pegasus, timer, net, "tx timeout\n");
usb_unlink_urb(pegasus->tx_urb);
-   pegasus->stats.tx_errors++;
+   net->stats.tx_errors++;
 }
 
 static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
@@ -731,23 +731,18 @@ static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
netif_device_detach(pegasus->net);
break;
default:
-   pegasus->stats.tx_errors++;
+   net->stats.tx_errors++;
netif_start_queue(net);
}
} else {
-   pegasus->stats.tx_packets++;
-   pegasus->stats.tx_bytes += skb->len;
+   net->stats.tx_packets++;
+   net->stats.tx_bytes += skb->len;
}
dev_kfree_skb(skb);
 
return NETDEV_TX_OK;
 }
 
-static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
-{
-   return &((pegasus_t *) netdev_priv(dev))->stats;
-}
-
 static inline void disable_net_traffic(pegasus_t *pegasus)
 {
__le16 tmp = cpu_to_le16(0);
@@ -1294,7 +1289,6 @@ static const struct net_device_ops pegasus_netdev_ops = {
.ndo_do_ioctl = pegasus_ioctl,
.ndo_start_xmit =   pegasus_start_xmit,
.ndo_set_rx_mode =  pegasus_set_multicast,
-   .ndo_get_stats =   

[PATCH] ch9200: Convert to use module_usb_driver

2015-09-22 Thread Tobias Klauser
Converts the ch9200 driver to use the module_usb_driver() macro which
makes the code smaller and a bit simpler.

Signed-off-by: Tobias Klauser <tklau...@distanz.ch>
---
 drivers/net/usb/ch9200.c | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c
index cabb670..5e151e6 100644
--- a/drivers/net/usb/ch9200.c
+++ b/drivers/net/usb/ch9200.c
@@ -426,18 +426,7 @@ static struct usb_driver ch9200_driver = {
.resume = usbnet_resume,
 };
 
-static int __init ch9200_init(void)
-{
-   return usb_register(_driver);
-}
-
-static void __exit ch9200_exit(void)
-{
-   usb_deregister(_driver);
-}
-
-module_init(ch9200_init);
-module_exit(ch9200_exit);
+module_usb_driver(ch9200_driver);
 
 MODULE_DESCRIPTION("QinHeng CH9200 USB Network device");
 MODULE_LICENSE("GPL");
-- 
2.5.0


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


Re: Fwd: USB HID Gadget support for dwc3 on platform/intel-mid

2015-01-09 Thread Tobias Klauser
Hi Chris

On 2015-01-08 at 17:38:07 +0100, Chris McClimans ch...@hippiehacker.org wrote:
 I found your email in the commits for gadget_hid.txt and thought one of you
 might might be able to point me in the right direction. I'm trying to get
 the g_hid module working with the Intel Edison.

Please don't send such e-mails to people in private, this is considered
quite rude by some. Rather send the e-mail to the respective mailing
list (linux-usb@vger.kernel.org in your case). That way the person
considering herself proficient on the subject can answer. Additionally
the possible solution for the problem will be archived in the mailin
list's archive, such that other people having the same problem in the
future might get their answer directly from there.

As for myself, I only did some minor edits to the documentation file and
haven't worked with g_hid in a while.

 I tried just compiling intel's patch(1) to 3.10.17
 with CONFIG_USB_GADGETFS=m CONFIG_USB_G_HID=m but I get an error trying to
 load the module:
 
 modprobe: ERROR: could not insert 'g_hid': No such device
 
 According to https://www.kernel.org/doc/Documentation/usb/gadget_hid.txt:
 
 g_hid is a platform driver, so to use it you need to add
 
   struct platform_device(s) to your platform code defining the
   HID function descriptors you want to use
 
 It's not clear to me what part of the platform code I should be adding, but
 I assume it's something under:
 https://github.com/instantinfrastructure/linux-yocto-3.10/tree/edison/arch/x86/platform/intel-mid

The documentation file already contains the respective code. Did you try
adding that to the appropriate place for your platform? You might want
to ask on a list specifc to the platform for where that would be.
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] USB: isp1362: Use devm_ioremap_resource

2014-08-05 Thread Tobias Klauser
Use devm_ioremap_resource to simplify error handling in the probe
function and to get rid of some boilerplate in the remove function.

Signed-off-by: Tobias Klauser tklau...@distanz.ch
---
 drivers/usb/host/isp1362-hcd.c | 103 ++---
 1 file changed, 25 insertions(+), 78 deletions(-)

diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 875bcfd..4bb3798 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -2616,30 +2616,10 @@ static int isp1362_remove(struct platform_device *pdev)
 {
struct usb_hcd *hcd = platform_get_drvdata(pdev);
struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
-   struct resource *res;
 
remove_debug_file(isp1362_hcd);
DBG(0, %s: Removing HCD\n, __func__);
usb_remove_hcd(hcd);
-
-   DBG(0, %s: Unmapping data_reg @ %p\n, __func__,
-   isp1362_hcd-data_reg);
-   iounmap(isp1362_hcd-data_reg);
-
-   DBG(0, %s: Unmapping addr_reg @ %p\n, __func__,
-   isp1362_hcd-addr_reg);
-   iounmap(isp1362_hcd-addr_reg);
-
-   res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-   DBG(0, %s: release mem_region: %08lx\n, __func__, (long unsigned 
int)res-start);
-   if (res)
-   release_mem_region(res-start, resource_size(res));
-
-   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   DBG(0, %s: release mem_region: %08lx\n, __func__, (long unsigned 
int)res-start);
-   if (res)
-   release_mem_region(res-start, resource_size(res));
-
DBG(0, %s: put_hcd\n, __func__);
usb_put_hcd(hcd);
DBG(0, %s: Done\n, __func__);
@@ -2651,12 +2631,11 @@ static int isp1362_probe(struct platform_device *pdev)
 {
struct usb_hcd *hcd;
struct isp1362_hcd *isp1362_hcd;
-   struct resource *addr, *data;
+   struct resource *addr, *data, *irq_res;
void __iomem *addr_reg;
void __iomem *data_reg;
int irq;
int retval = 0;
-   struct resource *irq_res;
unsigned int irq_flags = 0;
 
if (usb_disabled())
@@ -2667,52 +2646,35 @@ static int isp1362_probe(struct platform_device *pdev)
 * specific platform_data.  we don't probe for IRQs, and do only
 * minimal sanity checking.
 */
-   if (pdev-num_resources  3) {
-   retval = -ENODEV;
-   goto err1;
-   }
-
-   data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
-   irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
-   if (!addr || !data || !irq_res) {
-   retval = -ENODEV;
-   goto err1;
-   }
-   irq = irq_res-start;
+   if (pdev-num_resources  3)
+   return -ENODEV;
 
if (pdev-dev.dma_mask) {
DBG(1, won't do DMA);
-   retval = -ENODEV;
-   goto err1;
+   return -ENODEV;
}
 
-   if (!request_mem_region(addr-start, resource_size(addr), hcd_name)) {
-   retval = -EBUSY;
-   goto err1;
-   }
-   addr_reg = ioremap(addr-start, resource_size(addr));
-   if (addr_reg == NULL) {
-   retval = -ENOMEM;
-   goto err2;
-   }
+   irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+   if (!irq_res)
+   return -ENODEV;
 
-   if (!request_mem_region(data-start, resource_size(data), hcd_name)) {
-   retval = -EBUSY;
-   goto err3;
-   }
-   data_reg = ioremap(data-start, resource_size(data));
-   if (data_reg == NULL) {
-   retval = -ENOMEM;
-   goto err4;
-   }
+   irq = irq_res-start;
+
+   addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+   addr_reg = devm_ioremap_resource(pdev-dev, addr);
+   if (IS_ERR(addr_reg))
+   return PTR_ERR(addr_reg);
+
+   data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   data_reg = devm_ioremap_resource(pdev-dev, data);
+   if (IS_ERR(data_reg))
+   return PTR_ERR(data_reg);
 
/* allocate and initialize hcd */
hcd = usb_create_hcd(isp1362_hc_driver, pdev-dev, 
dev_name(pdev-dev));
-   if (!hcd) {
-   retval = -ENOMEM;
-   goto err5;
-   }
+   if (!hcd)
+   return -ENOMEM;
+
hcd-rsrc_start = data-start;
isp1362_hcd = hcd_to_isp1362_hcd(hcd);
isp1362_hcd-data_reg = data_reg;
@@ -2729,7 +2691,7 @@ static int isp1362_probe(struct platform_device *pdev)
if (!isp1362_hcd-board-delay) {
dev_err(hcd-self.controller, No platform delay function 
given\n);
retval = -ENODEV;
-   goto err6;
+   goto err;
}
 #endif
 
@@ -2744,32 +2706,17 @@ static int isp1362_probe(struct platform_device *pdev)
 
retval

[PATCH 1/2] usb: gadget: Add helper macro for usb_composite_driver boilerplate

2014-07-09 Thread Tobias Klauser
Introduce the module_usb_composite_driver macro as a convenience macro
for USB gadget composite driver modules, similar to module_usb_driver.
It is intended to be used by drivers which init/exit section does
nothing but calling usb_composite_probe/usb_composite_unrregister. By
using this macro it is possible to eliminate a few lines of boilerplate
code per USB gadget composite driver.

Based on f3a6a4b6 (USB: Add helper macro for usb_driver boilerplate)
which introduced the according macro for USB drivers.

Signed-off-by: Tobias Klauser tklau...@distanz.ch
---
 include/linux/usb/composite.h | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 7373203..c330f5e 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -386,6 +386,21 @@ struct usb_composite_driver {
 
 extern int usb_composite_probe(struct usb_composite_driver *driver);
 extern void usb_composite_unregister(struct usb_composite_driver *driver);
+
+/**
+ * module_usb_composite_driver() - Helper macro for registering a USB gadget
+ * composite driver
+ * @__usb_composite_driver: usb_composite_driver struct
+ *
+ * Helper macro for USB gadget composite drivers which do not do anything
+ * special in module init/exit. This eliminates a lot of boilerplate. Each
+ * module may only use this macro once, and calling it replaces module_init()
+ * and module_exit()
+ */
+#define module_usb_composite_driver(__usb_composite_driver) \
+   module_driver(__usb_composite_driver, usb_composite_probe, \
+  usb_composite_unregister)
+
 extern void usb_composite_setup_continue(struct usb_composite_dev *cdev);
 extern int composite_dev_prepare(struct usb_composite_driver *composite,
struct usb_composite_dev *cdev);
-- 
2.0.1


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


[PATCH 0/2] usb: gadget: Introduce and use helper macro for usb_composite_driver boilerplate

2014-07-09 Thread Tobias Klauser
Patch 1/2 introduces the module_usb_composite_driver helper macro (similar to
module_usb_driver and friends) which can be used to reduce
module_init/module_exit boilerplate for USB gadget composite drivers.

Patch 2/2 converts gadget drivers to use module_usb_composite_driver where
applicable.

Patches are against linux-next 20140709.

Tobias Klauser (2):
  usb: gadget: Add helper macro for usb_composite_driver boilerplate
  usb: gadget: Convert drivers to use module_usb_composite_driver()

 drivers/usb/gadget/acm_ms.c   | 14 ++
 drivers/usb/gadget/audio.c| 12 +---
 drivers/usb/gadget/cdc2.c | 14 ++
 drivers/usb/gadget/ether.c| 14 ++
 drivers/usb/gadget/gmidi.c| 13 +
 drivers/usb/gadget/multi.c| 13 +
 drivers/usb/gadget/ncm.c  | 14 ++
 drivers/usb/gadget/nokia.c| 12 +---
 drivers/usb/gadget/webcam.c   | 15 +--
 drivers/usb/gadget/zero.c | 14 ++
 include/linux/usb/composite.h | 15 +++
 11 files changed, 30 insertions(+), 120 deletions(-)

-- 
2.0.1


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


[PATCH 2/2] usb: gadget: Convert drivers to use module_usb_composite_driver()

2014-07-09 Thread Tobias Klauser
Use the module_usb_composite_driver() macro where applicable to
eliminate the module_init/module_exit boilerplate in USB gadget composite
drivers.

Signed-off-by: Tobias Klauser tklau...@distanz.ch
---
 drivers/usb/gadget/acm_ms.c | 14 ++
 drivers/usb/gadget/audio.c  | 12 +---
 drivers/usb/gadget/cdc2.c   | 14 ++
 drivers/usb/gadget/ether.c  | 14 ++
 drivers/usb/gadget/gmidi.c  | 13 +
 drivers/usb/gadget/multi.c  | 13 +
 drivers/usb/gadget/ncm.c| 14 ++
 drivers/usb/gadget/nokia.c  | 12 +---
 drivers/usb/gadget/webcam.c | 15 +--
 drivers/usb/gadget/zero.c   | 14 ++
 10 files changed, 15 insertions(+), 120 deletions(-)

diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index a252444..c30b7b5 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -267,18 +267,8 @@ static __refdata struct usb_composite_driver acm_ms_driver 
= {
.unbind = __exit_p(acm_ms_unbind),
 };
 
+module_usb_composite_driver(acm_ms_driver);
+
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_AUTHOR(Klaus Schwarzkopf schwarzk...@sensortherm.de);
 MODULE_LICENSE(GPL v2);
-
-static int __init init(void)
-{
-   return usb_composite_probe(acm_ms_driver);
-}
-module_init(init);
-
-static void __exit cleanup(void)
-{
-   usb_composite_unregister(acm_ms_driver);
-}
-module_exit(cleanup);
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index 231b0ef..6eb695e 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -172,17 +172,7 @@ static __refdata struct usb_composite_driver audio_driver 
= {
.unbind = __exit_p(audio_unbind),
 };
 
-static int __init init(void)
-{
-   return usb_composite_probe(audio_driver);
-}
-module_init(init);
-
-static void __exit cleanup(void)
-{
-   usb_composite_unregister(audio_driver);
-}
-module_exit(cleanup);
+module_usb_composite_driver(audio_driver);
 
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_AUTHOR(Bryan Wu coolo...@kernel.org);
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index e126b6b..2e85d94 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -231,18 +231,8 @@ static __refdata struct usb_composite_driver cdc_driver = {
.unbind = __exit_p(cdc_unbind),
 };
 
+module_usb_composite_driver(cdc_driver);
+
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_AUTHOR(David Brownell);
 MODULE_LICENSE(GPL);
-
-static int __init init(void)
-{
-   return usb_composite_probe(cdc_driver);
-}
-module_init(init);
-
-static void __exit cleanup(void)
-{
-   usb_composite_unregister(cdc_driver);
-}
-module_exit(cleanup);
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index c1c113e..c5fdc61 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -475,18 +475,8 @@ static __refdata struct usb_composite_driver eth_driver = {
.unbind = __exit_p(eth_unbind),
 };
 
+module_usb_composite_driver(eth_driver);
+
 MODULE_DESCRIPTION(PREFIX DRIVER_DESC);
 MODULE_AUTHOR(David Brownell, Benedikt Spanger);
 MODULE_LICENSE(GPL);
-
-static int __init init(void)
-{
-   return usb_composite_probe(eth_driver);
-}
-module_init(init);
-
-static void __exit cleanup(void)
-{
-   usb_composite_unregister(eth_driver);
-}
-module_exit(cleanup);
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index e879e2c..3d696b8 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -163,15 +163,4 @@ static __refdata struct usb_composite_driver midi_driver = 
{
.unbind = __exit_p(midi_unbind),
 };
 
-static int __init midi_init(void)
-{
-   return usb_composite_probe(midi_driver);
-}
-module_init(midi_init);
-
-static void __exit midi_cleanup(void)
-{
-   usb_composite_unregister(midi_driver);
-}
-module_exit(midi_cleanup);
-
+module_usb_composite_driver(midi_driver);
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 940f6cd..39d27bb 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -507,15 +507,4 @@ static __refdata struct usb_composite_driver multi_driver 
= {
.needs_serial   = 1,
 };
 
-
-static int __init multi_init(void)
-{
-   return usb_composite_probe(multi_driver);
-}
-module_init(multi_init);
-
-static void __exit multi_exit(void)
-{
-   usb_composite_unregister(multi_driver);
-}
-module_exit(multi_exit);
+module_usb_composite_driver(multi_driver);
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
index 81956fe..e90e23d 100644
--- a/drivers/usb/gadget/ncm.c
+++ b/drivers/usb/gadget/ncm.c
@@ -204,18 +204,8 @@ static __refdata struct usb_composite_driver ncm_driver = {
.unbind = __exit_p(gncm_unbind),
 };
 
+module_usb_composite_driver(ncm_driver);
+
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_AUTHOR(Yauheni Kaliuta);
 MODULE_LICENSE(GPL