Commit 86c8f9d1 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[IPV4] Fix EPROTONOSUPPORT error in inet_create

There is a coding error in inet_create that causes it to always return
ESOCKTNOSUPPORT.  It should return EPROTONOSUPPORT when there are
protocols registered for a given socket type but none of them match
the requested protocol.

This is based on a patch by Jayachandran C.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 24c69275
...@@ -228,13 +228,14 @@ static int inet_create(struct socket *sock, int protocol) ...@@ -228,13 +228,14 @@ static int inet_create(struct socket *sock, int protocol)
unsigned char answer_flags; unsigned char answer_flags;
char answer_no_check; char answer_no_check;
int try_loading_module = 0; int try_loading_module = 0;
int err = -ESOCKTNOSUPPORT; int err;
sock->state = SS_UNCONNECTED; sock->state = SS_UNCONNECTED;
/* Look for the requested type/protocol pair. */ /* Look for the requested type/protocol pair. */
answer = NULL; answer = NULL;
lookup_protocol: lookup_protocol:
err = -ESOCKTNOSUPPORT;
rcu_read_lock(); rcu_read_lock();
list_for_each_rcu(p, &inetsw[sock->type]) { list_for_each_rcu(p, &inetsw[sock->type]) {
answer = list_entry(p, struct inet_protosw, list); answer = list_entry(p, struct inet_protosw, list);
...@@ -252,6 +253,7 @@ static int inet_create(struct socket *sock, int protocol) ...@@ -252,6 +253,7 @@ static int inet_create(struct socket *sock, int protocol)
if (IPPROTO_IP == answer->protocol) if (IPPROTO_IP == answer->protocol)
break; break;
} }
err = -EPROTONOSUPPORT;
answer = NULL; answer = NULL;
} }
...@@ -280,9 +282,6 @@ static int inet_create(struct socket *sock, int protocol) ...@@ -280,9 +282,6 @@ static int inet_create(struct socket *sock, int protocol)
err = -EPERM; err = -EPERM;
if (answer->capability > 0 && !capable(answer->capability)) if (answer->capability > 0 && !capable(answer->capability))
goto out_rcu_unlock; goto out_rcu_unlock;
err = -EPROTONOSUPPORT;
if (!protocol)
goto out_rcu_unlock;
sock->ops = answer->ops; sock->ops = answer->ops;
answer_prot = answer->prot; answer_prot = answer->prot;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment