Re: [PATCH] mm, hugetlb: move the error handle logic out of normal code path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 15 May 2014 11:01:42 +0200 Michal Hocko <mhocko@xxxxxxx> 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.


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]