Skip to content

Commit

Permalink
usb: gadget: move the global the_dev variable to their users
Browse files Browse the repository at this point in the history
the u_ether.c file has a global variable named the_dev which keeps a
pointer to the network device after it has been created via
gether_setup_name(). It is only used internally by u_ether. This patches
moves the variable to its users and passes it via the port.ioport where
it is saved later anyway.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Apr 3, 2013
1 parent 1576182 commit d6a0143
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 87 deletions.
14 changes: 7 additions & 7 deletions drivers/usb/gadget/cdc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static struct usb_gadget_strings *dev_strings[] = {
};

static u8 hostaddr[ETH_ALEN];

static struct eth_dev *the_dev;
/*-------------------------------------------------------------------------*/
static struct usb_function *f_acm;
static struct usb_function_instance *fi_serial;
Expand All @@ -122,7 +122,7 @@ static int __init cdc_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

status = ecm_bind_config(c, hostaddr);
status = ecm_bind_config(c, hostaddr, the_dev);
if (status < 0)
return status;

Expand Down Expand Up @@ -169,9 +169,9 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
}

/* set up network link layer */
status = gether_setup(cdev->gadget, hostaddr);
if (status < 0)
return status;
the_dev = gether_setup(cdev->gadget, hostaddr);
if (IS_ERR(the_dev))
return PTR_ERR(the_dev);

/* set up serial link layer */
status = gserial_alloc_line(&tty_line);
Expand Down Expand Up @@ -202,7 +202,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
fail1:
gserial_free_line(tty_line);
fail0:
gether_cleanup();
gether_cleanup(the_dev);
return status;
}

Expand All @@ -211,7 +211,7 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
usb_put_function(f_acm);
usb_put_function_instance(fi_serial);
gserial_free_line(tty_line);
gether_cleanup();
gether_cleanup(the_dev);
return 0;
}

Expand Down
20 changes: 10 additions & 10 deletions drivers/usb/gadget/ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static struct usb_gadget_strings *dev_strings[] = {
};

static u8 hostaddr[ETH_ALEN];

static struct eth_dev *the_dev;
/*-------------------------------------------------------------------------*/

/*
Expand All @@ -224,7 +224,7 @@ static int __init rndis_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

return rndis_bind_config(c, hostaddr);
return rndis_bind_config(c, hostaddr, the_dev);
}

static struct usb_configuration rndis_config_driver = {
Expand Down Expand Up @@ -257,11 +257,11 @@ static int __init eth_do_config(struct usb_configuration *c)
}

if (use_eem)
return eem_bind_config(c);
return eem_bind_config(c, the_dev);
else if (can_support_ecm(c->cdev->gadget))
return ecm_bind_config(c, hostaddr);
return ecm_bind_config(c, hostaddr, the_dev);
else
return geth_bind_config(c, hostaddr);
return geth_bind_config(c, hostaddr, the_dev);
}

static struct usb_configuration eth_config_driver = {
Expand All @@ -279,9 +279,9 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
int status;

/* set up network link layer */
status = gether_setup(cdev->gadget, hostaddr);
if (status < 0)
return status;
the_dev = gether_setup(cdev->gadget, hostaddr);
if (IS_ERR(the_dev))
return PTR_ERR(the_dev);

/* set up main config label and device descriptor */
if (use_eem) {
Expand Down Expand Up @@ -338,13 +338,13 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
return 0;

fail:
gether_cleanup();
gether_cleanup(the_dev);
return status;
}

static int __exit eth_unbind(struct usb_composite_dev *cdev)
{
gether_cleanup();
gether_cleanup(the_dev);
return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion drivers/usb/gadget/f_ecm.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f)
* for calling @gether_cleanup() before module unload.
*/
int
ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev)
{
struct f_ecm *ecm;
int status;
Expand Down Expand Up @@ -852,6 +853,7 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr);
ecm_string_defs[1].s = ecm->ethaddr;

ecm->port.ioport = dev;
ecm->port.cdc_filter = DEFAULT_FILTER;

