Skip to contentSkip to conversation

net: remove useless if check from register_netdevice()

PATCH In review Denis Kirjanov 4 participants 6 messages Feb 13, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: remove useless if check from register_netdevice()

remove useless if check from register_netdevice()

---
v1 -> v2: Fixed identation

---
 net/core/dev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/dev.c +1 -2
index 4ad1b78..21a72ad 100644
@@ -5876,8 +5876,7 @@ int register_netdevice(struct net_device *dev)
 	if (dev->netdev_ops->ndo_init) {
 		ret = dev->netdev_ops->ndo_init(dev);
 		if (ret) {
-			if (ret > 0)
-				ret = -EIO;
+			ret = -EIO;
 			goto out;
 		}
 	}
Signature · 1 line
1.8.0.2
#1 lore raw
Quoted 14 lines · Denis Kirjanov

remove useless if check from register_netdevice()

---
v1 -> v2: Fixed identation

---
 net/core/dev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/dev.c +0 -0
index 4ad1b78..21a72ad 100644

net/core/dev.c int register_netdevice(struct net_device *dev) · line 5880

Quoted 7 lines
net/core/dev.c +1 -2
@@ -5876,8 +5876,7 @@ int register_netdevice(struct net_device *dev)
        if (dev->netdev_ops->ndo_init) {
                ret = dev->netdev_ops->ndo_init(dev);
                if (ret) {
-                       if (ret > 0)
-                               ret = -EIO;
+                       ret = -EIO;
                        goto out;

why is it a useless check?
seems perfectly valid to me.
most of the time ndo_init() returns negative error code like -ENOMEM which we want
to propagate further down and want to override it to -EIO if it's > 0

#2 lore raw

All of the users of ndo_init return negative error code on error path. Only staging stuff tries to use positive codes like octeon ethernet which does request_irq inside ndo_open...

Quoted 30 lines · Alexei Starovoitov
Quoted 14 lines · Denis Kirjanov

remove useless if check from register_netdevice()

---
v1 -> v2: Fixed identation

---
 net/core/dev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/dev.c +0 -0
index 4ad1b78..21a72ad 100644

net/core/dev.c int register_netdevice(struct net_device *dev) · line 5880

Quoted 7 lines
net/core/dev.c +1 -2
@@ -5876,8 +5876,7 @@ int register_netdevice(struct net_device *dev)
        if (dev->netdev_ops->ndo_init) {
                ret = dev->netdev_ops->ndo_init(dev);
                if (ret) {
-                       if (ret > 0)
-                               ret = -EIO;
+                       ret = -EIO;
                        goto out;

why is it a useless check?
seems perfectly valid to me.
most of the time ndo_init() returns negative error code like -ENOMEM which we want
to propagate further down and want to override it to -EIO if it's > 0

#3 lore raw
Quoted 4 lines · Denis Kirjanov

All of the users of ndo_init return negative error code on error path. Only staging stuff tries to use positive codes like octeon ethernet which does request_irq inside ndo_open...

You should put this explanation in the changelog.

maintainer
#4 lore raw
In reply to Denis Kirjanov

From: Denis Kirjanov <[email protected]>
Date: Thu, 13 Feb 2014 21:15:46 +0400

Quoted 3 lines

All of the users of ndo_init return negative error code on error path. Only staging stuff tries to use positive codes like octeon ethernet which does request_irq inside ndo_open...

Do not top-post, please.

Quote the necessary material of the person you are replying to, then provide your response underneath.

maintainer
#5 lore raw
In reply to Alexei Starovoitov

From: Alexei Starovoitov <[email protected]>
Date: Thu, 13 Feb 2014 08:23:08 -0800

Quoted 20 lines · Denis Kirjanov
Quoted 19 lines

remove useless if check from register_netdevice()

---
v1 -> v2: Fixed identation

---
 net/core/dev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/dev.c +0 -2
index 4ad1b78..21a72ad 100644
@@ -5876,8 +5876,7 @@ int register_netdevice(struct net_device *dev)
        if (dev->netdev_ops->ndo_init) {
                ret = dev->netdev_ops->ndo_init(dev);
                if (ret) {
-                       if (ret > 0)
-                               ret = -EIO;
Quoted 8 lines

net/core/dev.c int register_netdevice(struct net_device *dev) · line 5880

Quoted 2 lines
net/core/dev.c +1 -0
+                       ret = -EIO;
                        goto out;

why is it a useless check?
seems perfectly valid to me.
most of the time ndo_init() returns negative error code like -ENOMEM which we want
to propagate further down and want to override it to -EIO if it's > 0

Agreed, and if it is useless then unconditionally returining -EIO is absolutely the wrong thing to do. We should always use whatever negative error code ndo_init() gave us.

I'm not applying this patch.