Patchwork [net-next,2/3] netdevice: remove useless else keyword

login
register
mail settings
Submitter Jean Sacren
Date Aug. 6, 2013, 7:32 a.m.
Message ID <1375774371-831-2-git-send-email-sakiwit@gmail.com>
Download mbox | patch
Permalink /patch/264885/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

Jean Sacren - Aug. 6, 2013, 7:32 a.m.
Clean up multiple useless else keywords. Add empty lines for
readability.

Signed-off-by: Jean Sacren <sakiwit@gmail.com>
---
 net/core/dev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Daniel Borkmann - Aug. 6, 2013, 8:20 a.m.
On 08/06/2013 09:32 AM, Jean Sacren wrote:
> Clean up multiple useless else keywords. Add empty lines for
> readability.

Hmm, don't really think this is actually needed or makes things better.

> Signed-off-by: Jean Sacren <sakiwit@gmail.com>
> ---
>   net/core/dev.c | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 58eb802..1b0bea8 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -1062,9 +1062,11 @@ static int dev_get_valid_name(struct net *net,
>
>   	if (strchr(name, '%'))
>   		return dev_alloc_name_ns(net, dev, name);
> -	else if (__dev_get_by_name(net, name))
> +
> +	if (__dev_get_by_name(net, name))
>   		return -EEXIST;
> -	else if (dev->name != name)
> +
> +	if (dev->name != name)
>   		strlcpy(dev->name, name, IFNAMSIZ);
>
>   	return 0;
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches - Aug. 6, 2013, 2:37 p.m.
On Tue, 2013-08-06 at 10:20 +0200, Daniel Borkmann wrote:
> On 08/06/2013 09:32 AM, Jean Sacren wrote:
> > Clean up multiple useless else keywords. Add empty lines for
> > readability.
> 
> Hmm, don't really think this is actually needed or makes things better.

Maybe that's true.

Though this patch is pretty trivial and
I would (probably) not submit it, I think
it's a reasonable style rule to not use
else after an if() that always returns.

	if (foo)
		return bar;

	next_statement;

should be preferred over

	if (foo)
		return bar;
	else
		next_statement;

The blank lines though are a style taste.
Maybe removing the blank line before the
first if in this patch might be better.

{
	BUG_ON(!net);

	if (!dev_valid_name(name))
		return -EINVAL;
	if (strchr(name, '%'))
		return dev_alloc_name_ns(net, dev, name);
	if (__dev_get_by_name(net, name))
		return -EEXIST;
	if (dev->name != name)
		strlcpy(dev->name, name, IFNAMSIZ);

	return 0;
}


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index 58eb802..1b0bea8 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1062,9 +1062,11 @@  static int dev_get_valid_name(struct net *net,
 
 	if (strchr(name, '%'))
 		return dev_alloc_name_ns(net, dev, name);
-	else if (__dev_get_by_name(net, name))
+
+	if (__dev_get_by_name(net, name))
 		return -EEXIST;
-	else if (dev->name != name)
+
+	if (dev->name != name)
 		strlcpy(dev->name, name, IFNAMSIZ);
 
 	return 0;