[ROSE]: check rose_ndevs earlier

* Don't bother with proto registering if rose_ndevs is bad.
* Make escape structure more coherent.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Alexey Dobriyan and committed by David S. Miller a83cd2cc 70ff3b66

+11 -9
+11 -9
net/rose/af_rose.c
··· 1472 1472 static int __init rose_proto_init(void) 1473 1473 { 1474 1474 int i; 1475 - int rc = proto_register(&rose_proto, 0); 1475 + int rc; 1476 1476 1477 + if (rose_ndevs > 0x7FFFFFFF/sizeof(struct net_device *)) { 1478 + printk(KERN_ERR "ROSE: rose_proto_init - rose_ndevs parameter to large\n"); 1479 + rc = -EINVAL; 1480 + goto out; 1481 + } 1482 + 1483 + rc = proto_register(&rose_proto, 0); 1477 1484 if (rc != 0) 1478 1485 goto out; 1479 1486 1480 1487 rose_callsign = null_ax25_address; 1481 1488 1482 - if (rose_ndevs > 0x7FFFFFFF/sizeof(struct net_device *)) { 1483 - printk(KERN_ERR "ROSE: rose_proto_init - rose_ndevs parameter to large\n"); 1484 - proto_unregister(&rose_proto); 1485 - return -EINVAL; 1486 - } 1487 - 1488 1489 dev_rose = kmalloc(rose_ndevs * sizeof(struct net_device *), GFP_KERNEL); 1489 1490 if (dev_rose == NULL) { 1490 1491 printk(KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n"); 1491 - proto_unregister(&rose_proto); 1492 - return -ENOMEM; 1492 + rc = -ENOMEM; 1493 + goto out_proto_unregister; 1493 1494 } 1494 1495 1495 1496 memset(dev_rose, 0x00, rose_ndevs * sizeof(struct net_device*)); ··· 1541 1540 free_netdev(dev_rose[i]); 1542 1541 } 1543 1542 kfree(dev_rose); 1543 + out_proto_unregister: 1544 1544 proto_unregister(&rose_proto); 1545 1545 goto out; 1546 1546 }