diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2015-03-05 15:35:06 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-06 00:18:20 -0500 |
commit | df197195a5248164df0709fbadc61133897281f5 (patch) | |
tree | b1a5a3f8088ac6120af7e40815754849811a30ea /net/dsa/dsa.c | |
parent | b324c07ac4771a6ac8f57a3e1897e1b36b0a9ff0 (diff) |
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>
Diffstat (limited to 'net/dsa/dsa.c')
-rw-r--r-- | net/dsa/dsa.c | 88 |
1 files changed, 51 insertions, 37 deletions
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 79879d01488a..6f02ccc57593 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c | |||
@@ -175,43 +175,14 @@ __ATTRIBUTE_GROUPS(dsa_hwmon); | |||
175 | #endif /* CONFIG_NET_DSA_HWMON */ | 175 | #endif /* CONFIG_NET_DSA_HWMON */ |
176 | 176 | ||
177 | /* basic switch operations **************************************************/ | 177 | /* basic switch operations **************************************************/ |
178 | static struct dsa_switch * | 178 | static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent) |
179 | dsa_switch_setup(struct dsa_switch_tree *dst, int index, | ||
180 | struct device *parent, struct device *host_dev) | ||
181 | { | 179 | { |
182 | struct dsa_chip_data *pd = dst->pd->chip + index; | 180 | struct dsa_switch_driver *drv = ds->drv; |
183 | struct dsa_switch_driver *drv; | 181 | struct dsa_switch_tree *dst = ds->dst; |
184 | struct dsa_switch *ds; | 182 | struct dsa_chip_data *pd = ds->pd; |
185 | int ret; | ||
186 | char *name; | ||
187 | int i; | ||
188 | bool valid_name_found = false; | 183 | bool valid_name_found = false; |
189 | 184 | int index = ds->index; | |
190 | /* | 185 | int i, ret; |
191 | * Probe for switch model. | ||
192 | */ | ||
193 | drv = dsa_switch_probe(host_dev, pd->sw_addr, &name); | ||
194 | if (drv == NULL) { | ||
195 | netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n", | ||
196 | index); | ||
197 | return ERR_PTR(-EINVAL); | ||
198 | } | ||
199 | netdev_info(dst->master_netdev, "[%d]: detected a %s switch\n", | ||
200 | index, name); | ||
201 | |||
202 | |||
203 | /* | ||
204 | * Allocate and initialise switch state. | ||
205 | */ | ||
206 | ds = kzalloc(sizeof(*ds) + drv->priv_size, GFP_KERNEL); | ||
207 | if (ds == NULL) | ||
208 | return ERR_PTR(-ENOMEM); | ||
209 | |||
210 | ds->dst = dst; | ||
211 | ds->index = index; | ||
212 | ds->pd = dst->pd->chip + index; | ||
213 | ds->drv = drv; | ||
214 | ds->master_dev = host_dev; | ||
215 | 186 | ||
216 | /* | 187 | /* |
217 | * Validate supplied switch configuration. | 188 | * Validate supplied switch configuration. |
@@ -350,13 +321,56 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index, | |||
350 | } | 321 | } |
351 | #endif /* CONFIG_NET_DSA_HWMON */ | 322 | #endif /* CONFIG_NET_DSA_HWMON */ |
352 | 323 | ||
353 | return ds; | 324 | return ret; |
354 | 325 | ||
355 | out_free: | 326 | out_free: |
356 | mdiobus_free(ds->slave_mii_bus); | 327 | mdiobus_free(ds->slave_mii_bus); |
357 | out: | 328 | out: |
358 | kfree(ds); | 329 | kfree(ds); |
359 | return ERR_PTR(ret); | 330 | return ret; |
331 | } | ||
332 | |||
333 | static struct dsa_switch * | ||
334 | dsa_switch_setup(struct dsa_switch_tree *dst, int index, | ||
335 | struct device *parent, struct device *host_dev) | ||
336 | { | ||
337 | struct dsa_chip_data *pd = dst->pd->chip + index; | ||
338 | struct dsa_switch_driver *drv; | ||
339 | struct dsa_switch *ds; | ||
340 | int ret; | ||
341 | char *name; | ||
342 | |||
343 | /* | ||
344 | * Probe for switch model. | ||
345 | */ | ||
346 | drv = dsa_switch_probe(host_dev, pd->sw_addr, &name); | ||
347 | if (drv == NULL) { | ||
348 | netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n", | ||
349 | index); | ||
350 | return ERR_PTR(-EINVAL); | ||
351 | } | ||
352 | netdev_info(dst->master_netdev, "[%d]: detected a %s switch\n", | ||
353 | index, name); | ||
354 | |||
355 | |||
356 | /* | ||
357 | * Allocate and initialise switch state. | ||
358 | */ | ||
359 | ds = kzalloc(sizeof(*ds) + drv->priv_size, GFP_KERNEL); | ||
360 | if (ds == NULL) | ||
361 | return NULL; | ||
362 | |||
363 | ds->dst = dst; | ||
364 | ds->index = index; | ||
365 | ds->pd = pd; | ||
366 | ds->drv = drv; | ||
367 | ds->master_dev = host_dev; | ||
368 | |||
369 | ret = dsa_switch_setup_one(ds, parent); | ||
370 | if (ret) | ||
371 | return NULL; | ||
372 | |||
373 | return ds; | ||
360 | } | 374 | } |
361 | 375 | ||
362 | static void dsa_switch_destroy(struct dsa_switch *ds) | 376 | static void dsa_switch_destroy(struct dsa_switch *ds) |