All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Jiri Slaby <jirislaby@gmail.com>
Cc: kenchen@google.com,
	Linux kernel mailing list <linux-kernel@vger.kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: Re: broken do_each_pid_{thread,task}
Date: Mon, 15 Dec 2008 12:51:08 +0100	[thread overview]
Message-ID: <20081215115108.GA17577@redhat.com> (raw)
In-Reply-To: <4946406D.6000506@gmail.com>

On 12/15, Jiri Slaby wrote:
>
> Oleg Nesterov napsal(a):
> > On 12/15, Jiri Slaby wrote:
> >> 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.
> >
> > Still can't understand... OK, I think we misundersood each other.
> > Do you agree that the code is technically correct? Or I missed
> > something?
> >
> > "continue" looks fine to me too, it is also for the inner loop.
>
> But it doesn't jump to the `if' (this is what I would expect from the
> `continue' here), but to the third statement of the `for'.

Yes, but this doesn't matter,

> Maybe better to ask, is the test expected to be fired after *each*
> invocation of the body?

Yes, but we need this only when type == PIDTYPE_PID, so the code
is correct.

> > Look, "if (PIDTYPE_PGID == PIDTYPE_PID)" is not possible too, should
> > the compiler (or whatever) complain?
>
> Correct, in this particular case (and I checked that also other users which
> uses `continue' inside the loop don't pass PIDTYPE_PID).

Yes.

Don't get me wrong, I do agree (let me repeat again) this check is
absolutely ugly and may cause the problems.

As I said, it fixes the minor and only theoretical problem. Perhaps we
can move this check to the code  which does do_each_pid_task(PIDTYPE_PID).
Or better yet, just introduce for_each_pid_task() (see another email).

> >> (And it's not compiler which complains
> >> here.)
> >
> > Ah, OK, thanks. Just curious, and who does?
>
> A static analyzer. Stay tuned, we will announce it later, it's in the state
> of development :).

Great, thanks ;)

Oleg.


  reply	other threads:[~2008-12-15 11:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-14 21:59 broken do_each_pid_{thread,task} Jiri Slaby
2008-12-15  1:02 ` Eric W. Biederman
2008-12-15 10:47   ` Oleg Nesterov
2008-12-15 17:09     ` Oleg Nesterov
2009-02-24 13:22       ` Jiri Slaby
2009-02-24 15:49         ` Oleg Nesterov
2009-02-24 16:21           ` Jiri Slaby
2009-02-24 21:49             ` [RFC, PATCH] introduce pid_for_each_task() to replace do_each_pid_task() Oleg Nesterov
2008-12-15 10:24 ` broken do_each_pid_{thread,task} Oleg Nesterov
2008-12-15 10:50   ` Jiri Slaby
2008-12-15 11:02     ` Oleg Nesterov
2008-12-15 11:33       ` Jiri Slaby
2008-12-15 11:51         ` Oleg Nesterov [this message]
2009-10-12 10:55           ` Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081215115108.GA17577@redhat.com \
    --to=oleg@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=jirislaby@gmail.com \
    --cc=kenchen@google.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.