From patchwork Sun Mar 23 06:55:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 26907 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f197.google.com (mail-ob0-f197.google.com [209.85.214.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EE50520490 for ; Sun, 23 Mar 2014 06:56:35 +0000 (UTC) Received: by mail-ob0-f197.google.com with SMTP id wp18sf16912149obc.0 for ; Sat, 22 Mar 2014 23:56:35 -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=VNxbqyF9a5ECbv16l0fg5ZwyJ8C9xkuaRexwqiKEN9c=; b=cYDizccCcAEqKcKUEn+TEVmynfazCZQ0VBtIvIGWjGkeAspX2s8F4VhppRVfbQFlrW /HRHDAIeHwo5eMgfEkyaHhMPIQSezPYI+JRnoku/TIoJZLmebiaITWByy849ckyWR8Tt JQW/Kk3aAQI2v0wkv38AIm8i6hTm4K5/zYT8QPiHK6ydT5A1nqSVWywP1VU49IYYA3vV WQ2cfc8FjpsySe+NQxvv5p7nnfrw9qd+8Sn2497IICL99SJMrtd6bLGcYozxcAzHFj3C JZeYpW+Vw3Dbar+eHUTG5GKnwxKfrmgIJs+FabGe1LPYk09zFI8m1zHcaaxR9UW93j8L 8tCQ== X-Gm-Message-State: ALoCoQmlQ31UFsHHIupDjwBFvWEjC5fRo07uYPJ7NySYKErBt2ZTG+Bw7w/TRT6BOaGtLSrzKK3Y X-Received: by 10.182.28.67 with SMTP id z3mr9944778obg.12.1395557795143; Sat, 22 Mar 2014 23:56:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.32.11 with SMTP id g11ls1215241qgg.11.gmail; Sat, 22 Mar 2014 23:56:35 -0700 (PDT) X-Received: by 10.58.90.99 with SMTP id bv3mr35094veb.34.1395557795002; Sat, 22 Mar 2014 23:56:35 -0700 (PDT) Received: from mail-vc0-x233.google.com (mail-vc0-x233.google.com [2607:f8b0:400c:c03::233]) by mx.google.com with ESMTPS id is3si2290394vec.99.2014.03.22.23.56.34 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 22 Mar 2014 23:56:34 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c03::233 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:c03::233; Received: by mail-vc0-f179.google.com with SMTP id ij19so4501717vcb.10 for ; Sat, 22 Mar 2014 23:56:34 -0700 (PDT) X-Received: by 10.220.133.80 with SMTP id e16mr45001462vct.13.1395557794854; Sat, 22 Mar 2014 23:56:34 -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 i9csp134589vck; Sat, 22 Mar 2014 23:56:34 -0700 (PDT) X-Received: by 10.68.170.66 with SMTP id ak2mr63894422pbc.5.1395557793543; Sat, 22 Mar 2014 23:56:33 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b5si6717681pbq.61.2014.03.22.23.56.32; Sat, 22 Mar 2014 23:56:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of netdev-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 S1751579AbaCWGzw (ORCPT + 4 others); Sun, 23 Mar 2014 02:55:52 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:50998 "EHLO mail-pb0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751007AbaCWGzu (ORCPT ); Sun, 23 Mar 2014 02:55:50 -0400 Received: by mail-pb0-f45.google.com with SMTP id uo5so4135740pbc.32 for ; Sat, 22 Mar 2014 23:55:49 -0700 (PDT) X-Received: by 10.68.191.39 with SMTP id gv7mr63930550pbc.90.1395557749823; Sat, 22 Mar 2014 23:55:49 -0700 (PDT) Received: from localhost.localdomain ([75.148.49.89]) by mx.google.com with ESMTPSA id e6sm19586716pbg.4.2014.03.22.23.55.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 22 Mar 2014 23:55:48 -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 v4] net: netfilter: LLVMLinux: vlais-netfilter Date: Sat, 22 Mar 2014 23:55:44 -0700 Message-Id: <1395557744-25248-1-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D0F6E0F8D@AcuExch.aculab.com> References: <063D6719AE5E284EB5DD2968C1650D6D0F6E0F8D@AcuExch.aculab.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: netdev@vger.kernel.org X-Original-Sender: behanw@converseincode.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c03::233 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. This version of the patch removes the trailing alignment that the VLAIS structure would allocate in order to simplify the patch. Author: Mark Charlebois Signed-off-by: Mark Charlebois Signed-off-by: Behan Webster Signed-off-by: Vinícius Tinti --- net/netfilter/xt_repldata.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h index 6efe4e5..8fd3241 100644 --- a/net/netfilter/xt_repldata.h +++ b/net/netfilter/xt_repldata.h @@ -5,23 +5,35 @@ * 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); \ + struct type##_standard entries[]; \ + } *tbl; \ + struct type##_error *term; \ + size_t term_offset = (offsetof(typeof(*tbl), entries[nhooks]) + \ + __alignof__(*term) - 1) & ~(__alignof__(*term) - 1); \ + tbl = kzalloc(term_offset + sizeof(*term), GFP_KERNEL); \ if (tbl == NULL) \ return NULL; \ + term = (struct type##_error *)&(((char *)tbl)[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; \