From: Behan Webster <behanw@converseincode.com>
To: balbi@ti.com, davem@davemloft.net
Cc: linux-usb@vger.kernel.org, netfilter-devel@vger.kernel.org,
linux-kernel@vger.kernel.org, "Jan-Simon Möller" <dl9pf@gmx.de>,
pageexec@freemail.hu, "Behan Webster" <behanw@converseincode.com>
Subject: [PATCH V2 3/3] Remove VLAIS usage from netfilter
Date: Tue, 30 Oct 2012 17:18:57 -0400 [thread overview]
Message-ID: <1351631937-21455-4-git-send-email-behanw@converseincode.com> (raw)
In-Reply-To: <1351631937-21455-1-git-send-email-behanw@converseincode.com>
From: Jan-Simon Möller <dl9pf@gmx.de>
The use of variable length arrays in structs (VLAIS) in the Linux Kernel code
precludes the use of compilers which don't implement VLAIS (for instance the
Clang compiler). This patch instead calculates offsets into the kmalloc-ed
memory buffer using macros from valign.h.
Patch from series at
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120507/142707.html
by PaX Team.
Signed-off-by: Jan-Simon Möller <dl9pf@gmx.de>
Cc: pageexec@freemail.hu
[Modified to use macros from valign.h]
Signed-off-by: Behan Webster <behanw@converseincode.com>
---
net/netfilter/xt_repldata.h | 40 ++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h
index 6efe4e5..d2b4232 100644
--- a/net/netfilter/xt_repldata.h
+++ b/net/netfilter/xt_repldata.h
@@ -5,31 +5,39 @@
* they serve as the hanging-off data accessed through repl.data[].
*/
+#include <linux/valign.h>
+
#define xt_alloc_initial_table(type, typ2) ({ \
unsigned int hook_mask = info->valid_hooks; \
unsigned int nhooks = hweight32(hook_mask); \
unsigned int bytes = 0, hooknum = 0, i = 0; \
- struct { \
- struct type##_replace repl; \
- struct type##_standard entries[nhooks]; \
- struct type##_error term; \
- } *tbl = kzalloc(sizeof(*tbl), GFP_KERNEL); \
- if (tbl == NULL) \
+ int replsize = paddedsize(0, 1, \
+ struct type##_replace, struct type##_standard); \
+ int entsize = paddedsize(replsize, nhooks, \
+ struct type##_standard, struct type##_error); \
+ int termsize = paddedsize(replsize+entsize, 1, \
+ struct type##_error, int); \
+ struct type##_replace *repl = kzalloc(replsize+entsize+termsize, \
+ GFP_KERNEL); \
+ if (repl == NULL) \
return NULL; \
- strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
- tbl->term = (struct type##_error)typ2##_ERROR_INIT; \
- tbl->repl.valid_hooks = hook_mask; \
- tbl->repl.num_entries = nhooks + 1; \
- tbl->repl.size = nhooks * sizeof(struct type##_standard) + \
- sizeof(struct type##_error); \
+ struct type##_standard *entries = paddedstart(repl, replsize, \
+ struct type##_standard); \
+ struct type##_error *term = paddedstart(entries, entsize, \
+ struct type##_error); \
+ strncpy(repl->name, info->name, sizeof(repl->name)); \
+ *term = (struct type##_error)typ2##_ERROR_INIT; \
+ repl->valid_hooks = hook_mask; \
+ repl->num_entries = nhooks + 1; \
+ repl->size = entsize+termsize; \
for (; hook_mask != 0; hook_mask >>= 1, ++hooknum) { \
if (!(hook_mask & 1)) \
continue; \
- tbl->repl.hook_entry[hooknum] = bytes; \
- tbl->repl.underflow[hooknum] = bytes; \
- tbl->entries[i++] = (struct type##_standard) \
+ repl->hook_entry[hooknum] = bytes; \
+ repl->underflow[hooknum] = bytes; \
+ entries[i++] = (struct type##_standard) \
typ2##_STANDARD_INIT(NF_ACCEPT); \
bytes += sizeof(struct type##_standard); \
} \
- tbl; \
+ repl; \
})
--
1.7.9.5
next prev parent reply other threads:[~2012-10-30 21:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-30 21:18 [PATCH V2 0/3] Removing the use of VLAIS from USB Gadget and netfilter Behan Webster
2012-10-30 21:18 ` [PATCH V2 1/3] Helper macros used for replacing the use of VLAIS Behan Webster
2012-10-30 21:18 ` [PATCH V2 2/3] Remove VLAIS usage from gadget code Behan Webster
[not found] ` <1351631937-21455-3-git-send-email-behanw-k/hB3zQhLwledRVtV/plodBPR1lH4CV8@public.gmane.org>
2012-10-31 13:28 ` Felipe Balbi
[not found] ` <20121031132838.GQ10998-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-10-31 15:33 ` Behan Webster
[not found] ` <509144C0.8000601-k/hB3zQhLwledRVtV/plodBPR1lH4CV8@public.gmane.org>
2012-11-01 7:21 ` Felipe Balbi
2012-11-01 15:03 ` David Miller
[not found] ` <20121101072116.GA32013-S8G//mZuvNWo5Im9Ml3/Zg@public.gmane.org>
2012-12-03 11:57 ` Sebastian Andrzej Siewior
[not found] ` <20121203115706.GA4760-E0PNVn5OA6ohrxcnuTQ+TQ@public.gmane.org>
2012-12-03 18:57 ` Behan Webster
2012-12-04 22:24 ` Sebastian Andrzej Siewior
[not found] ` <20121204222438.GA7624-E0PNVn5OA6ohrxcnuTQ+TQ@public.gmane.org>
2012-12-04 23:50 ` Behan Webster
2012-12-05 23:48 ` [llvmlinux] " Bryce Lelbach
2012-10-30 21:18 ` Behan Webster [this message]
2012-10-31 16:45 ` [PATCH V2 0/3] Removing the use of VLAIS from USB Gadget and netfilter David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1351631937-21455-4-git-send-email-behanw@converseincode.com \
--to=behanw@converseincode.com \
--cc=balbi@ti.com \
--cc=davem@davemloft.net \
--cc=dl9pf@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pageexec@freemail.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).