ref: d19bb4037402c8e0e352a271b5a6dd8281112559
parent: c7893567d09c576ed2a676bec431ef630c29c6d5
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Wed May 23 14:30:34 EDT 2012
ethervt610xx: dont assume sizeof(Ds) <= cls
--- a/sys/src/9/pc/ethervt6102.c
+++ b/sys/src/9/pc/ethervt6102.c
@@ -468,7 +468,7 @@
static void
vt6102attach(Ether* edev)
{- int i;
+ int dsz, i;
Ctlr *ctlr;
Ds *ds, *prev;
uchar *alloc, *bounce;
@@ -488,13 +488,13 @@
*/
ctlr->nrd = Nrd;
ctlr->ntd = Ntd;
- alloc = malloc((ctlr->nrd+ctlr->ntd)*ctlr->cls + ctlr->ntd*Txcopy + ctlr->cls-1);
+ dsz = ROUNDUP(sizeof(Ds), ctlr->cls);
+ alloc = mallocalign((ctlr->nrd+ctlr->ntd)*dsz + ctlr->ntd*Txcopy, dsz, 0, 0);
if(alloc == nil){qunlock(&ctlr->alock);
error(Enomem);
}
ctlr->alloc = alloc;
- alloc = (uchar*)ROUNDUP((ulong)alloc, ctlr->cls);
ctlr->rd = (Ds*)alloc;
@@ -517,7 +517,7 @@
prev = ctlr->rd + ctlr->nrd-1;
for(i = 0; i < ctlr->nrd; i++){ds = (Ds*)alloc;
- alloc += ctlr->cls;
+ alloc += dsz;
ds->control = Rdbsz;
ds->branch = PCIWADDR(alloc);
@@ -541,10 +541,10 @@
ctlr->td = (Ds*)alloc;
prev = ctlr->td + ctlr->ntd-1;
- bounce = alloc + ctlr->ntd*ctlr->cls;
+ bounce = alloc + ctlr->ntd*dsz;
for(i = 0; i < ctlr->ntd; i++){ds = (Ds*)alloc;
- alloc += ctlr->cls;
+ alloc += dsz;
ds->bounce = bounce;
bounce += Txcopy;
@@ -978,12 +978,6 @@
if((cls = pcicfgr8(p, PciCLS)) == 0 || cls == 0xFF)
cls = 0x10;
ctlr->cls = cls*4;
- if(ctlr->cls < sizeof(Ds)){- print("vt6102: cls %d < sizeof(Ds)\n", ctlr->cls);- iofree(port);
- free(ctlr);
- continue;
- }
ctlr->tft = Ctft64;
if(vt6102reset(ctlr)){--- a/sys/src/9/pc/ethervt6105m.c
+++ b/sys/src/9/pc/ethervt6105m.c
@@ -610,7 +610,6 @@
vt6105Mattach(Ether* edev)
{Ctlr *ctlr;
-// MiiPhy *phy;
uchar *alloc;
Ds *ds, *prev;
int dsz, i, timeo;
@@ -1142,12 +1141,6 @@
if((cls = pcicfgr8(p, PciCLS)) == 0 || cls == 0xFF)
cls = 0x10;
ctlr->cls = cls*4;
- if(ctlr->cls < sizeof(Ds)){- print("vt6105M: cls %d < sizeof(Ds)\n", ctlr->cls);- iofree(port);
- free(ctlr);
- continue;
- }
ctlr->tft = CtftSAF;
if(vt6105Mreset(ctlr)){--
⑨