mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-07 15:04:17 +00:00
net: dsa: split dsa_switch_setup into two functions
Split the part of dsa_switch_setup() which is responsible for allocating and initializing a 'struct dsa_switch' and the part which is doing a given switch device setup and slave network device creation. This is a preliminary change to allow a separate caller of dsa_switch_setup_one() which may have externally initialized the dsa_switch structure, outside of dsa_switch_setup(). Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
b324c07ac4
commit
df197195a5
1 changed files with 51 additions and 37 deletions
|
@ -175,43 +175,14 @@ __ATTRIBUTE_GROUPS(dsa_hwmon);
|
||||||
#endif /* CONFIG_NET_DSA_HWMON */
|
#endif /* CONFIG_NET_DSA_HWMON */
|
||||||
|
|
||||||
/* basic switch operations **************************************************/
|
/* basic switch operations **************************************************/
|
||||||
static struct dsa_switch *
|
static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
|
||||||
dsa_switch_setup(struct dsa_switch_tree *dst, int index,
|
|
||||||
struct device *parent, struct device *host_dev)
|
|
||||||
{
|
{
|
||||||
struct dsa_chip_data *pd = dst->pd->chip + index;
|
struct dsa_switch_driver *drv = ds->drv;
|
||||||
struct dsa_switch_driver *drv;
|
struct dsa_switch_tree *dst = ds->dst;
|
||||||
struct dsa_switch *ds;
|
struct dsa_chip_data *pd = ds->pd;
|
||||||
int ret;
|
|
||||||
char *name;
|
|
||||||
int i;
|
|
||||||
bool valid_name_found = false;
|
bool valid_name_found = false;
|
||||||
|
int index = ds->index;
|
||||||
/*
|
int i, ret;
|
||||||
* Probe for switch model.
|
|
||||||
*/
|
|
||||||
drv = dsa_switch_probe(host_dev, pd->sw_addr, &name);
|
|
||||||
if (drv == NULL) {
|
|
||||||
netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n",
|
|
||||||
index);
|
|
||||||
return ERR_PTR(-EINVAL);
|
|
||||||
}
|
|
||||||
netdev_info(dst->master_netdev, "[%d]: detected a %s switch\n",
|
|
||||||
index, name);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Allocate and initialise switch state.
|
|
||||||
*/
|
|
||||||
ds = kzalloc(sizeof(*ds) + drv->priv_size, GFP_KERNEL);
|
|
||||||
if (ds == NULL)
|
|
||||||
return ERR_PTR(-ENOMEM);
|
|
||||||
|
|
||||||
ds->dst = dst;
|
|
||||||
ds->index = index;
|
|
||||||
ds->pd = dst->pd->chip + index;
|
|
||||||
ds->drv = drv;
|
|
||||||
ds->master_dev = host_dev;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Validate supplied switch configuration.
|
* Validate supplied switch configuration.
|
||||||
|
@ -350,13 +321,56 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_NET_DSA_HWMON */
|
#endif /* CONFIG_NET_DSA_HWMON */
|
||||||
|
|
||||||
return ds;
|
return ret;
|
||||||
|
|
||||||
out_free:
|
out_free:
|
||||||
mdiobus_free(ds->slave_mii_bus);
|
mdiobus_free(ds->slave_mii_bus);
|
||||||
out:
|
out:
|
||||||
kfree(ds);
|
kfree(ds);
|
||||||
return ERR_PTR(ret);
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct dsa_switch *
|
||||||
|
dsa_switch_setup(struct dsa_switch_tree *dst, int index,
|
||||||
|
struct device *parent, struct device *host_dev)
|
||||||
|
{
|
||||||
|
struct dsa_chip_data *pd = dst->pd->chip + index;
|
||||||
|
struct dsa_switch_driver *drv;
|
||||||
|
struct dsa_switch *ds;
|
||||||
|
int ret;
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Probe for switch model.
|
||||||
|
*/
|
||||||
|
drv = dsa_switch_probe(host_dev, pd->sw_addr, &name);
|
||||||
|
if (drv == NULL) {
|
||||||
|
netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n",
|
||||||
|
index);
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
}
|
||||||
|
netdev_info(dst->master_netdev, "[%d]: detected a %s switch\n",
|
||||||
|
index, name);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate and initialise switch state.
|
||||||
|
*/
|
||||||
|
ds = kzalloc(sizeof(*ds) + drv->priv_size, GFP_KERNEL);
|
||||||
|
if (ds == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ds->dst = dst;
|
||||||
|
ds->index = index;
|
||||||
|
ds->pd = pd;
|
||||||
|
ds->drv = drv;
|
||||||
|
ds->master_dev = host_dev;
|
||||||
|
|
||||||
|
ret = dsa_switch_setup_one(ds, parent);
|
||||||
|
if (ret)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return ds;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dsa_switch_destroy(struct dsa_switch *ds)
|
static void dsa_switch_destroy(struct dsa_switch *ds)
|
||||||
|
|
Loading…
Add table
Reference in a new issue