ecm->port.func.name = "cdc_ethernet";
Expand Down
3 changes: 2 additions & 1 deletion drivers/usb/gadget/f_eem.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static int eem_unwrap(struct gether *port,
* Caller must have called @gether_setup(). Caller is also responsible
* for calling @gether_cleanup() before module unload.
*/
int __init eem_bind_config(struct usb_configuration *c)
int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev)
{
struct f_eem *eem;
int status;
Expand All @@ -549,6 +549,7 @@ int __init eem_bind_config(struct usb_configuration *c)
if (!eem)
return -ENOMEM;

eem->port.ioport = dev;
eem->port.cdc_filter = DEFAULT_FILTER;

eem->port.func.name = "cdc_eem";
Expand Down
4 changes: 3 additions & 1 deletion drivers/usb/gadget/f_ncm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,8 @@ ncm_unbind(struct usb_configuration *c, struct usb_function *f)
* Caller must have called @gether_setup(). Caller is also responsible
* for calling @gether_cleanup() before module unload.
*/
int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev)
{
struct f_ncm *ncm;
int status;
Expand Down Expand Up @@ -1321,6 +1322,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])

spin_lock_init(&ncm->lock);
ncm_reset_values(ncm);
ncm->port.ioport = dev;
ncm->port.is_fixed = true;

ncm->port.func.name = "cdc_network";
Expand Down
3 changes: 2 additions & 1 deletion drivers/usb/gadget/f_rndis.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ static inline bool can_support_rndis(struct usb_configuration *c)

int
rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
u32 vendorID, const char *manufacturer)
u32 vendorID, const char *manufacturer, struct eth_dev *dev)
{
struct f_rndis *rndis;
int status;
Expand Down Expand Up @@ -847,6 +847,7 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
rndis->vendorID = vendorID;
rndis->manufacturer = manufacturer;

rndis->port.ioport = dev;
/* RNDIS activates when the host changes this filter */
rndis->port.cdc_filter = 0;

Expand Down
4 changes: 3 additions & 1 deletion drivers/usb/gadget/f_subset.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ geth_unbind(struct usb_configuration *c, struct usb_function *f)
* Caller must have called @gether_setup(). Caller is also responsible
* for calling @gether_cleanup() before module unload.
*/
int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev)
{
struct f_gether *geth;
int status;
Expand All @@ -406,6 +407,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr);
geth_string_defs[1].s = geth->ethaddr;

geth->port.ioport = dev;
geth->port.cdc_filter = DEFAULT_FILTER;

geth->port.func.name = "cdc_subset";
Expand Down
35 changes: 21 additions & 14 deletions drivers/usb/gadget/g_ffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#define pr_fmt(fmt) "g_ffs: " fmt

#include <linux/module.h>

/*
* kbuild is not very cooperative with respect to linking separately
* compiled library objects into one module. So for now we won't use
Expand All @@ -38,13 +37,16 @@
# include "u_ether.c"

static u8 gfs_hostaddr[ETH_ALEN];
static struct eth_dev *the_dev;
# ifdef CONFIG_USB_FUNCTIONFS_ETH
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev);
# endif
#else
# define gether_cleanup() do { } while (0)
# define gether_setup(gadget, hostaddr) ((int)0)
# define the_dev NULL
# define gether_cleanup(dev) do { } while (0)
# define gfs_hostaddr NULL
struct eth_dev;
#endif

#include "f_fs.c"
Expand Down Expand Up @@ -137,7 +139,8 @@ static struct usb_gadget_strings *gfs_dev_strings[] = {

struct gfs_configuration {
struct usb_configuration c;
int (*eth)(struct usb_configuration *c, u8 *ethaddr);
int (*eth)(struct usb_configuration *c, u8 *ethaddr,
struct eth_dev *dev);
} gfs_configurations[] = {
#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
{
Expand Down Expand Up @@ -346,10 +349,13 @@ static int gfs_bind(struct usb_composite_dev *cdev)

if (missing_funcs)
return -ENODEV;

ret = gether_setup(cdev->gadget, gfs_hostaddr);
if (unlikely(ret < 0))
#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
the_dev = gether_setup(cdev->gadget, gfs_hostaddr);
#endif
if (IS_ERR(the_dev)) {
ret = PTR_ERR(the_dev);
goto error_quick;
}
gfs_ether_setup = true;

ret = usb_string_ids_tab(cdev, gfs_strings);
Expand Down Expand Up @@ -386,7 +392,7 @@ static int gfs_bind(struct usb_composite_dev *cdev)
for (i = 0; i < func_num; i++)
functionfs_unbind(ffs_tab[i].ffs_data);
error:
gether_cleanup();
gether_cleanup(the_dev);
error_quick:
gfs_ether_setup = false;
return ret;
Expand All @@ -410,7 +416,7 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
* do...?
*/
if (gfs_ether_setup)
gether_cleanup();
gether_cleanup(the_dev);
gfs_ether_setup = false;

