1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-12-19 17:28:06 +02:00

m1/perf/sched.c: return -1 if malloc fails

This commit is contained in:
Werner Almesberger 2011-09-26 16:55:04 -03:00
parent 0a7e5b1473
commit 24a9b85ce0

View File

@ -312,7 +312,7 @@ static void mark(int vm_reg)
}
static void init_registers(struct fpvm_fragment *frag,
static int init_registers(struct fpvm_fragment *frag,
unsigned int *registers)
{
int i;
@ -321,6 +321,8 @@ static void init_registers(struct fpvm_fragment *frag,
sc->regs =
calloc(frag->nbindings-frag->next_sur, sizeof(struct vm_reg));
if (!sc->regs)
return -1;
for (i = 0; i != frag->ninstructions; i++) {
mark(frag->code[i].opa);
@ -332,6 +334,8 @@ static void init_registers(struct fpvm_fragment *frag,
for (i = PFPU_SPREG_COUNT; i != PFPU_REG_COUNT; i++)
if (!sc->pfpu_regs[i].used)
list_add_tail(&sc->unallocated, &sc->pfpu_regs[i].more);
return 0;
}
@ -609,15 +613,22 @@ static int schedule(unsigned int *code)
}
static void init_scheduler_context(struct fpvm_fragment *frag,
static int init_scheduler_context(struct fpvm_fragment *frag,
unsigned int *reg)
{
sc = calloc(1, sizeof(*sc));
if (!sc)
return -1;
sc->frag = frag;
init_registers(frag, reg);
if (init_registers(frag, reg) < 0) {
free(sc);
return -1;
}
init_scheduler(frag);
return 0;
}
@ -627,7 +638,8 @@ int gfpus_schedule(struct fpvm_fragment *frag, unsigned int *code,
pfpu_instruction vecout;
int res;
init_scheduler_context(frag, reg);
if (init_scheduler_context(frag, reg) < 0)
return -1;
memset(code, 0, PFPU_PROGSIZE*sizeof(*code));
res = schedule(code);