This patch tries to fix an issue reported in net/ipv4/af_inet.c by Coverity, please review and apply if correct.
Error reported: CID: 1728 Checker: DEADCODE File: net/ipv4/af_inet.c Function: inet_create Description: After this line (or expression), the value of "protocol" cannot be 0 Problem Description: In the existing code, if the protocol is not supported, "answer" will be NULL and an error code of -ESOCKTNOSUPPORT will be returned. The condition "if(!protocol)" which returns -EPROTONOSUPPORT will never be reached because the value of protocol cannot be 0(IPPROTO_IP), when the answer != NULL. This patch - removes the "if(!protocol)" check - adds a check when answer == NULL, to see if the list is empty to return -ESOCKTNOSUPPORT or -EPROTONOSUPPORT Signed-off-by: Jayachandran C. <c.jayachandran at gmail.com> --- af_inet.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) diff -ur linux-2.6.15-rc3-git1.clean/net/ipv4/af_inet.c linux-2.6.15-rc3-git1/net/ipv4/af_inet.c --- linux-2.6.15-rc3-git1.clean/net/ipv4/af_inet.c Wed Nov 30 21:55:27 2005 +++ linux-2.6.15-rc3-git1/net/ipv4/af_inet.c Thu Dec 1 05:19:22 2005 @@ -228,7 +228,7 @@ unsigned char answer_flags; char answer_no_check; int try_loading_module = 0; - int err = -ESOCKTNOSUPPORT; + int err; sock->state = SS_UNCONNECTED; @@ -273,16 +273,18 @@ request_module("net-pf-%d-proto-%d", PF_INET, protocol); goto lookup_protocol; - } else + } else { + if (list_empty(&inetsw[sock->type])) + err = -ESOCKTNOSUPPORT; + else + err = -EPROTONOSUPPORT; goto out_rcu_unlock; + } } err = -EPERM; if (answer->capability > 0 && !capable(answer->capability)) goto out_rcu_unlock; - err = -EPROTONOSUPPORT; - if (!protocol) - goto out_rcu_unlock; sock->ops = answer->ops; answer_prot = answer->prot; - To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html