Commit 8c8408358f19a386298744829bf67b90c129ff18
Committed by
Linus Torvalds
1 parent
e024715f5f
Exists in
master
and in
20 other branches
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>
Showing 1 changed file with 13 additions and 12 deletions Side-by-side Diff
arch/um/drivers/net_kern.c
... | ... | @@ -348,17 +348,24 @@ |
348 | 348 | struct net_device *dev; |
349 | 349 | struct uml_net_private *lp; |
350 | 350 | int save, err, size; |
351 | - char name[sizeof(dev->name)]; | |
352 | 351 | |
353 | 352 | size = transport->private_size + sizeof(struct uml_net_private) + |
354 | 353 | sizeof(((struct uml_net_private *) 0)->user); |
355 | 354 | |
356 | 355 | device = kzalloc(sizeof(*device), GFP_KERNEL); |
357 | 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 | 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 | 369 | INIT_LIST_HEAD(&device->list); |
363 | 370 | device->index = n; |
364 | 371 | |
365 | 372 | |
... | ... | @@ -366,9 +373,9 @@ |
366 | 373 | * netdevice, that is OK, register_netdev{,ice}() will notice this |
367 | 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 | 380 | printk(KERN_INFO "Netdevice %d ", n); |
374 | 381 | printk("(%02x:%02x:%02x:%02x:%02x:%02x) ", |
... | ... | @@ -376,11 +383,6 @@ |
376 | 383 | device->mac[2], device->mac[3], |
377 | 384 | device->mac[4], device->mac[5]); |
378 | 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 | 387 | lp = dev->priv; |
386 | 388 | /* This points to the transport private data. It's still clear, but we |
... | ... | @@ -399,7 +401,6 @@ |
399 | 401 | goto out_free_netdev; |
400 | 402 | SET_NETDEV_DEV(dev,&device->pdev.dev); |
401 | 403 | |
402 | - strcpy(dev->name, name); | |
403 | 404 | device->dev = dev; |
404 | 405 | |
405 | 406 | /* |
406 | 407 | |
... | ... | @@ -466,13 +467,13 @@ |
466 | 467 | return; |
467 | 468 | |
468 | 469 | out_undo_user_init: |
469 | - if (transport->user->init != NULL) | |
470 | + if (transport->user->remove != NULL) | |
470 | 471 | (*transport->user->remove)(&lp->user); |
471 | 472 | out_unregister: |
472 | 473 | platform_device_unregister(&device->pdev); |
473 | 474 | out_free_netdev: |
474 | 475 | free_netdev(dev); |
475 | -out_free_device: ; | |
476 | +out_free_device: | |
476 | 477 | kfree(device); |
477 | 478 | } |
478 | 479 |