Browse Source

stopped memory leak in natsemi::nat_open()

tags/v0.9.3
Udayan Kumar 18 years ago
parent
commit
132d0fb70c
1 changed files with 15 additions and 12 deletions
  1. 15
    12
      src/drivers/net/natsemi.c

+ 15
- 12
src/drivers/net/natsemi.c View File

49
 /* Revision History */
49
 /* Revision History */
50
 
50
 
51
 /*
51
 /*
52
-  02 JUL 2007 Udayan Kumar	 1.2 ported the driver from etherboot to gPXE API
52
+  02 JUL 2007 Udayan Kumar	 1.2 ported the driver from etherboot to gPXE API.
53
+				     Fully rewritten,adapting the old driver.
53
 		      	      	     Added a circular buffer for transmit and receive.
54
 		      	      	     Added a circular buffer for transmit and receive.
54
 		                     transmit routine will not wait for transmission to finish.
55
 		                     transmit routine will not wait for transmission to finish.
55
 			             poll routine deals with it.
56
 			             poll routine deals with it.
366
 	 */
367
 	 */
367
 	nat->rx_cur=0;
368
 	nat->rx_cur=0;
368
 	for (i=0;i<NUM_RX_DESC;i++) {
369
 	for (i=0;i<NUM_RX_DESC;i++) {
369
-
370
 		nat->iobuf[i] = alloc_iob ( RX_BUF_SIZE );
370
 		nat->iobuf[i] = alloc_iob ( RX_BUF_SIZE );
371
 		if (!nat->iobuf[i])
371
 		if (!nat->iobuf[i])
372
-		       return -ENOMEM;	
372
+			goto memory_alloc_err;
373
 		nat->rx[i].link   = virt_to_bus((i+1 < NUM_RX_DESC) ? &nat->rx[i+1] : &nat->rx[0]);
373
 		nat->rx[i].link   = virt_to_bus((i+1 < NUM_RX_DESC) ? &nat->rx[i+1] : &nat->rx[0]);
374
 		nat->rx[i].cmdsts = (uint32_t) RX_BUF_SIZE;
374
 		nat->rx[i].cmdsts = (uint32_t) RX_BUF_SIZE;
375
 		nat->rx[i].bufptr = virt_to_bus(nat->iobuf[i]->data);
375
 		nat->rx[i].bufptr = virt_to_bus(nat->iobuf[i]->data);
414
 	 */
414
 	 */
415
 	outl((RxOk|RxErr|TxOk|TxErr),nat->ioaddr + IntrMask); 
415
 	outl((RxOk|RxErr|TxOk|TxErr),nat->ioaddr + IntrMask); 
416
 	//outl(1,nat->ioaddr +IntrEnable);
416
 	//outl(1,nat->ioaddr +IntrEnable);
417
-
418
 	return 0;
417
 	return 0;
418
+		       
419
+memory_alloc_err:
420
+	/* this block frees the previously allocated buffers
421
+	 * if memory for all the buffers is not available
422
+	 */
423
+	i=0;
424
+	while(nat->rx[i].cmdsts == (uint32_t) RX_BUF_SIZE) {
425
+		free_iob(nat->iobuf[i]);
426
+		i++;
427
+	}
428
+	return -ENOMEM;	
419
 }
429
 }
420
 
430
 
421
 /**
431
 /**
426
 static void nat_close ( struct net_device *netdev ) {
436
 static void nat_close ( struct net_device *netdev ) {
427
 	struct natsemi_nic *nat = netdev->priv;
437
 	struct natsemi_nic *nat = netdev->priv;
428
 	int i;
438
 	int i;
429
-
430
-
431
 	/* Reset the hardware to disable everything in one go
439
 	/* Reset the hardware to disable everything in one go
432
 	 */
440
 	 */
433
 	nat_reset ( nat );
441
 	nat_reset ( nat );
464
 	 */
472
 	 */
465
 	nat->tx_iobuf[nat->tx_cur]=iobuf;
473
 	nat->tx_iobuf[nat->tx_cur]=iobuf;
466
 
474
 
467
-	/* Pad and align packet has been ignored because its not required here
475
+	/* Pad and align packet has not been used because its not required here
468
 	 * iob_pad ( iobuf, ETH_ZLEN ); can be used to achieve it
476
 	 * iob_pad ( iobuf, ETH_ZLEN ); can be used to achieve it
469
 	 */
477
 	 */
470
 
478
 
569
 		nat->rx_cur=(nat->rx_cur+1) % NUM_RX_DESC;
577
 		nat->rx_cur=(nat->rx_cur+1) % NUM_RX_DESC;
570
 		rx_status=nat->rx[nat->rx_cur].cmdsts; 
578
 		rx_status=nat->rx[nat->rx_cur].cmdsts; 
571
 	}
579
 	}
572
-
573
 end:
580
 end:
574
-
575
 	/* re-enable the potentially idle receive state machine 
581
 	/* re-enable the potentially idle receive state machine 
576
 	 */
582
 	 */
577
 	outl(RxOn, nat->ioaddr + ChipCmd);	
583
 	outl(RxOn, nat->ioaddr + ChipCmd);	
646
 		if ( ( rc = nvo_register ( &nat->nvo ) ) != 0 )
652
 		if ( ( rc = nvo_register ( &nat->nvo ) ) != 0 )
647
 			goto err_register_nvo;
653
 			goto err_register_nvo;
648
 	}
654
 	}
649
-	
650
-
651
 	return 0;
655
 	return 0;
652
 
656
 
653
 err_register_nvo:
657
 err_register_nvo:
681
 
685
 
682
 static struct pci_device_id natsemi_nics[] = {
686
 static struct pci_device_id natsemi_nics[] = {
683
 	PCI_ROM(0x100b, 0x0020, "dp83815", "DP83815"),
687
 	PCI_ROM(0x100b, 0x0020, "dp83815", "DP83815"),
684
-
685
 };
688
 };
686
 
689
 
687
 struct pci_driver natsemi_driver __pci_driver = {
690
 struct pci_driver natsemi_driver __pci_driver = {

Loading…
Cancel
Save