From: Ingo Molnar <mingo@elte.hu>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Pallipadi, Venkatesh" <venkatesh.pallipadi@intel.com>,
Catalin Marinas <catalin.marinas@arm.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Darren Hart <dvhltc@us.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH -v2] futex: fix reference leak
Date: Wed, 11 Feb 2009 13:28:49 +0100 [thread overview]
Message-ID: <20090211122849.GD16535@elte.hu> (raw)
In-Reply-To: <1234205874.5951.151.camel@laptop>
* Peter Zijlstra <peterz@infradead.org> wrote:
> + if (!unqueue_me(&q)) {
> + ret = 0;
> + goto out_put_key;
> + }
> + if (rem) {
> + ret = -ETIMEDOUT;
> + goto out_put_key;
> + }
hm, we generally prefer to write such things as:
ret = 0;
if (!unqueue_me(&q))
goto out_put_key;
ret = -ETIMEDOUT;
if (rem)
goto out_put_key;
Also, while at it, the flow of control looks weird in other places too:
if (!abs_time)
return -ERESTARTSYS;
else {
struct restart_block *restart;
restart = ¤t_thread_info()->restart_block;
restart->fn = futex_wait_restart;
restart->futex.uaddr = (u32 *)uaddr;
Shouldnt it be something like:
if (!abs_time)
return -ERESTARTSYS;
restart = ¤t_thread_info()->restart_block;
restart->fn = futex_wait_restart;
restart->futex.uaddr = (u32 *)uaddr;
(with the variable definition moving up to local variables.)
and this:
> + if (!abs_time) {
> + ret = -ERESTARTSYS;
> + goto out_put_key;
> + } else {
> struct restart_block *restart;
> restart = ¤t_thread_info()->restart_block;
> restart->fn = futex_wait_restart;
> @@ -1309,11 +1314,13 @@ retry:
> restart->futex.flags |= FLAGS_SHARED;
> if (clockrt)
> restart->futex.flags |= FLAGS_CLOCKRT;
> - return -ERESTART_RESTARTBLOCK;
> + ret = -ERESTART_RESTARTBLOCK;
> + goto out_put_key;
> }
>
> out_unlock_put_key:
> queue_unlock(&q, hb);
> +out_put_key:
> put_futex_key(fshared, &q.key);
and this looks weird too, we jump-goto over the queue_unlock() in essence.
A proper flow would be to rename the error labels as err_unlock_*[etc], move
them out of line, let them jump back to the normal labels - and let the
tail section of the code above fall through.
Ingo
next prev parent reply other threads:[~2009-02-11 12:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-09 12:18 mm_alloc()'ed structure leak Catalin Marinas
2009-02-09 13:12 ` Catalin Marinas
2009-02-09 14:44 ` Catalin Marinas
2009-02-09 15:12 ` Peter Zijlstra
2009-02-09 16:45 ` Peter Zijlstra
2009-02-09 16:47 ` Peter Zijlstra
2009-02-09 17:28 ` Catalin Marinas
2009-02-09 18:26 ` [PATCH] futex: fix reference leak Peter Zijlstra
2009-02-09 18:53 ` Pallipadi, Venkatesh
2009-02-09 18:57 ` [PATCH -v2] " Peter Zijlstra
2009-02-09 20:49 ` Darren Hart
2009-02-11 12:28 ` Ingo Molnar [this message]
2009-02-11 15:36 ` [PATCH -v3] " Peter Zijlstra
2009-02-11 15:49 ` Ingo Molnar
2009-02-11 15:56 ` Peter Zijlstra
2009-02-11 16:26 ` Ingo Molnar
2009-02-11 17:10 ` [PATCH -v4] " Peter Zijlstra
2009-02-11 17:24 ` Ingo Molnar
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=20090211122849.GD16535@elte.hu \
--to=mingo@elte.hu \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=dvhltc@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=venkatesh.pallipadi@intel.com \
/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.