shithub: riscv

Download patch

ref: 61a8b5c8037a78843815eccc225487b27b1547a7
parent: 8f6173c8bd347defffeafe1526e0bc5bca36c492
author: aiju <[email protected]>
date: Tue Jul 19 14:56:41 EDT 2011

fixed memory leak in bcm driver

--- a/sys/src/9/pc/etherbcm.c
+++ b/sys/src/9/pc/etherbcm.c
@@ -326,18 +326,20 @@
 }
 
 static void
-bcmtransclean(Ether *edev)
+bcmtransclean(Ether *edev, int dolock)
 {
 	Ctlr *ctlr;
 	
 	ctlr = edev->ctlr;
-	ilock(&ctlr->txlock);
+	if(dolock)
+		ilock(&ctlr->txlock);
 	while(ctlr->sendcleani != (ctlr->status[4] >> 16)) {
-		freeb(ctlr->sends[ctlr->sendri]);
-		ctlr->sends[ctlr->sendri] = 0;
+		freeb(ctlr->sends[ctlr->sendcleani]);
+		ctlr->sends[ctlr->sendcleani] = 0;
 		ctlr->sendcleani = (ctlr->sendcleani + 1) & (SendRingLen - 1);
 	}
-	iunlock(&ctlr->txlock);
+	if(dolock)
+		iunlock(&ctlr->txlock);
 }
 
 static void
@@ -356,6 +358,11 @@
 			print("bcm: send queue full\n");
 			break;
 		}
+		if(incr == ctlr->sendcleani) {
+			bcmtransclean(edev, 0);
+			if(incr == ctlr->sendcleani)
+				break;
+		}
 		bp = qget(edev->oq);
 		if(bp == nil) break;
 		next = ctlr->sendr + ctlr->sendri * 4;
@@ -414,7 +421,7 @@
 	if(status & LinkStateChange) checklink(edev);
 //	print("bcm: interrupt %8ulx %8ulx\n", ctlr->status[2], ctlr->status[4]);
 	bcmreceive(edev);
-	bcmtransclean(edev);
+	bcmtransclean(edev, 1);
 	bcmtransmit(edev);
 	csr32(ctlr, InterruptMailbox) = tag << 24;
 	iunlock(&ctlr->imlock);