|
5 | 5 | * they serve as the hanging-off data accessed through repl.data[].
|
6 | 6 | */
|
7 | 7 |
|
| 8 | +/* tbl has the following structure equivalent, but is C99 compliant: |
| 9 | + * struct { |
| 10 | + * struct type##_replace repl; |
| 11 | + * struct type##_standard entries[nhooks]; |
| 12 | + * struct type##_error term; |
| 13 | + * } *tbl; |
| 14 | + */ |
| 15 | + |
8 | 16 | #define xt_alloc_initial_table(type, typ2) ({ \
|
9 | 17 | unsigned int hook_mask = info->valid_hooks; \
|
10 | 18 | unsigned int nhooks = hweight32(hook_mask); \
|
11 | 19 | unsigned int bytes = 0, hooknum = 0, i = 0; \
|
12 | 20 | struct { \
|
13 | 21 | struct type##_replace repl; \
|
14 |
| - struct type##_standard entries[nhooks]; \ |
15 |
| - struct type##_error term; \ |
16 |
| - } *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \ |
| 22 | + struct type##_standard entries[]; \ |
| 23 | + } *tbl; \ |
| 24 | + struct type##_error *term; \ |
| 25 | + size_t term_offset = (offsetof(typeof(*tbl), entries[nhooks]) + \ |
| 26 | + __alignof__(*term) - 1) & ~(__alignof__(*term) - 1); \ |
| 27 | + tbl = kzalloc(term_offset + sizeof(*term), GFP_KERNEL); \ |
17 | 28 | if (tbl == NULL) \
|
18 | 29 | return NULL; \
|
| 30 | + term = (struct type##_error *)&(((char *)tbl)[term_offset]); \ |
19 | 31 | strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
|
20 |
| - tbl->term = (struct type##_error)typ2##_ERROR_INIT; \ |
| 32 | + *term = (struct type##_error)typ2##_ERROR_INIT; \ |
21 | 33 | tbl->repl.valid_hooks = hook_mask; \
|
22 | 34 | tbl->repl.num_entries = nhooks + 1; \
|
23 | 35 | tbl->repl.size = nhooks * sizeof(struct type##_standard) + \
|
24 |
| - sizeof(struct type##_error); \ |
| 36 | + sizeof(struct type##_error); \ |
25 | 37 | for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \
|
26 | 38 | if (!(hook_mask & 1)) \
|
27 | 39 | continue; \
|
|
0 commit comments