diff --git a/m1/perf/sched.c b/m1/perf/sched.c index e7cc6db..25d3aeb 100644 --- a/m1/perf/sched.c +++ b/m1/perf/sched.c @@ -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);