@@ -199,6 +199,8 @@ static struct net_device *cycx_x25_get_dev_by_lcn(struct wan_device *wandev,
199
199
static struct net_device *
200
200
cycx_x25_get_dev_by_dte_addr (struct wan_device * wandev , char * dte );
201
201
202
+ static void cycx_x25_chan_setup (struct net_device * dev );
203
+
202
204
#ifdef CYCLOMX_X25_DEBUG
203
205
static void hex_dump (char * msg , unsigned char * p , int len );
204
206
static void cycx_x25_dump_config (struct cycx_x25_config * conf );
@@ -353,6 +355,12 @@ static int cycx_wan_update(struct wan_device *wandev)
353
355
return 0 ;
354
356
}
355
357
358
+ /* callback to initialize device */
359
+ static void cycx_x25_chan_setup (struct net_device * dev )
360
+ {
361
+ dev -> init = cycx_netdevice_init ;
362
+ }
363
+
356
364
/* Create new logical channel.
357
365
* This routine is called by the router when ROUTER_IFNEW IOCTL is being
358
366
* handled.
@@ -376,11 +384,12 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev,
376
384
return - EINVAL ;
377
385
}
378
386
379
- /* allocate and initialize private data */
380
- chan = kzalloc ( sizeof ( struct cycx_x25_channel ), GFP_KERNEL );
381
- if (!chan )
387
+ dev = alloc_netdev ( sizeof ( struct cycx_x25_channel ), conf -> name ,
388
+ cycx_x25_chan_setup );
389
+ if (!dev )
382
390
return - ENOMEM ;
383
391
392
+ chan = netdev_priv (dev );
384
393
strcpy (chan -> name , conf -> name );
385
394
chan -> card = card ;
386
395
chan -> link = conf -> port ;
@@ -396,14 +405,14 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev,
396
405
if (len > WAN_ADDRESS_SZ ) {
397
406
printk (KERN_ERR "%s: %s local addr too long!\n" ,
398
407
wandev -> name , chan -> name );
399
- kfree ( chan ) ;
400
- return - EINVAL ;
408
+ err = - EINVAL ;
409
+ goto error ;
401
410
} else {
402
411
chan -> local_addr = kmalloc (len + 1 , GFP_KERNEL );
403
412
404
413
if (!chan -> local_addr ) {
405
- kfree ( chan ) ;
406
- return - ENOMEM ;
414
+ err = - ENOMEM ;
415
+ goto error ;
407
416
}
408
417
}
409
418
@@ -429,41 +438,31 @@ static int cycx_wan_new_if(struct wan_device *wandev, struct net_device *dev,
429
438
"%s: PVC %u is out of range on interface %s!\n" ,
430
439
wandev -> name , lcn , chan -> name );
431
440
err = - EINVAL ;
441
+ goto error ;
432
442
}
433
443
} else {
434
444
printk (KERN_ERR "%s: invalid media address on interface %s!\n" ,
435
445
wandev -> name , chan -> name );
436
446
err = - EINVAL ;
447
+ goto error ;
437
448
}
438
449
439
- if (err ) {
440
- kfree (chan -> local_addr );
441
- kfree (chan );
442
- return err ;
443
- }
444
-
445
- /* prepare network device data space for registration */
446
- strcpy (dev -> name , chan -> name );
447
- dev -> init = cycx_netdevice_init ;
448
- dev -> priv = chan ;
449
-
450
450
return 0 ;
451
+
452
+ error :
453
+ free_netdev (dev );
454
+ return err ;
451
455
}
452
456
453
457
/* Delete logical channel. */
454
458
static int cycx_wan_del_if (struct wan_device * wandev , struct net_device * dev )
455
459
{
456
- if (dev -> priv ) {
457
- struct cycx_x25_channel * chan = dev -> priv ;
460
+ struct cycx_x25_channel * chan = netdev_priv (dev );
458
461
459
- if (chan -> svc ) {
460
- kfree (chan -> local_addr );
461
- if (chan -> state == WAN_CONNECTED )
462
- del_timer (& chan -> timer );
463
- }
464
-
465
- kfree (chan );
466
- dev -> priv = NULL ;
462
+ if (chan -> svc ) {
463
+ kfree (chan -> local_addr );
464
+ if (chan -> state == WAN_CONNECTED )
465
+ del_timer (& chan -> timer );
467
466
}
468
467
469
468
return 0 ;
@@ -484,7 +483,7 @@ static const struct header_ops cycx_header_ops = {
484
483
* registration. */
485
484
static int cycx_netdevice_init (struct net_device * dev )
486
485
{
487
- struct cycx_x25_channel * chan = dev -> priv ;
486
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
488
487
struct cycx_device * card = chan -> card ;
489
488
struct wan_device * wandev = & card -> wandev ;
490
489
@@ -542,7 +541,7 @@ static int cycx_netdevice_open(struct net_device *dev)
542
541
* o if there's no more open channels then disconnect physical link. */
543
542
static int cycx_netdevice_stop (struct net_device * dev )
544
543
{
545
- struct cycx_x25_channel * chan = dev -> priv ;
544
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
546
545
547
546
netif_stop_queue (dev );
548
547
@@ -596,7 +595,7 @@ static int cycx_netdevice_rebuild_header(struct sk_buff *skb)
596
595
static int cycx_netdevice_hard_start_xmit (struct sk_buff * skb ,
597
596
struct net_device * dev )
598
597
{
599
- struct cycx_x25_channel * chan = dev -> priv ;
598
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
600
599
struct cycx_device * card = chan -> card ;
601
600
602
601
if (!chan -> svc )
@@ -670,7 +669,7 @@ static int cycx_netdevice_hard_start_xmit(struct sk_buff *skb,
670
669
* Return a pointer to struct net_device_stats */
671
670
static struct net_device_stats * cycx_netdevice_get_stats (struct net_device * dev )
672
671
{
673
- struct cycx_x25_channel * chan = dev -> priv ;
672
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
674
673
675
674
return chan ? & chan -> ifstats : NULL ;
676
675
}
@@ -783,7 +782,7 @@ static void cycx_x25_irq_rx(struct cycx_device *card, struct cycx_x25_cmd *cmd)
783
782
return ;
784
783
}
785
784
786
- chan = dev -> priv ;
785
+ chan = netdev_priv ( dev ) ;
787
786
reset_timer (dev );
788
787
789
788
if (chan -> drop_sequence ) {
@@ -883,7 +882,7 @@ static void cycx_x25_irq_connect(struct cycx_device *card,
883
882
return ;
884
883
}
885
884
886
- chan = dev -> priv ;
885
+ chan = netdev_priv ( dev ) ;
887
886
chan -> lcn = lcn ;
888
887
cycx_x25_connect_response (card , chan );
889
888
cycx_x25_set_chan_state (dev , WAN_CONNECTED );
@@ -913,7 +912,7 @@ static void cycx_x25_irq_connect_confirm(struct cycx_device *card,
913
912
}
914
913
915
914
clear_bit (-- key , (void * )& card -> u .x .connection_keys );
916
- chan = dev -> priv ;
915
+ chan = netdev_priv ( dev ) ;
917
916
chan -> lcn = lcn ;
918
917
cycx_x25_set_chan_state (dev , WAN_CONNECTED );
919
918
}
@@ -953,7 +952,7 @@ static void cycx_x25_irq_disconnect(struct cycx_device *card,
953
952
954
953
dev = cycx_x25_get_dev_by_lcn (wandev , lcn );
955
954
if (dev ) {
956
- struct cycx_x25_channel * chan = dev -> priv ;
955
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
957
956
958
957
cycx_x25_disconnect_response (card , chan -> link , lcn );
959
958
cycx_x25_set_chan_state (dev , WAN_DISCONNECTED );
@@ -1301,7 +1300,7 @@ static struct net_device *cycx_x25_get_dev_by_lcn(struct wan_device *wandev,
1301
1300
struct cycx_x25_channel * chan ;
1302
1301
1303
1302
while (dev ) {
1304
- chan = ( struct cycx_x25_channel * ) dev -> priv ;
1303
+ chan = netdev_priv ( dev ) ;
1305
1304
1306
1305
if (chan -> lcn == lcn )
1307
1306
break ;
@@ -1318,7 +1317,7 @@ static struct net_device *
1318
1317
struct cycx_x25_channel * chan ;
1319
1318
1320
1319
while (dev ) {
1321
- chan = ( struct cycx_x25_channel * ) dev -> priv ;
1320
+ chan = netdev_priv ( dev ) ;
1322
1321
1323
1322
if (!strcmp (chan -> addr , dte ))
1324
1323
break ;
@@ -1336,7 +1335,7 @@ static struct net_device *
1336
1335
* <0 failure */
1337
1336
static int cycx_x25_chan_connect (struct net_device * dev )
1338
1337
{
1339
- struct cycx_x25_channel * chan = dev -> priv ;
1338
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
1340
1339
struct cycx_device * card = chan -> card ;
1341
1340
1342
1341
if (chan -> svc ) {
@@ -1361,7 +1360,7 @@ static int cycx_x25_chan_connect(struct net_device *dev)
1361
1360
* o if SVC then clear X.25 call */
1362
1361
static void cycx_x25_chan_disconnect (struct net_device * dev )
1363
1362
{
1364
- struct cycx_x25_channel * chan = dev -> priv ;
1363
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
1365
1364
1366
1365
if (chan -> svc ) {
1367
1366
x25_clear_call (chan -> card , chan -> link , chan -> lcn , 0 , 0 );
@@ -1374,7 +1373,7 @@ static void cycx_x25_chan_disconnect(struct net_device *dev)
1374
1373
static void cycx_x25_chan_timer (unsigned long d )
1375
1374
{
1376
1375
struct net_device * dev = (struct net_device * )d ;
1377
- struct cycx_x25_channel * chan = dev -> priv ;
1376
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
1378
1377
1379
1378
if (chan -> state == WAN_CONNECTED )
1380
1379
cycx_x25_chan_disconnect (dev );
@@ -1386,7 +1385,7 @@ static void cycx_x25_chan_timer(unsigned long d)
1386
1385
/* Set logical channel state. */
1387
1386
static void cycx_x25_set_chan_state (struct net_device * dev , u8 state )
1388
1387
{
1389
- struct cycx_x25_channel * chan = dev -> priv ;
1388
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
1390
1389
struct cycx_device * card = chan -> card ;
1391
1390
unsigned long flags ;
1392
1391
char * string_state = NULL ;
@@ -1452,7 +1451,7 @@ static void cycx_x25_set_chan_state(struct net_device *dev, u8 state)
1452
1451
* to the router. */
1453
1452
static int cycx_x25_chan_send (struct net_device * dev , struct sk_buff * skb )
1454
1453
{
1455
- struct cycx_x25_channel * chan = dev -> priv ;
1454
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
1456
1455
struct cycx_device * card = chan -> card ;
1457
1456
int bitm = 0 ; /* final packet */
1458
1457
unsigned len = skb -> len ;
@@ -1545,7 +1544,7 @@ static unsigned dec_to_uint(u8 *str, int len)
1545
1544
1546
1545
static void reset_timer (struct net_device * dev )
1547
1546
{
1548
- struct cycx_x25_channel * chan = dev -> priv ;
1547
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
1549
1548
1550
1549
if (chan -> svc )
1551
1550
mod_timer (& chan -> timer , jiffies + chan -> idle_tmout * HZ );
@@ -1598,7 +1597,7 @@ static void cycx_x25_dump_devs(struct wan_device *wandev)
1598
1597
printk (KERN_INFO "---------------------------------------\n" );
1599
1598
1600
1599
while (dev ) {
1601
- struct cycx_x25_channel * chan = dev -> priv ;
1600
+ struct cycx_x25_channel * chan = netdev_priv ( dev ) ;
1602
1601
1603
1602
printk (KERN_INFO "%-5.5s %-15.15s %d ETH_P_%s\n" ,
1604
1603
chan -> name , chan -> addr , netif_queue_stopped (dev ),
0 commit comments