kernel: fix inproper use of malloc/smalloc
This commit is contained in:
parent
589f99915e
commit
bf3476d661
|
@ -871,7 +871,7 @@ archctlread(Chan*, void *a, long nn, vlong offset)
|
|||
int n;
|
||||
char *buf, *p, *ep;
|
||||
|
||||
p = buf = malloc(READSTR);
|
||||
p = buf = smalloc(READSTR);
|
||||
ep = p + READSTR;
|
||||
p = seprint(p, ep, "cpu %s %lud%s\n",
|
||||
cputype->name, (ulong)(m->cpuhz+999999)/1000000,
|
||||
|
|
|
@ -765,7 +765,7 @@ i82365read(Chan *c, void *a, long n, vlong off)
|
|||
case Qattr:
|
||||
return pcmread(SLOTNO(c), TYPE(c) == Qattr, a, n, off);
|
||||
case Qctl:
|
||||
buf = p = malloc(READSTR);
|
||||
buf = p = smalloc(READSTR);
|
||||
e = p + READSTR;
|
||||
pp = slot + SLOTNO(c);
|
||||
|
||||
|
|
|
@ -1292,7 +1292,7 @@ pccardread(Chan *c, void *a, long n, vlong offset)
|
|||
return devdirread(c, a, n, 0, 0, pccardgen);
|
||||
|
||||
case Qctl:
|
||||
buf = p = malloc(READSTR);
|
||||
buf = p = smalloc(READSTR);
|
||||
buf[0] = 0;
|
||||
e = p + READSTR;
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ vgaread(Chan* c, void* a, long n, vlong off)
|
|||
case Qvgactl:
|
||||
scr = &vgascreen[0];
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
if(waserror()){
|
||||
free(p);
|
||||
nexterror();
|
||||
|
|
|
@ -322,7 +322,7 @@ ifstat(Ether* ether, void* a, long n, ulong offset)
|
|||
if(n == 0)
|
||||
return 0;
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
l = snprint(p, READSTR, "Overflow: %lud\n", ctlr->of);
|
||||
l += snprint(p+l, READSTR-l, "Ru: %lud\n", ctlr->ru);
|
||||
l += snprint(p+l, READSTR-l, "Rps: %lud\n", ctlr->rps);
|
||||
|
|
|
@ -204,7 +204,7 @@ ifstat(Ether* ether, void* a, long n, ulong offset)
|
|||
if(n == 0)
|
||||
return 0;
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
len = snprint(p, READSTR, "Rxbuff: %ld\n", ctlr->rxbuff);
|
||||
len += snprint(p+len, READSTR-len, "Crc: %ld\n", ctlr->crc);
|
||||
len += snprint(p+len, READSTR-len, "Oflo: %ld\n", ctlr->oflo);
|
||||
|
|
|
@ -310,7 +310,7 @@ rtl8139ifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
Ctlr *ctlr;
|
||||
|
||||
ctlr = edev->ctlr;
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
l = snprint(p, READSTR, "rcr %#8.8ux\n", ctlr->rcr);
|
||||
l += snprint(p+l, READSTR-l, "multicast %ud\n", ctlr->mcast);
|
||||
l += snprint(p+l, READSTR-l, "ierrs %d\n", ctlr->ierrs);
|
||||
|
|
|
@ -494,10 +494,11 @@ rtl8169ifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
Dtcc *dtcc;
|
||||
int i, l, r, timeo;
|
||||
|
||||
p = smalloc(READSTR);
|
||||
|
||||
ctlr = edev->ctlr;
|
||||
qlock(&ctlr->slock);
|
||||
|
||||
p = nil;
|
||||
if(waserror()){
|
||||
qunlock(&ctlr->slock);
|
||||
free(p);
|
||||
|
@ -524,12 +525,10 @@ rtl8169ifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
if(n == 0){
|
||||
qunlock(&ctlr->slock);
|
||||
poperror();
|
||||
free(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((p = malloc(READSTR)) == nil)
|
||||
error(Enomem);
|
||||
|
||||
l = snprint(p, READSTR, "TxOk: %llud\n", dtcc->txok);
|
||||
l += snprint(p+l, READSTR-l, "RxOk: %llud\n", dtcc->rxok);
|
||||
l += snprint(p+l, READSTR-l, "TxEr: %llud\n", dtcc->txer);
|
||||
|
|
|
@ -504,9 +504,10 @@ gc82543ifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
int i, l, r;
|
||||
uvlong tuvl, ruvl;
|
||||
|
||||
p = smalloc(READSTR);
|
||||
|
||||
ctlr = edev->ctlr;
|
||||
lock(&ctlr->slock);
|
||||
p = malloc(READSTR);
|
||||
l = 0;
|
||||
for(i = 0; i < Nstatistics; i++){
|
||||
r = csr32r(ctlr, Statistics+i*4);
|
||||
|
|
|
@ -434,7 +434,7 @@ ifstat(Ether* ether, void* a, long n, ulong offset)
|
|||
memmove(dump, ctlr->dump, sizeof(dump));
|
||||
unlock(&ctlr->dlock);
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
len = snprint(p, READSTR, "transmit good frames: %lud\n", dump[0]);
|
||||
len += snprint(p+len, READSTR-len, "transmit maximum collisions errors: %lud\n", dump[1]);
|
||||
len += snprint(p+len, READSTR-len, "transmit late collisions errors: %lud\n", dump[2]);
|
||||
|
|
|
@ -647,10 +647,11 @@ i82563ifstat(Ether *edev, void *a, long n, ulong offset)
|
|||
Ctlr *ctlr;
|
||||
Rbpool *b;
|
||||
|
||||
p = s = smalloc(READSTR);
|
||||
e = p + READSTR;
|
||||
|
||||
ctlr = edev->ctlr;
|
||||
qlock(&ctlr->slock);
|
||||
p = s = malloc(READSTR);
|
||||
e = p + READSTR;
|
||||
|
||||
for(i = 0; i < Nstatistics; i++){
|
||||
r = csr32r(ctlr, Statistics + i*4);
|
||||
|
|
|
@ -336,10 +336,10 @@ ifstat(Ether *e, void *a, long n, ulong offset)
|
|||
char *s, *p, *q;
|
||||
Ctlr *c;
|
||||
|
||||
c = e->ctlr;
|
||||
p = s = malloc(READSTR);
|
||||
p = s = smalloc(READSTR);
|
||||
q = p + READSTR;
|
||||
|
||||
c = e->ctlr;
|
||||
readstats(c);
|
||||
for(i = 0; i < nelem(stattab); i++)
|
||||
if(c->stats[i] > 0)
|
||||
|
|
|
@ -360,7 +360,7 @@ ifstat(Ether* ether, void* a, long n, ulong offset)
|
|||
if(n == 0)
|
||||
return 0;
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
l = snprint(p, READSTR, "Rxa: %lud\n", ctlr->rxa);
|
||||
l += snprint(p+l, READSTR-l, "Rxo: %lud\n", ctlr->rxo);
|
||||
l += snprint(p+l, READSTR-l, "Rlong: %lud\n", ctlr->rlong);
|
||||
|
|
|
@ -920,7 +920,7 @@ dp83820ifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
if(n == 0)
|
||||
return 0;
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
l = 0;
|
||||
for(i = 0; i < Nmibd; i++){
|
||||
r = csr32r(ctlr, Mibd+(i*sizeof(int)));
|
||||
|
|
|
@ -1174,7 +1174,7 @@ ifstat(Ether* ether, void* a, long n, ulong offset)
|
|||
statistics(ether);
|
||||
iunlock(&ctlr->wlock);
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
len = snprint(p, READSTR, "interrupts: %lud\n", ctlr->interrupts);
|
||||
len += snprint(p+len, READSTR-len, "bogusinterrupts: %lud\n", ctlr->bogusinterrupts);
|
||||
len += snprint(p+len, READSTR-len, "timer: %lud %lud\n",
|
||||
|
|
|
@ -343,7 +343,7 @@ ga620ifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
|
||||
if(n == 0)
|
||||
return 0;
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
l = 0;
|
||||
for(i = 0; i < 256; i++){
|
||||
if((r = ctlr->gib->statistics[i]) == 0)
|
||||
|
@ -1173,6 +1173,10 @@ ga620pci(void)
|
|||
}
|
||||
|
||||
ctlr = malloc(sizeof(Ctlr));
|
||||
if(ctlr == nil){
|
||||
print("ga620: can't allocate memory\n");
|
||||
continue;
|
||||
}
|
||||
ctlr->port = p->mem[0].bar & ~0x0F;
|
||||
ctlr->pcidev = p;
|
||||
ctlr->id = p->did<<16 | p->vid;
|
||||
|
|
|
@ -599,10 +599,10 @@ igbeifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
int i, l, r;
|
||||
uvlong tuvl, ruvl;
|
||||
|
||||
p = smalloc(READSTR);
|
||||
l = 0;
|
||||
ctlr = edev->ctlr;
|
||||
qlock(&ctlr->slock);
|
||||
p = malloc(READSTR);
|
||||
l = 0;
|
||||
for(i = 0; i < Nstatistics; i++){
|
||||
r = csr32r(ctlr, Statistics+i*4);
|
||||
if((s = statistics[i]) == nil)
|
||||
|
@ -1965,6 +1965,10 @@ igbepci(void)
|
|||
break;
|
||||
}
|
||||
ctlr = malloc(sizeof(Ctlr));
|
||||
if(ctlr == nil){
|
||||
print("igbe: can't allocate memory\n");
|
||||
continue;
|
||||
}
|
||||
ctlr->port = p->mem[0].bar & ~0x0F;
|
||||
ctlr->pcidev = p;
|
||||
ctlr->id = (p->did<<16)|p->vid;
|
||||
|
|
|
@ -1362,19 +1362,15 @@ lstcount(Block *b)
|
|||
static long
|
||||
m10gifstat(Ether *e, void *v, long n, ulong off)
|
||||
{
|
||||
int l;
|
||||
char *p;
|
||||
Ctlr *c;
|
||||
Stats s;
|
||||
|
||||
c = e->ctlr;
|
||||
p = malloc(READSTR+1);
|
||||
l = 0;
|
||||
p = smalloc(READSTR);
|
||||
/* no point in locking this because this is done via dma. */
|
||||
memmove(&s, c->stats, sizeof s);
|
||||
|
||||
// l +=
|
||||
snprint(p+l, READSTR,
|
||||
snprint(p, READSTR,
|
||||
"txcnt = %lud\n" "linkstat = %lud\n" "dlink = %lud\n"
|
||||
"derror = %lud\n" "drunt = %lud\n" "doverrun = %lud\n"
|
||||
"dnosm = %lud\n" "dnobg = %lud\n" "nrdma = %lud\n"
|
||||
|
|
|
@ -644,7 +644,6 @@ ifstat(Ether* ether, void* a, long n, ulong offset)
|
|||
return 0;
|
||||
|
||||
ctlr = ether->ctlr;
|
||||
p = malloc(READSTR);
|
||||
|
||||
s = 0;
|
||||
if (ctlr->rev > 0) {
|
||||
|
@ -660,6 +659,7 @@ ifstat(Ether* ether, void* a, long n, ulong offset)
|
|||
}
|
||||
}
|
||||
|
||||
p = smalloc(READSTR);
|
||||
len = snprint(p, READSTR, "rev: 91c%s\n", (s) ? s : "???");
|
||||
len += snprint(p + len, READSTR - len, "rxovrn: %uld\n", ctlr->rovrn);
|
||||
len += snprint(p + len, READSTR - len, "lcar: %uld\n", ctlr->lcar);
|
||||
|
|
|
@ -401,9 +401,8 @@ vgbeifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
|
||||
ctlr = edev->ctlr;
|
||||
|
||||
p = malloc(READSTR);
|
||||
l = 0;
|
||||
l += snprint(p+l, READSTR-l, "tx: %uld\n", ctlr->stats.tx);
|
||||
p = smalloc(READSTR);
|
||||
l = snprint(p+l, READSTR-l, "tx: %uld\n", ctlr->stats.tx);
|
||||
l += snprint(p+l, READSTR-l, "tx [errs]: %uld\n", ctlr->stats.txe);
|
||||
l += snprint(p+l, READSTR-l, "rx: %uld\n", ctlr->stats.rx);
|
||||
l += snprint(p+l, READSTR-l, "intr: %uld\n", ctlr->stats.intr);
|
||||
|
|
|
@ -346,7 +346,7 @@ vt6102ifstat(Ether* edev, void* a, long n, ulong offset)
|
|||
|
||||
ctlr = edev->ctlr;
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
l = 0;
|
||||
for(i = 0; i < Nrxstats; i++){
|
||||
l += snprint(p+l, READSTR-l, "%s: %ud\n",
|
||||
|
|
|
@ -603,7 +603,7 @@ procfork(Proc *p)
|
|||
|
||||
/* copy local descriptor table */
|
||||
if(up->ldt != nil && up->nldt > 0){
|
||||
p->ldt = malloc(sizeof(Segdesc) * up->nldt);
|
||||
p->ldt = smalloc(sizeof(Segdesc) * up->nldt);
|
||||
memmove(p->ldt, up->ldt, sizeof(Segdesc) * up->nldt);
|
||||
p->nldt = up->nldt;
|
||||
}
|
||||
|
|
|
@ -88,6 +88,8 @@ mmuinit(void)
|
|||
m->pdb[PDX(VPT)] = PADDR(m->pdb)|PTEWRITE|PTEVALID;
|
||||
|
||||
m->tss = malloc(sizeof(Tss));
|
||||
if(m->tss == nil)
|
||||
panic("mmuinit: no memory for Tss");
|
||||
memset(m->tss, 0, sizeof(Tss));
|
||||
m->tss->iomap = 0xDFFF<<16;
|
||||
|
||||
|
|
|
@ -225,6 +225,8 @@ mkiointr(PCMPintr* p)
|
|||
if(memcmp(mppcmp->product, "INTEL X38MLST ", 20) == 0){
|
||||
if(p->busno == 1 && p->intin == 16 && p->irq == 1){
|
||||
pcmpintr = malloc(sizeof(PCMPintr));
|
||||
if(pcmpintr == nil)
|
||||
panic("iointr: no memory for PCMPintr");
|
||||
memmove(pcmpintr, p, sizeof(PCMPintr));
|
||||
print("mkiointr: %20.20s bus %d intin %d irq %d\n",
|
||||
(char*)mppcmp->product,
|
||||
|
|
|
@ -181,7 +181,9 @@ piix4smbus(void)
|
|||
if(p == nil)
|
||||
return nil;
|
||||
|
||||
s = smalloc(sizeof(*s));
|
||||
s = malloc(sizeof(*s));
|
||||
if(s == nil)
|
||||
panic("piix4smbus: no memory for SMBus");
|
||||
memmove(s, &smbusproto, sizeof(*s));
|
||||
s->arg = p;
|
||||
|
||||
|
|
|
@ -2551,7 +2551,11 @@ map(Pcidev *p, int bar)
|
|||
static void
|
||||
initmem(Ctlr *c)
|
||||
{
|
||||
c->fis = smalloc(0x800 + 0x100*16); /* §6.1.9.3 */
|
||||
c->fis = malloc(0x800 + 0x100*16); /* §6.1.9.3 */
|
||||
c->cl = malloc(nelem(c->cq)*sizeof *c->cl);
|
||||
c->cmdtab = malloc(Nctlrdrv*sizeof *c->cmdtab);
|
||||
if(c->fis == nil || c->cl == nil || c->cmdtab == nil)
|
||||
panic("sdodin: no memory");
|
||||
c->reg[Fisbase + 0] = PCIWADDR(c->fis);
|
||||
c->reg[Fisbase + 1] = Pciwaddrh(c->fis);
|
||||
c->reg[Cqbase + 0] = PCIWADDR(c->cq);
|
||||
|
@ -2560,10 +2564,8 @@ initmem(Ctlr *c)
|
|||
c->reg[Dqbase + 0] = PCIWADDR(c->dq);
|
||||
c->reg[Dqbase + 1] = Pciwaddrh(c->dq);
|
||||
c->reg[Dqcfg] = Dqen | nelem(c->dq);
|
||||
c->cl = smalloc(nelem(c->cq)*sizeof *c->cl);
|
||||
c->reg[Clbase + 0] = PCIWADDR(c->cl);
|
||||
c->reg[Clbase + 1] = Pciwaddrh(c->cl);
|
||||
c->cmdtab = smalloc(Nctlrdrv*sizeof *c->cmdtab);
|
||||
}
|
||||
|
||||
/* §5.1.2 */
|
||||
|
|
|
@ -262,7 +262,7 @@ axpstatus(Uart* uart, void* buf, long n, long offset)
|
|||
|
||||
ccb = ((Cc*)(uart->regs))->ccb;
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
bs = ccb->bs;
|
||||
fstat = ccb->df;
|
||||
ms = ccb->ms;
|
||||
|
|
|
@ -171,7 +171,7 @@ i8250status(Uart* uart, void* buf, long n, long offset)
|
|||
uchar ier, lcr, mcr, msr;
|
||||
|
||||
ctlr = uart->regs;
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
mcr = ctlr->sticky[Mcr];
|
||||
msr = csr8r(ctlr, Msr);
|
||||
ier = ctlr->sticky[Ier];
|
||||
|
|
|
@ -180,7 +180,11 @@ scanpci(void)
|
|||
dprint("usbehci: %#x %#x: port %#lux size %#x irq %d\n",
|
||||
p->vid, p->did, io, p->mem[0].size, p->intl);
|
||||
|
||||
ctlr = smalloc(sizeof(Ctlr));
|
||||
ctlr = malloc(sizeof(Ctlr));
|
||||
if(ctlr == nil){
|
||||
print("usbehci: no memory\n");
|
||||
continue;
|
||||
}
|
||||
ctlr->pcidev = p;
|
||||
capio = ctlr->capio = vmap(io, p->mem[0].size);
|
||||
ctlr->opio = (Eopio*)((uintptr)capio + (capio->cap & 0xff));
|
||||
|
|
|
@ -2383,15 +2383,19 @@ scanpci(void)
|
|||
dprint("ohci: %x/%x port 0x%lux size 0x%x irq %d\n",
|
||||
p->vid, p->did, mem, p->mem[0].size, p->intl);
|
||||
if(mem == 0){
|
||||
print("ohci: failed to map registers\n");
|
||||
print("usbohci: failed to map registers\n");
|
||||
continue;
|
||||
}
|
||||
if(p->intl == 0xFF || p->intl == 0) {
|
||||
print("ohci: no irq assigned for port %#lux\n", mem);
|
||||
print("usbohci: no irq assigned for port %#lux\n", mem);
|
||||
continue;
|
||||
}
|
||||
|
||||
ctlr = smalloc(sizeof(Ctlr));
|
||||
ctlr = malloc(sizeof(Ctlr));
|
||||
if(ctlr == nil){
|
||||
print("usbohci: no memory\n");
|
||||
continue;
|
||||
}
|
||||
ctlr->pcidev = p;
|
||||
ctlr->ohci = vmap(mem, p->mem[0].size);
|
||||
dprint("scanpci: ctlr %#p, ohci %#p\n", ctlr, ctlr->ohci);
|
||||
|
@ -2403,7 +2407,7 @@ scanpci(void)
|
|||
break;
|
||||
}
|
||||
if(i == Nhcis)
|
||||
print("ohci: bug: no more controllers\n");
|
||||
print("usbohci: bug: no more controllers\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2139,7 +2139,12 @@ scanpci(void)
|
|||
dprint("uhci: %#x %#x: port %#ux size %#x irq %d\n",
|
||||
p->vid, p->did, io, p->mem[4].size, p->intl);
|
||||
|
||||
ctlr = smalloc(sizeof(Ctlr));
|
||||
ctlr = malloc(sizeof(Ctlr));
|
||||
if(ctlr == nil){
|
||||
iofree(io);
|
||||
print("usbuhci: no memory\n");
|
||||
continue;
|
||||
}
|
||||
ctlr->pcidev = p;
|
||||
ctlr->port = io;
|
||||
for(i = 0; i < Nhcis; i++)
|
||||
|
@ -2148,7 +2153,7 @@ scanpci(void)
|
|||
break;
|
||||
}
|
||||
if(i == Nhcis)
|
||||
print("uhci: bug: no more controllers\n");
|
||||
print("usbuhci: bug: no more controllers\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ w_seek(Ctlr* ctlr, ushort id, ushort offset, int chan)
|
|||
static ushort off[] = { WR_Off0, WR_Off1 };
|
||||
|
||||
if(chan != 0 && chan != 1)
|
||||
panic("wavelan: bad chan\n");
|
||||
panic("wavelan: bad chan");
|
||||
csr_outs(ctlr, sel[chan], id);
|
||||
csr_outs(ctlr, off[chan], offset);
|
||||
for (i=0; i<WTmOut; i++){
|
||||
|
@ -846,7 +846,7 @@ w_ifstat(Ether* ether, void* a, long n, ulong offset)
|
|||
if(n == 0 || offset != 0)
|
||||
return 0;
|
||||
|
||||
p = malloc(READSTR);
|
||||
p = smalloc(READSTR);
|
||||
l = 0;
|
||||
|
||||
PRINTSTAT("Signal: %d\n", ctlr->signal-149);
|
||||
|
|
|
@ -509,7 +509,7 @@ uartwrite(Chan *c, void *buf, long n, vlong)
|
|||
poperror();
|
||||
break;
|
||||
case Nctlqid:
|
||||
cmd = malloc(n+1);
|
||||
cmd = smalloc(n+1);
|
||||
memmove(cmd, buf, n);
|
||||
cmd[n] = 0;
|
||||
qlock(p);
|
||||
|
|
|
@ -214,6 +214,8 @@ timersinit(void)
|
|||
*/
|
||||
todinit();
|
||||
t = malloc(sizeof(*t));
|
||||
if(t == nil)
|
||||
panic("timersinit: no memory for Timer");
|
||||
t->tmode = Tperiodic;
|
||||
t->tt = nil;
|
||||
t->tns = 1000000000/HZ;
|
||||
|
@ -229,6 +231,8 @@ addclock0link(void (*f)(void), int ms)
|
|||
|
||||
/* Synchronize to hztimer if ms is 0 */
|
||||
nt = malloc(sizeof(Timer));
|
||||
if(nt == nil)
|
||||
panic("addclock0link: no memory for Timer");
|
||||
if(ms == 0)
|
||||
ms = 1000/HZ;
|
||||
nt->tns = (vlong)ms*1000000LL;
|
||||
|
|
Loading…
Reference in a new issue