net: ipv6: Use struct_size() helper and kcalloc()
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. Also, remove unnecessary function ipv6_rpl_srh_alloc_size() and replace kzalloc() with kcalloc(), which has a 2-factor argument form for multiplication. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
5777cbba79
commit
6f39345768
@@ -580,7 +580,7 @@ looped_back:
|
||||
hdr->segments_left--;
|
||||
i = n - hdr->segments_left;
|
||||
|
||||
buf = kzalloc(ipv6_rpl_srh_alloc_size(n + 1) * 2, GFP_ATOMIC);
|
||||
buf = kcalloc(struct_size(hdr, segments.addr, n + 2), 2, GFP_ATOMIC);
|
||||
if (unlikely(!buf)) {
|
||||
kfree_skb(skb);
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user