mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Michal Hocko <mhocko@suse.cz>
Cc: Jianyu Zhan <nasa4836@gmail.com>,
	iamjoonsoo.kim@lge.com, aneesh.kumar@linux.vnet.ibm.com,
	n-horiguchi@ah.jp.nec.com, aarcange@redhat.com,
	steve.capper@linaro.org, davidlohr@hp.com,
	kirill.shutemov@linux.intel.com, dave.hansen@linux.intel.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm, hugetlb: move the error handle logic out of normal code path
Date: Thu, 15 May 2014 15:36:20 -0700	[thread overview]
Message-ID: <20140515153620.344fe054b6b8d054a28fbf82@linux-foundation.org> (raw)
In-Reply-To: <20140515090142.GB3938@dhcp22.suse.cz>

On Thu, 15 May 2014 11:01:42 +0200 Michal Hocko <mhocko@suse.cz> wrote:

> On Wed 14-05-14 15:10:59, Jianyu Zhan wrote:
> > alloc_huge_page() now mixes normal code path with error handle logic.
> > This patches move out the error handle logic, to make normal code
> > path more clean and redue code duplicate.
> 
> I don't know. Part of the function returns and cleans up on its own and
> other part relies on clean up labels. This is not so much nicer than the
> previous state.

That's actually a common pattern:

foo()
{
	if (check which doesn't change any state)
		return -Efoo;
	if (another check which doesn't change any state)
		return -Ebar;

	do_something_which_changes_state()
	
	if (another check)
		goto undo_that_state_chage;
	...

undo_that_state_change:
	...
}


This ties into the main reason why we use all these gotos: to support
evolution of the code.  With multiple return points we risk later
adding resource leaks and locking errors.  Plus the code becomes more
and more duplicative and spaghettified.



  reply	other threads:[~2014-05-15 22:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-14  7:10 Jianyu Zhan
2014-05-15  9:01 ` Michal Hocko
2014-05-15 22:36   ` Andrew Morton [this message]
2014-05-16  7:57     ` Michal Hocko
2014-05-15 22:38 ` Davidlohr Bueso
2014-05-18 17:27 ` Aneesh Kumar K.V

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=20140515153620.344fe054b6b8d054a28fbf82@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=aarcange@redhat.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=davidlohr@hp.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.cz \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=nasa4836@gmail.com \
    --cc=steve.capper@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®