37
37
#define ETH_HEADER_OTHER 14
38
38
#define ISS_NET_TIMER_VALUE (HZ / 10)
39
39
40
-
41
- static DEFINE_SPINLOCK (devices_lock );
42
- static LIST_HEAD (devices );
43
-
44
40
/* ------------------------------------------------------------------------- */
45
41
46
42
/* We currently only support the TUNTAP transport protocol. */
@@ -70,8 +66,6 @@ struct iss_net_ops {
70
66
/* This structure contains out private information for the driver. */
71
67
72
68
struct iss_net_private {
73
- struct list_head device_list ;
74
-
75
69
spinlock_t lock ;
76
70
struct net_device * dev ;
77
71
struct platform_device pdev ;
@@ -472,23 +466,30 @@ static const struct net_device_ops iss_netdev_ops = {
472
466
.ndo_set_rx_mode = iss_net_set_multicast_list ,
473
467
};
474
468
475
- static int iss_net_configure (int index , char * init )
469
+ static void iss_net_pdev_release (struct device * dev )
470
+ {
471
+ struct platform_device * pdev = to_platform_device (dev );
472
+ struct iss_net_private * lp =
473
+ container_of (pdev , struct iss_net_private , pdev );
474
+
475
+ free_netdev (lp -> dev );
476
+ }
477
+
478
+ static void iss_net_configure (int index , char * init )
476
479
{
477
480
struct net_device * dev ;
478
481
struct iss_net_private * lp ;
479
- int err ;
480
482
481
483
dev = alloc_etherdev (sizeof (* lp ));
482
484
if (dev == NULL ) {
483
485
pr_err ("eth_configure: failed to allocate device\n" );
484
- return 1 ;
486
+ return ;
485
487
}
486
488
487
489
/* Initialize private element. */
488
490
489
491
lp = netdev_priv (dev );
490
492
* lp = (struct iss_net_private ) {
491
- .device_list = LIST_HEAD_INIT (lp -> device_list ),
492
493
.dev = dev ,
493
494
.index = index ,
494
495
};
@@ -509,25 +510,24 @@ static int iss_net_configure(int index, char *init)
509
510
if (!tuntap_probe (lp , index , init )) {
510
511
pr_err ("%s: invalid arguments. Skipping device!\n" ,
511
512
dev -> name );
512
- goto errout ;
513
+ goto err_free_netdev ;
513
514
}
514
515
515
516
pr_info ("Netdevice %d (%pM)\n" , index , dev -> dev_addr );
516
517
517
518
/* sysfs register */
518
519
519
520
if (!driver_registered ) {
520
- platform_driver_register (& iss_net_driver );
521
+ if (platform_driver_register (& iss_net_driver ))
522
+ goto err_free_netdev ;
521
523
driver_registered = 1 ;
522
524
}
523
525
524
- spin_lock (& devices_lock );
525
- list_add (& lp -> device_list , & devices );
526
- spin_unlock (& devices_lock );
527
-
528
526
lp -> pdev .id = index ;
529
527
lp -> pdev .name = DRIVER_NAME ;
530
- platform_device_register (& lp -> pdev );
528
+ lp -> pdev .dev .release = iss_net_pdev_release ;
529
+ if (platform_device_register (& lp -> pdev ))
530
+ goto err_free_netdev ;
531
531
SET_NETDEV_DEV (dev , & lp -> pdev .dev );
532
532
533
533
dev -> netdev_ops = & iss_netdev_ops ;
@@ -536,23 +536,20 @@ static int iss_net_configure(int index, char *init)
536
536
dev -> irq = -1 ;
537
537
538
538
rtnl_lock ();
539
- err = register_netdevice (dev );
540
- rtnl_unlock ();
541
-
542
- if (err ) {
539
+ if (register_netdevice (dev )) {
540
+ rtnl_unlock ();
543
541
pr_err ("%s: error registering net device!\n" , dev -> name );
544
- /* XXX: should we call ->remove() here? */
545
- free_netdev (dev );
546
- return 1 ;
542
+ platform_device_unregister (& lp -> pdev );
543
+ return ;
547
544
}
545
+ rtnl_unlock ();
548
546
549
547
timer_setup (& lp -> tl , iss_net_user_timer_expire , 0 );
550
548
551
- return 0 ;
549
+ return ;
552
550
553
- errout :
554
- /* FIXME: unregister; free, etc.. */
555
- return - EIO ;
551
+ err_free_netdev :
552
+ free_netdev (dev );
556
553
}
557
554
558
555
/* ------------------------------------------------------------------------- */
@@ -574,7 +571,7 @@ struct iss_net_init {
574
571
575
572
static int __init iss_net_setup (char * str )
576
573
{
577
- struct iss_net_private * device = NULL ;
574
+ struct iss_net_init * device = NULL ;
578
575
struct iss_net_init * new ;
579
576
struct list_head * ele ;
580
577
char * end ;
@@ -595,16 +592,12 @@ static int __init iss_net_setup(char *str)
595
592
}
596
593
str = end ;
597
594
598
- spin_lock (& devices_lock );
599
-
600
- list_for_each (ele , & devices ) {
601
- device = list_entry (ele , struct iss_net_private , device_list );
595
+ list_for_each (ele , & eth_cmd_line ) {
596
+ device = list_entry (ele , struct iss_net_init , list );
602
597
if (device -> index == n )
603
598
break ;
604
599
}
605
600
606
- spin_unlock (& devices_lock );
607
-
608
601
if (device && device -> index == n ) {
609
602
pr_err ("Device %u already configured\n" , n );
610
603
return 1 ;
0 commit comments