The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] shm: Remove silly double assignment
@ 2008-06-10 12:53 Neil Horman
  2008-06-11 10:45 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Neil Horman @ 2008-06-10 12:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: mingo, nhorman, torvalds

    Found a silly double assignment of err is do_shmat.  Silly, but good to clean up
    the useless code.
    
    Signed-off-by: Neil Horman <nhorman@tuxdriver.com>

diff --git a/ipc/shm.c b/ipc/shm.c
index 554429a..d05f6b5 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -894,8 +894,6 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
 	if (!sfd)
 		goto out_put_dentry;
 
-	err = -ENOMEM;
-
 	file = alloc_file(path.mnt, path.dentry, f_mode, &shm_file_operations);
 	if (!file)
 		goto out_free;
-- 
/****************************************************
 * Neil Horman <nhorman@tuxdriver.com>
 * Software Engineer, Red Hat
 ****************************************************/

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] shm: Remove silly double assignment
  2008-06-10 12:53 [PATCH] shm: Remove silly double assignment Neil Horman
@ 2008-06-11 10:45 ` Andrew Morton
  2008-06-11 17:03   ` Neil Horman
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2008-06-11 10:45 UTC (permalink / raw)
  To: Neil Horman; +Cc: linux-kernel, mingo, torvalds

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

>     Found a silly double assignment of err is do_shmat.  Silly, but good to clean up
>     the useless code.
>     
>     Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
> 
> diff --git a/ipc/shm.c b/ipc/shm.c
> index 554429a..d05f6b5 100644
> --- a/ipc/shm.c
> +++ b/ipc/shm.c
> @@ -894,8 +894,6 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
>  	if (!sfd)
>  		goto out_put_dentry;
>  
> -	err = -ENOMEM;
> -
>  	file = alloc_file(path.mnt, path.dentry, f_mode, &shm_file_operations);
>  	if (!file)
>  		goto out_free;

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] shm: Remove silly double assignment
  2008-06-11 10:45 ` Andrew Morton
@ 2008-06-11 17:03   ` Neil Horman
  2008-06-18 10:06     ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Neil Horman @ 2008-06-11 17:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, mingo, torvalds

On Wed, Jun 11, 2008 at 03:45:06AM -0700, Andrew Morton wrote:
> On Tue, 10 Jun 2008 08:53:39 -0400 Neil Horman <nhorman@tuxdriver.com> wrote:
> 
> >     Found a silly double assignment of err is do_shmat.  Silly, but good to clean up
> >     the useless code.
> >     
> >     Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
> > 
> > diff --git a/ipc/shm.c b/ipc/shm.c
> > index 554429a..d05f6b5 100644
> > --- a/ipc/shm.c
> > +++ b/ipc/shm.c
> > @@ -894,8 +894,6 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
> >  	if (!sfd)
> >  		goto out_put_dentry;
> >  
> > -	err = -ENOMEM;
> > -
> >  	file = alloc_file(path.mnt, path.dentry, f_mode, &shm_file_operations);
> >  	if (!file)
> >  		goto out_free;
> 
> 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.
yes, I see that keeping the second assignment lets you insert code in the middle
without having up to update afterwards.  I just don't think the redundant
assignment is worth keeping just for that purpose.


> 
> 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.
> 
Yes, but that would be the fault of the subsequent patch, and if they couldn't
see that problem, I fear that a double assignment isn't going to help them much.

> The compiler should optimise away the second assignment anyway.
Agreed, its really not a big deal.  If its not worth it, its fine with me.  I
was just being janitorial, and thought this looked rather redundant.

Best
Neil

-- 
/****************************************************
 * Neil Horman <nhorman@tuxdriver.com>
 * Software Engineer, Red Hat
 ****************************************************/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] shm: Remove silly double assignment
  2008-06-11 17:03   ` Neil Horman
@ 2008-06-18 10:06     ` Ingo Molnar
  0 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2008-06-18 10:06 UTC (permalink / raw)
  To: Neil Horman; +Cc: Andrew Morton, linux-kernel, mingo, torvalds


* 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.
>
> yes, I see that keeping the second assignment lets you insert code in 
> the middle without having up to update afterwards.  I just don't think 
> the redundant assignment is worth keeping just for that purpose.

cleanups is all about having familar, robust, predictable, 
self-contained patterns of code that are easy to recognize, easy to 
review and easy to keep working well.

In this case we've got an admittedly boundary case: removing the 
technically redundant piece of code, while a valid cleanup at first 
sight, makes the code less robust against future changes.

	Ingo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-06-18 10:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-10 12:53 [PATCH] shm: Remove silly double assignment Neil Horman
2008-06-11 10:45 ` Andrew Morton
2008-06-11 17:03   ` Neil Horman
2008-06-18 10:06     ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox