ipv4: avoid undefined behavior in do_ip_setsockopt()
authorXi Wang <xi.wang@gmail.com>
Sun, 11 Nov 2012 11:20:01 +0000 (11:20 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 26 Nov 2012 19:37:46 +0000 (11:37 -0800)
commit0fa89335e494872552e8e1d4e594c18559922e5c
tree47351b01daf7eecfe04bf029fc6bcf08a2e0d61a
parent999d6a5194c9707b081869f40306ac5e1727edf4
ipv4: avoid undefined behavior in do_ip_setsockopt()

[ Upstream commit 0c9f79be295c99ac7e4b569ca493d75fdcc19e4e ]

(1<<optname) is undefined behavior in C with a negative optname or
optname larger than 31.  In those cases the result of the shift is
not necessarily zero (e.g., on x86).

This patch simplifies the code with a switch statement on optname.
It also allows the compiler to generate better code (e.g., using a
64-bit mask).

Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/ip_sockglue.c