Re: [PATCH] shm: Remove silly double assignment

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andrew Morton
Date: Wednesday, June 11, 2008 - 3:45 am

On Tue, 10 Jun 2008 08:53:39 -0400 Neil Horman <nhorman@tuxdriver.com> wrote:


Not silly, really.  Look:

	err = -ENOMEM;
	if (expr1)
		goto out;

	err = -ENOMEM;
	if (expr2)
		goto out;

each of these two units is a separate, self-contained clause.  Removing
the second assignment to `err' breaks that separation and will make one
clause undesirably dependent upon the other.

Example: if someone later comes up and does

	err = -ENOMEM;
	if (expr1)
		goto out;

+	er = -EINVAL;
+	if (expr3)
+		goto out;

	if (expr2)
		goto out;

then whoops, it broke.

The compiler should optimise away the second assignment anyway.
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] shm: Remove silly double assignment, Neil Horman, (Tue Jun 10, 5:53 am)
Re: [PATCH] shm: Remove silly double assignment, Andrew Morton, (Wed Jun 11, 3:45 am)
Re: [PATCH] shm: Remove silly double assignment, Neil Horman, (Wed Jun 11, 10:03 am)
Re: [PATCH] shm: Remove silly double assignment, Ingo Molnar, (Wed Jun 18, 3:06 am)