Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[NETFILTER]: xt_sctp: simplify xt_sctp.h

The use of xt_sctp.h flagged up -Wshadow warnings in userspace, which
prompted me to look at it and clean it up. Basic operations have been
directly replaced by library calls (memcpy, memset is both available
in the kernel and userspace, and usually faster than a self-made
loop). The is_set and is_clear functions now use a processing time
shortcut, too.

Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de>
Signed-off-by: Patrick McHardy <kaber@trash.net>

authored by

Jan Engelhardt and committed by
Patrick McHardy
b9f61b16 fdccecd0

+31 -45
+31 -45
include/linux/netfilter/xt_sctp.h
··· 37 37 38 38 #define SCTP_CHUNKMAP_SET(chunkmap, type) \ 39 39 do { \ 40 - chunkmap[type / bytes(u_int32_t)] |= \ 40 + (chunkmap)[type / bytes(u_int32_t)] |= \ 41 41 1 << (type % bytes(u_int32_t)); \ 42 42 } while (0) 43 43 44 44 #define SCTP_CHUNKMAP_CLEAR(chunkmap, type) \ 45 45 do { \ 46 - chunkmap[type / bytes(u_int32_t)] &= \ 46 + (chunkmap)[type / bytes(u_int32_t)] &= \ 47 47 ~(1 << (type % bytes(u_int32_t))); \ 48 48 } while (0) 49 49 50 50 #define SCTP_CHUNKMAP_IS_SET(chunkmap, type) \ 51 51 ({ \ 52 - (chunkmap[type / bytes (u_int32_t)] & \ 52 + ((chunkmap)[type / bytes (u_int32_t)] & \ 53 53 (1 << (type % bytes (u_int32_t)))) ? 1: 0; \ 54 54 }) 55 55 56 - #define SCTP_CHUNKMAP_RESET(chunkmap) \ 57 - do { \ 58 - int i; \ 59 - for (i = 0; i < ARRAY_SIZE(chunkmap); i++) \ 60 - chunkmap[i] = 0; \ 61 - } while (0) 56 + #define SCTP_CHUNKMAP_RESET(chunkmap) \ 57 + memset((chunkmap), 0, sizeof(chunkmap)) 62 58 63 - #define SCTP_CHUNKMAP_SET_ALL(chunkmap) \ 64 - do { \ 65 - int i; \ 66 - for (i = 0; i < ARRAY_SIZE(chunkmap); i++) \ 67 - chunkmap[i] = ~0; \ 68 - } while (0) 59 + #define SCTP_CHUNKMAP_SET_ALL(chunkmap) \ 60 + memset((chunkmap), ~0U, sizeof(chunkmap)) 69 61 70 - #define SCTP_CHUNKMAP_COPY(destmap, srcmap) \ 71 - do { \ 72 - int i; \ 73 - for (i = 0; i < ARRAY_SIZE(srcmap); i++) \ 74 - destmap[i] = srcmap[i]; \ 75 - } while (0) 62 + #define SCTP_CHUNKMAP_COPY(destmap, srcmap) \ 63 + memcpy((destmap), (srcmap), sizeof(srcmap)) 76 64 77 - #define SCTP_CHUNKMAP_IS_CLEAR(chunkmap) \ 78 - ({ \ 79 - int i; \ 80 - int flag = 1; \ 81 - for (i = 0; i < ARRAY_SIZE(chunkmap); i++) { \ 82 - if (chunkmap[i]) { \ 83 - flag = 0; \ 84 - break; \ 85 - } \ 86 - } \ 87 - flag; \ 88 - }) 65 + #define SCTP_CHUNKMAP_IS_CLEAR(chunkmap) \ 66 + __sctp_chunkmap_is_clear((chunkmap), ARRAY_SIZE(chunkmap)) 67 + static inline bool 68 + __sctp_chunkmap_is_clear(const u_int32_t *chunkmap, unsigned int n) 69 + { 70 + unsigned int i; 71 + for (i = 0; i < n; ++i) 72 + if (chunkmap[i]) 73 + return false; 74 + return true; 75 + } 89 76 90 - #define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \ 91 - ({ \ 92 - int i; \ 93 - int flag = 1; \ 94 - for (i = 0; i < ARRAY_SIZE(chunkmap); i++) { \ 95 - if (chunkmap[i] != ~0) { \ 96 - flag = 0; \ 97 - break; \ 98 - } \ 99 - } \ 100 - flag; \ 101 - }) 77 + #define SCTP_CHUNKMAP_IS_ALL_SET(chunkmap) \ 78 + __sctp_chunkmap_is_all_set((chunkmap), ARRAY_SIZE(chunkmap)) 79 + static inline bool 80 + __sctp_chunkmap_is_all_set(const u_int32_t *chunkmap, unsigned int n) 81 + { 82 + unsigned int i; 83 + for (i = 0; i < n; ++i) 84 + if (chunkmap[i] != ~0U) 85 + return false; 86 + return true; 87 + } 102 88 103 89 #endif /* _XT_SCTP_H_ */ 104 90