From patchwork Wed Mar 19 01:50:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 26530 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 89B4F202FA for ; Wed, 19 Mar 2014 01:51:08 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id i17sf19065942qcy.3 for ; Tue, 18 Mar 2014 18:51:08 -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=AiD/S6JSBZ72brNyuHxrVU0OEJf8MxivbH8k20J4tUY=; b=aYLO6+LgU4fMauOc4O2C60a2kDGnQy0mcYaSsCd18Zh2kBaKoDPPxJwr3VkjFPoD7Q mBXDmWVIKIPF941UpjSiSC0LZdR0aMQONLh+Y9nZuFXMOHKnZ1P/kFrgEZIhhzBGl70m HMcYgG0HJF81UJ/jRSCrTezUoUaACM7f/hvsV2JilCeZN47j47ySamnonUjYrIkjPlVj Blp4HC0Xxvc/jmHYLyX94JhNKoR/ehUFO/wyNnYKBOuiOxthqqBkVc698lPp1w/Evuz1 xrXzblTyDUkrHoIfvPjuQYOMwXrk3M0VOXMowWnTTUezuaw4sz0eSr7lFMVFNEaN/i45 7iKA== X-Gm-Message-State: ALoCoQlYgbqHwGNG1mqBCZtan3ipeenizGL/urkMgpfEC8HjcCvmiLlXABXspdxW4W4MlmZIvtJE X-Received: by 10.58.154.228 with SMTP id vr4mr4066368veb.0.1395193868263; Tue, 18 Mar 2014 18:51:08 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.38.47 with SMTP id s44ls2311740qgs.70.gmail; Tue, 18 Mar 2014 18:51:08 -0700 (PDT) X-Received: by 10.52.189.33 with SMTP id gf1mr12574164vdc.26.1395193868127; Tue, 18 Mar 2014 18:51:08 -0700 (PDT) Received: from mail-ve0-x22e.google.com (mail-ve0-x22e.google.com [2607:f8b0:400c:c01::22e]) by mx.google.com with ESMTPS id f17si7165088vco.27.2014.03.18.18.51.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Mar 2014 18:51:08 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22e 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::22e; Received: by mail-ve0-f174.google.com with SMTP id oz11so8077710veb.33 for ; Tue, 18 Mar 2014 18:51:07 -0700 (PDT) X-Received: by 10.58.96.36 with SMTP id dp4mr7217109veb.21.1395193867932; Tue, 18 Mar 2014 18:51:07 -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 i9csp260007vck; Tue, 18 Mar 2014 18:51:07 -0700 (PDT) X-Received: by 10.66.122.101 with SMTP id lr5mr13896031pab.130.1395193866106; Tue, 18 Mar 2014 18:51:06 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id dg5si19406549pbc.157.2014.03.18.18.51.05; Tue, 18 Mar 2014 18:51:05 -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 S933501AbaCSBu7 (ORCPT + 26 others); Tue, 18 Mar 2014 21:50:59 -0400 Received: from mail-pd0-f176.google.com ([209.85.192.176]:60022 "EHLO mail-pd0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756760AbaCSBu4 (ORCPT ); Tue, 18 Mar 2014 21:50:56 -0400 Received: by mail-pd0-f176.google.com with SMTP id r10so7900083pdi.21 for ; Tue, 18 Mar 2014 18:50:56 -0700 (PDT) X-Received: by 10.66.148.230 with SMTP id tv6mr657577pab.155.1395193856029; Tue, 18 Mar 2014 18:50:56 -0700 (PDT) Received: from localhost.localdomain ([75.148.49.89]) by mx.google.com with ESMTPSA id fn2sm95533401pab.38.2014.03.18.18.50.53 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Mar 2014 18:50:54 -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, torvalds@linux-foundation.org, dwmw2@infradead.org, pageexec@freemail.hu, David.Laight@ACULAB.COM, Mark Charlebois , Behan Webster , =?UTF-8?q?Vin=C3=ADcius=20Tinti?= Subject: [PATCH v3] net: netfilter: LLVMLinux: vlais-netfilter Date: Tue, 18 Mar 2014 18:50:41 -0700 Message-Id: <1395193841-2886-1-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D0F6E0286@AcuExch.aculab.com> References: <063D6719AE5E284EB5DD2968C1650D6D0F6E0286@AcuExch.aculab.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::22e 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 | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h index 6efe4e5..343599e 100644 --- a/net/netfilter/xt_repldata.h +++ b/net/netfilter/xt_repldata.h @@ -5,23 +5,40 @@ * 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 entries_end = offsetof(typeof(*tbl), \ + entries[nhooks-1]) + sizeof(tbl->entries[0]); \ + size_t term_offset = (entries_end + __alignof__(*term) - 1) \ + & ~(__alignof__(*term) - 1); \ + size_t term_end = term_offset + sizeof(*term); \ + size_t tbl_sz = (term_end + __alignof__(tbl->repl) - 1) \ + & ~(__alignof__(tbl->repl) - 1); \ + tbl = kzalloc(tbl_sz, 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; \