Browse Source

stopped memory leak in natsemi::nat_open()

tags/v0.9.3
Udayan Kumar 17 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,7 +49,8 @@
49 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 54
 		      	      	     Added a circular buffer for transmit and receive.
54 55
 		                     transmit routine will not wait for transmission to finish.
55 56
 			             poll routine deals with it.
@@ -366,10 +367,9 @@ static int nat_open ( struct net_device *netdev ) {
366 367
 	 */
367 368
 	nat->rx_cur=0;
368 369
 	for (i=0;i<NUM_RX_DESC;i++) {
369
-
370 370
 		nat->iobuf[i] = alloc_iob ( RX_BUF_SIZE );
371 371
 		if (!nat->iobuf[i])
372
-		       return -ENOMEM;	
372
+			goto memory_alloc_err;
373 373
 		nat->rx[i].link   = virt_to_bus((i+1 < NUM_RX_DESC) ? &nat->rx[i+1] : &nat->rx[0]);
374 374
 		nat->rx[i].cmdsts = (uint32_t) RX_BUF_SIZE;
375 375
 		nat->rx[i].bufptr = virt_to_bus(nat->iobuf[i]->data);
@@ -414,8 +414,18 @@ static int nat_open ( struct net_device *netdev ) {
414 414
 	 */
415 415
 	outl((RxOk|RxErr|TxOk|TxErr),nat->ioaddr + IntrMask); 
416 416
 	//outl(1,nat->ioaddr +IntrEnable);
417
-
418 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,8 +436,6 @@ static int nat_open ( struct net_device *netdev ) {
426 436
 static void nat_close ( struct net_device *netdev ) {
427 437
 	struct natsemi_nic *nat = netdev->priv;
428 438
 	int i;
429
-
430
-
431 439
 	/* Reset the hardware to disable everything in one go
432 440
 	 */
433 441
 	nat_reset ( nat );
@@ -464,7 +472,7 @@ static int nat_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
464 472
 	 */
465 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 476
 	 * iob_pad ( iobuf, ETH_ZLEN ); can be used to achieve it
469 477
 	 */
470 478
 
@@ -569,9 +577,7 @@ static void nat_poll ( struct net_device *netdev, unsigned int rx_quota ) {
569 577
 		nat->rx_cur=(nat->rx_cur+1) % NUM_RX_DESC;
570 578
 		rx_status=nat->rx[nat->rx_cur].cmdsts; 
571 579
 	}
572
-
573 580
 end:
574
-
575 581
 	/* re-enable the potentially idle receive state machine 
576 582
 	 */
577 583
 	outl(RxOn, nat->ioaddr + ChipCmd);	
@@ -646,8 +652,6 @@ static int nat_probe ( struct pci_device *pci,
646 652
 		if ( ( rc = nvo_register ( &nat->nvo ) ) != 0 )
647 653
 			goto err_register_nvo;
648 654
 	}
649
-	
650
-
651 655
 	return 0;
652 656
 
653 657
 err_register_nvo:
@@ -681,7 +685,6 @@ static void nat_remove ( struct pci_device *pci ) {
681 685
 
682 686
 static struct pci_device_id natsemi_nics[] = {
683 687
 	PCI_ROM(0x100b, 0x0020, "dp83815", "DP83815"),
684
-
685 688
 };
686 689
 
687 690
 struct pci_driver natsemi_driver __pci_driver = {

Loading…
Cancel
Save