Re: broken do_each_pid_{thread,task}

From: Jiri Slaby
Date: Mon Dec 15 2008 - 05:51:03 EST


Oleg Nesterov napsal(a):
> On 12/14, Jiri Slaby wrote:
>> I'm getting
>> `if (type == PIDTYPE_PID)' is unreachable
>> warning from kernel/exit.c. The preprocessed code looks like:
>> do {
>> struct hlist_node *pos___;
>> if (pgrp != ((void *)0))
>> for (LIST ITERATION) {
>> {
>> if (!((p->state & 4) != 0))
>> continue;
>> retval = 1;
>> break;
>> }
>> if (PIDTYPE_PGID == PIDTYPE_PID)
>> break;
>> }
>> } while (0);
>> and it's obviously wrong.
>
> Why do you think it is wrong? This break stops the "hlist_for_each"
> loop, not the enclosing "do while".

The `continue' matters here (and also in other do_each_pid_task cases).
Sorry for not mentioning it explicitly.

> Actually, I don't understand why the compiler complains, and I never
> saw a warning myself.

Because the `if' is not reachable :). (And it's not compiler which complains
here.)

>> After investigating this code usage all around, it's broken on many places
>> this or similar way.
>>
>> For do_each_pid_thread(), even this code snippet from fs/ioprio.c is broken
>> due to double do {} while expansion:
>> do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
>> ret = set_task_ioprio(p, ioprio);
>> if (ret)
>> break;
>> } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
>
> Yes, this is obviously not what was intended. But afaics, this is
> the only place which should be fixed?

Actually yes. And add a big warning to the macros or whatever to not get
into it later again.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/