net-ipv6: Fix alleged compiler warning in ipv6_exthdrs_len()
authorJerry Chu <hkchu@google.com>
Mon, 16 Dec 2013 02:48:07 +0000 (18:48 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 16 Dec 2013 04:55:04 +0000 (23:55 -0500)
It was reported that Commit 299603e8370a93dd5d8e8d800f0dff1ce2c53d36
("net-gro: Prepare GRO stack for the upcoming tunneling support")
triggered a compiler warning in ipv6_exthdrs_len():

net/ipv6/ip6_offload.c: In function ‘ipv6_gro_complete’:
net/ipv6/ip6_offload.c:178:24: warning: ‘optlen’ may be used uninitialized in this function [-Wmaybe-u
    opth = (void *)opth + optlen;
     ^
    net/ipv6/ip6_offload.c:164:22: note: ‘optlen’ was declared here
    int len = 0, proto, optlen;
                        ^
Note that there was no real bug here - optlen was never uninitialized
before use. (Was the version of gcc I used smarter to not complain?)

Reported-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: H.K. Jerry Chu <hkchu@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/ip6_offload.c

index 08861f1ff883844dacc0722011a06303aba190fa..6fb4162fa78572411ccac31ac833c4eabe523fdc 100644 (file)
@@ -160,8 +160,8 @@ out:
 static int ipv6_exthdrs_len(struct ipv6hdr *iph,
                            const struct net_offload **opps)
 {
-       struct ipv6_opt_hdr *opth = NULL;
-       int len = 0, optlen = 0, proto;
+       struct ipv6_opt_hdr *opth = (void *)iph;
+       int len = 0, proto, optlen = sizeof(*iph);
 
        proto = iph->nexthdr;
        for (;;) {
@@ -172,12 +172,8 @@ static int ipv6_exthdrs_len(struct ipv6hdr *iph,
                        if (!((*opps)->flags & INET6_PROTO_GSO_EXTHDR))
                                break;
                }
-               if (opth == NULL) {
-                       opth = (void *)(iph+1);
-               } else {
-                       optlen = ipv6_optlen(opth);
-                       opth = (void *)opth + optlen;
-               }
+               opth = (void *)opth + optlen;
+               optlen = ipv6_optlen(opth);
                len += optlen;
                proto = opth->nexthdr;
        }