From 0ac690c36aadbfca61c9028e4e683abba4bcc4f2 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Fri, 12 Aug 2011 14:35:42 -0700 Subject: [PATCH] USB: gadget: android: Use "rndis%d" for RNDIS device name instead of "usb%d" Signed-off-by: Mike Lockwood --- drivers/usb/gadget/android.c | 2 +- drivers/usb/gadget/u_ether.c | 22 +++++++++++++++++++++- drivers/usb/gadget/u_ether.h | 3 +++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c index ebe6766..c82b43b 100644 --- a/drivers/usb/gadget/android.c +++ b/drivers/usb/gadget/android.c @@ -373,7 +373,7 @@ static int rndis_function_bind_config(struct android_usb_function *f, rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2], rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]); - ret = gether_setup(c->cdev->gadget, rndis->ethaddr); + ret = gether_setup_name(c->cdev->gadget, rndis->ethaddr, "rndis"); if (ret) { pr_err("%s: gether_setup failed\n", __func__); return ret; diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c index 6590501..b5a30fe 100644 --- a/drivers/usb/gadget/u_ether.c +++ b/drivers/usb/gadget/u_ether.c @@ -765,6 +765,26 @@ static struct device_type gadget_type = { */ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) { + return gether_setup_name(g, ethaddr, "usb"); +} + +/** + * gether_setup_name - initialize one ethernet-over-usb link + * @g: gadget to associated with these links + * @ethaddr: NULL, or a buffer in which the ethernet address of the + * host side of the link is recorded + * @netname: name for network device (for example, "usb") + * Context: may sleep + * + * This sets up the single network link that may be exported by a + * gadget driver using this framework. The link layer addresses are + * set up using module parameters. + * + * Returns negative errno, or zero on success + */ +int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], + const char *netname) +{ struct eth_dev *dev; struct net_device *net; int status; @@ -787,7 +807,7 @@ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) /* network device setup */ dev->net = net; - strcpy(net->name, "usb%d"); + snprintf(net->name, sizeof(net->name), "%s%%d", netname); if (get_ether_addr(dev_addr, net->dev_addr)) dev_warn(&g->dev, diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h index 5bb1021..64b65f9 100644 --- a/drivers/usb/gadget/u_ether.h +++ b/drivers/usb/gadget/u_ether.h @@ -86,6 +86,9 @@ struct gether { /* netdev setup/teardown as directed by the gadget driver */ int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]); void gether_cleanup(void); +/* variant of gether_setup that allows customizing network device name */ +int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], + const char *netname); /* connect/disconnect is handled by individual functions */ struct net_device *gether_connect(struct gether *); -- 2.7.4