for (i = func_num; --i; )
Expand Down Expand Up @@ -440,7 +446,7 @@ static int gfs_do_config(struct usb_configuration *c)
}

if (gc->eth) {
ret = gc->eth(c, gfs_hostaddr);
ret = gc->eth(c, gfs_hostaddr, the_dev);
if (unlikely(ret < 0))
return ret;
}
Expand Down Expand Up @@ -469,11 +475,12 @@ static int gfs_do_config(struct usb_configuration *c)

#ifdef CONFIG_USB_FUNCTIONFS_ETH

static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev)
{
return can_support_ecm(c->cdev->gadget)
? ecm_bind_config(c, ethaddr)
: geth_bind_config(c, ethaddr);
? ecm_bind_config(c, ethaddr, dev)
: geth_bind_config(c, ethaddr, dev);
}

#endif
15 changes: 8 additions & 7 deletions drivers/usb/gadget/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static u8 hostaddr[ETH_ALEN];

static unsigned char tty_line;
static struct usb_function_instance *fi_acm;
static struct eth_dev *the_dev;

/********** RNDIS **********/

Expand All @@ -152,7 +153,7 @@ static __init int rndis_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

ret = rndis_bind_config(c, hostaddr);
ret = rndis_bind_config(c, hostaddr, the_dev);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -214,7 +215,7 @@ static __init int cdc_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

ret = ecm_bind_config(c, hostaddr);
ret = ecm_bind_config(c, hostaddr, the_dev);
if (ret < 0)
return ret;

Expand Down Expand Up @@ -279,9 +280,9 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
}

/* set up network link layer */
status = gether_setup(cdev->gadget, hostaddr);
if (status < 0)
return status;
the_dev = gether_setup(cdev->gadget, hostaddr);
if (IS_ERR(the_dev))
return PTR_ERR(the_dev);

/* set up serial link layer */
status = gserial_alloc_line(&tty_line);
Expand Down Expand Up @@ -337,7 +338,7 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
fail0dot5:
gserial_free_line(tty_line);
fail0:
gether_cleanup();
gether_cleanup(the_dev);
return status;
}

Expand All @@ -351,7 +352,7 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
#endif
usb_put_function_instance(fi_acm);
gserial_free_line(tty_line);
gether_cleanup();
gether_cleanup(the_dev);
return 0;
}

Expand Down
13 changes: 7 additions & 6 deletions drivers/usb/gadget/ncm.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL,
};

struct eth_dev *the_dev;
static u8 hostaddr[ETH_ALEN];

/*-------------------------------------------------------------------------*/
Expand All @@ -124,7 +125,7 @@ static int __init ncm_do_config(struct usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}

return ncm_bind_config(c, hostaddr);
return ncm_bind_config(c, hostaddr, the_dev);
}

static struct usb_configuration ncm_config_driver = {
Expand All @@ -143,9 +144,9 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
int status;

/* set up network link layer */
status = gether_setup(cdev->gadget, hostaddr);
if (status < 0)
return status;
the_dev = gether_setup(cdev->gadget, hostaddr);
if (IS_ERR(the_dev))
return PTR_ERR(the_dev);

/* Allocate string descriptor numbers ... note that string
* contents can be overridden by the composite_dev glue.
Expand All @@ -168,13 +169,13 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
return 0;

fail:
gether_cleanup();
gether_cleanup(the_dev);
return status;
}

static int __exit gncm_unbind(struct usb_composite_dev *cdev)
{
gether_cleanup();
gether_cleanup(the_dev);
return 0;
}

Expand Down
Loading

0 comments on commit d6a0143

Please sign in to comment.