[POWERPC] spusched: Fix null pointer dereference in find_victim
[deliverable/linux.git] / arch / powerpc / platforms / cell / spufs / sched.c
index 227968b4779d3adc531fac2a71ef68dd1f18c386..5bebe7fbe056de17a39a8b78d419f67580735f74 100644 (file)
@@ -351,7 +351,8 @@ static void aff_set_ref_point_location(struct spu_gang *gang)
                lowest_offset = ctx->aff_offset;
        }
 
-       gang->aff_ref_spu = aff_ref_location(ctx, mem_aff, gs, lowest_offset);
+       gang->aff_ref_spu = aff_ref_location(gang->aff_ref_ctx, mem_aff, gs,
+                                                       lowest_offset);
 }
 
 static struct spu *ctx_location(struct spu *ref, int offset, int node)
@@ -578,7 +579,7 @@ static struct spu *find_victim(struct spu_context *ctx)
                list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) {
                        struct spu_context *tmp = spu->ctx;
 
-                       if (tmp->prio > ctx->prio &&
+                       if (tmp && tmp->prio > ctx->prio &&
                            (!victim || tmp->prio > victim->prio))
                                victim = spu->ctx;
                }
@@ -610,9 +611,9 @@ static struct spu *find_victim(struct spu_context *ctx)
 
                        mutex_lock(&cbe_spu_info[node].list_mutex);
                        cbe_spu_info[node].nr_active--;
+                       spu_unbind_context(spu, victim);
                        mutex_unlock(&cbe_spu_info[node].list_mutex);
 
-                       spu_unbind_context(spu, victim);
                        victim->stats.invol_ctx_switch++;
                        spu->stats.invol_ctx_switch++;
                        mutex_unlock(&victim->state_mutex);
@@ -927,10 +928,6 @@ int __init spu_sched_init(void)
                INIT_LIST_HEAD(&spu_prio->runq[i]);
                __clear_bit(i, spu_prio->bitmap);
        }
-       for (i = 0; i < MAX_NUMNODES; i++) {
-               mutex_init(&cbe_spu_info[i].list_mutex);
-               INIT_LIST_HEAD(&cbe_spu_info[i].spus);
-       }
        spin_lock_init(&spu_prio->runq_lock);
 
        setup_timer(&spusched_timer, spusched_wake, 0);
This page took 0.04313 seconds and 5 git commands to generate.