From patchwork Tue Mar 18 06:12:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 26450 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3E52C20143 for ; Tue, 18 Mar 2014 06:12:24 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id wo20sf25862190obc.10 for ; Mon, 17 Mar 2014 23:12:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=5RI31UX0TrrUiwkYFHZj+X1Gp2P1eiDAUS/kRTIJy8I=; b=ksrZKT01aVs9gz5Eiyr79fCw/3CregwRHgajfxsKSTUHuoFKjCBShnXCq72ZRksUkx FJFsp6I+gc18IGB+hU1i5gaSnQ+DCKqaJj50UxHlVIlWx/qUApax24G55BSGZ20mGUVr D4dI7FjxaRG7U5Edp4DQZPe7DdQMb/LRo7LomCa2L7fHbI0uWQnWH8mn5z8up8AXZEj7 iJuAfDe6LG+t/wHRFb5Iz9o97wDYeJQPGryqg9Dp/gyh3hO4Zo/o0ZwdlNn5mF2PFkag cCInJPXGdOpOnHwfyEn6WtEF9D2ZRe3U6khFznHyYAkaCvOBB3dYvVU/LKonoNdGPzYR nRYQ== X-Gm-Message-State: ALoCoQksFvoU7y0h2TxZLpJ6DhkW0LvQbDHNro3+W90uf9qdZOZ1mQnYg9blgUR29bkIndecEig+ X-Received: by 10.50.73.198 with SMTP id n6mr2912389igv.0.1395123143674; Mon, 17 Mar 2014 23:12:23 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.166 with SMTP id q35ls1960831qga.89.gmail; Mon, 17 Mar 2014 23:12:23 -0700 (PDT) X-Received: by 10.52.72.12 with SMTP id z12mr735788vdu.40.1395123143556; Mon, 17 Mar 2014 23:12:23 -0700 (PDT) Received: from mail-ve0-x22c.google.com (mail-ve0-x22c.google.com [2607:f8b0:400c:c01::22c]) by mx.google.com with ESMTPS id tr5si2417585vdc.36.2014.03.17.23.12.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Mar 2014 23:12:23 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22c is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22c; Received: by mail-ve0-f172.google.com with SMTP id jx11so6586918veb.3 for ; Mon, 17 Mar 2014 23:12:23 -0700 (PDT) X-Received: by 10.52.165.129 with SMTP id yy1mr8657499vdb.25.1395123143401; Mon, 17 Mar 2014 23:12:23 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.78.9 with SMTP id i9csp180057vck; Mon, 17 Mar 2014 23:12:22 -0700 (PDT) X-Received: by 10.69.31.171 with SMTP id kn11mr31164565pbd.47.1395123142518; Mon, 17 Mar 2014 23:12:22 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id og9si9037828pbb.356.2014.03.17.23.12.21; Mon, 17 Mar 2014 23:12:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753215AbaCRGMM (ORCPT + 26 others); Tue, 18 Mar 2014 02:12:12 -0400 Received: from mail-pa0-f44.google.com ([209.85.220.44]:34029 "EHLO mail-pa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752457AbaCRGMJ (ORCPT ); Tue, 18 Mar 2014 02:12:09 -0400 Received: by mail-pa0-f44.google.com with SMTP id bj1so6847778pad.3 for ; Mon, 17 Mar 2014 23:12:09 -0700 (PDT) X-Received: by 10.66.158.132 with SMTP id wu4mr31054613pab.66.1395123128970; Mon, 17 Mar 2014 23:12:08 -0700 (PDT) Received: from localhost.localdomain ([75.148.49.89]) by mx.google.com with ESMTPSA id nx12sm82511580pab.6.2014.03.17.23.12.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Mar 2014 23:12:07 -0700 (PDT) From: behanw@converseincode.com To: davem@davemloft.net Cc: pablo@netfilter.org, kaber@trash.net, kadlec@blackhole.kfki.hu, netfilter-devel@vger.kernel.org, netfilter@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dwmw2@infradead.org, pageexec@freemail.hu, Mark Charlebois , Behan Webster , =?UTF-8?q?Vin=C3=ADcius=20Tinti?= Subject: [PATCH v2] net: netfilter: LLVMLinux: vlais-netfilter Date: Mon, 17 Mar 2014 23:12:01 -0700 Message-Id: <1395123121-27053-1-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <022D9517-4804-47BB-B789-CCF25F25C1ED@me.com> References: <022D9517-4804-47BB-B789-CCF25F25C1ED@me.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Original-Sender: behanw@converseincode.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22c is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (no key for signature) header.i=@converseincode.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Mark Charlebois Replaced non-standard C use of Variable Length Arrays In Structs (VLAIS) in xt_repldata.h with a C99 compliant flexible array member and then calculated offsets to the other struct members. These other members aren't referenced by name in this code, however this patch maintains the same memory layout and padding as was previously accomplished using VLAIS. Had the original structure been ordered differently, with the entries VLA at the end, then it could have been a flexible member, and this patch would have been a lot simpler. However since the data stored in this structure is ultimately exported to userspace, the order of this structure can't be changed. This patch makes no attempt to change the existing behavior, merely the way in which the current layout is accomplished using standard C99 constructs. As such the code can now be compiled with either gcc or clang. Author: Mark Charlebois Signed-off-by: Mark Charlebois Signed-off-by: Behan Webster Signed-off-by: Vinícius Tinti --- net/netfilter/xt_repldata.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h index 6efe4e5..f83a519 100644 --- a/net/netfilter/xt_repldata.h +++ b/net/netfilter/xt_repldata.h @@ -5,29 +5,50 @@ * they serve as the hanging-off data accessed through repl.data[]. */ +/* tbl has the following structure equivalent, but is C99 compliant: + * struct { + * struct type##_replace repl; + * struct type##_standard entries[nhooks]; + * struct type##_error term; + * } *tbl; + */ + #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); \ + char data[0]; \ + } *tbl; \ + struct type##_standard *entries; \ + struct type##_error *term; \ + size_t entries_offset = (-sizeof(tbl->repl)) & \ + (__alignof__(*entries)-1); \ + size_t entries_end = entries_offset + nhooks * sizeof(*entries); \ + size_t term_offset = entries_end + \ + (-sizeof(tbl->repl) - entries_end) & (__alignof__(*term)-1); \ + size_t term_end = term_offset + sizeof(*term); \ + size_t data_sz = term_end + \ + (-sizeof(tbl->repl) - term_end) & (__alignof__(tbl->repl)-1); \ + size_t tbl_sz = sizeof(tbl->repl) + data_sz; \ + tbl = kzalloc(tbl_sz, GFP_KERNEL); \ if (tbl == NULL) \ return NULL; \ + entries = (struct type##_standard *)&tbl->data[entries_offset]; \ + term = (struct type##_error *)&tbl->data[term_offset]; \ strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \ - tbl->term = (struct type##_error)typ2##_ERROR_INIT; \ + *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); \ + sizeof(struct type##_error); \ 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) \ + entries[i++] = (struct type##_standard) \ typ2##_STANDARD_INIT(NF_ACCEPT); \ bytes += sizeof(struct type##_standard); \ } \