diff options
author | Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> | 2007-05-06 17:51:14 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-07 15:13:02 -0400 |
commit | 8c8408358f19a386298744829bf67b90c129ff18 (patch) | |
tree | dd2b57ba36e912b4d586678324758afddc236fee | |
parent | e024715f5f6250179a31716a898800a48cf23b39 (diff) |
uml: Eliminate temporary buffer in eth_configure
Avoid using the temporary buffer introduced by previous patch to hold the
device name.
Btw, avoid leaking device on an error path. Other error paths may need
cleanup.
Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/um/drivers/net_kern.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c index cd466e30af67..3f5e8e634308 100644 --- a/arch/um/drivers/net_kern.c +++ b/arch/um/drivers/net_kern.c | |||
@@ -348,17 +348,24 @@ static void eth_configure(int n, void *init, char *mac, | |||
348 | struct net_device *dev; | 348 | struct net_device *dev; |
349 | struct uml_net_private *lp; | 349 | struct uml_net_private *lp; |
350 | int save, err, size; | 350 | int save, err, size; |
351 | char name[sizeof(dev->name)]; | ||
352 | 351 | ||
353 | size = transport->private_size + sizeof(struct uml_net_private) + | 352 | size = transport->private_size + sizeof(struct uml_net_private) + |
354 | sizeof(((struct uml_net_private *) 0)->user); | 353 | sizeof(((struct uml_net_private *) 0)->user); |
355 | 354 | ||
356 | device = kzalloc(sizeof(*device), GFP_KERNEL); | 355 | device = kzalloc(sizeof(*device), GFP_KERNEL); |
357 | if (device == NULL) { | 356 | if (device == NULL) { |
358 | printk(KERN_ERR "eth_configure failed to allocate uml_net\n"); | 357 | printk(KERN_ERR "eth_configure failed to allocate struct " |
358 | "uml_net\n"); | ||
359 | return; | 359 | return; |
360 | } | 360 | } |
361 | 361 | ||
362 | dev = alloc_etherdev(size); | ||
363 | if (dev == NULL) { | ||
364 | printk(KERN_ERR "eth_configure: failed to allocate struct " | ||
365 | "net_device for eth%d\n", n); | ||
366 | goto out_free_device; | ||
367 | } | ||
368 | |||
362 | INIT_LIST_HEAD(&device->list); | 369 | INIT_LIST_HEAD(&device->list); |
363 | device->index = n; | 370 | device->index = n; |
364 | 371 | ||
@@ -366,9 +373,9 @@ static void eth_configure(int n, void *init, char *mac, | |||
366 | * netdevice, that is OK, register_netdev{,ice}() will notice this | 373 | * netdevice, that is OK, register_netdev{,ice}() will notice this |
367 | * and fail. | 374 | * and fail. |
368 | */ | 375 | */ |
369 | snprintf(name, sizeof(name), "eth%d", n); | 376 | snprintf(dev->name, sizeof(dev->name), "eth%d", n); |
370 | 377 | ||
371 | setup_etheraddr(mac, device->mac, name); | 378 | setup_etheraddr(mac, device->mac, dev->name); |
372 | 379 | ||
373 | printk(KERN_INFO "Netdevice %d ", n); | 380 | printk(KERN_INFO "Netdevice %d ", n); |
374 | printk("(%02x:%02x:%02x:%02x:%02x:%02x) ", | 381 | printk("(%02x:%02x:%02x:%02x:%02x:%02x) ", |
@@ -376,11 +383,6 @@ static void eth_configure(int n, void *init, char *mac, | |||
376 | device->mac[2], device->mac[3], | 383 | device->mac[2], device->mac[3], |
377 | device->mac[4], device->mac[5]); | 384 | device->mac[4], device->mac[5]); |
378 | printk(": "); | 385 | printk(": "); |
379 | dev = alloc_etherdev(size); | ||
380 | if (dev == NULL) { | ||
381 | printk(KERN_ERR "eth_configure: failed to allocate device\n"); | ||
382 | goto out_free_device; | ||
383 | } | ||
384 | 386 | ||
385 | lp = dev->priv; | 387 | lp = dev->priv; |
386 | /* This points to the transport private data. It's still clear, but we | 388 | /* This points to the transport private data. It's still clear, but we |
@@ -399,7 +401,6 @@ static void eth_configure(int n, void *init, char *mac, | |||
399 | goto out_free_netdev; | 401 | goto out_free_netdev; |
400 | SET_NETDEV_DEV(dev,&device->pdev.dev); | 402 | SET_NETDEV_DEV(dev,&device->pdev.dev); |
401 | 403 | ||
402 | strcpy(dev->name, name); | ||
403 | device->dev = dev; | 404 | device->dev = dev; |
404 | 405 | ||
405 | /* | 406 | /* |
@@ -466,13 +467,13 @@ static void eth_configure(int n, void *init, char *mac, | |||
466 | return; | 467 | return; |
467 | 468 | ||
468 | out_undo_user_init: | 469 | out_undo_user_init: |
469 | if (transport->user->init != NULL) | 470 | if (transport->user->remove != NULL) |
470 | (*transport->user->remove)(&lp->user); | 471 | (*transport->user->remove)(&lp->user); |
471 | out_unregister: | 472 | out_unregister: |
472 | platform_device_unregister(&device->pdev); | 473 | platform_device_unregister(&device->pdev); |
473 | out_free_netdev: | 474 | out_free_netdev: |
474 | free_netdev(dev); | 475 | free_netdev(dev); |
475 | out_free_device: ; | 476 | out_free_device: |
476 | kfree(device); | 477 | kfree(device); |
477 | } | 478 | } |
478 | 479 | ||