From patchwork Thu Mar 6 19:56:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Behan Webster X-Patchwork-Id: 25848 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0B45E203C3 for ; Thu, 6 Mar 2014 19:56:55 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rp16sf7597033pbb.9 for ; Thu, 06 Mar 2014 11:56:55 -0800 (PST) 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 :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=7gk78RCUshK0RMFreI4fFoIYB3gLgDIdsR6THSfIcHk=; b=QfXKX/gdODA1yBJ1NaAnUjuzNDLeuTYRYTiHj3u1w+YteYxoFQm7wEy0HrDgrNbgU0 jk1gOLe5JQoVtgR022lwVjSUVnbFlrbuDbmzDtznGWg3qZQBe+Cy9Jg8nHBKJecXGun6 QYL/3l9SoYKXSQYTikVdXH47KPFXQAqcorMxjZnkztUCtyTyuZd8D+hXHDOEo1spixA1 VivZI9/hIsnh4SUv/LrFoaDsgSLEb/fXC04fJo77yzQEa6EpgZJ56AZYqW5pKcxKDzE0 JW8Bw5w43QlFuM0mSqP5eXuV77YMxveevKpREUce33zyjSXKg1h3bxzFzfOoUxw7d/Fs KOMA== X-Gm-Message-State: ALoCoQnA2jvqPnugYuYSiGBcC1EUev79LY+ufiB13lFqKMnQxdcwhTFjO+xedHvADutpfXAkNG+g X-Received: by 10.66.221.137 with SMTP id qe9mr6287271pac.4.1394135815271; Thu, 06 Mar 2014 11:56:55 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.30.201 with SMTP id d67ls926352qgd.62.gmail; Thu, 06 Mar 2014 11:56:55 -0800 (PST) X-Received: by 10.220.136.6 with SMTP id p6mr6537917vct.9.1394135814995; Thu, 06 Mar 2014 11:56:54 -0800 (PST) Received: from mail-ve0-x231.google.com (mail-ve0-x231.google.com [2607:f8b0:400c:c01::231]) by mx.google.com with ESMTPS id tt2si2129744vdc.126.2014.03.06.11.56.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Mar 2014 11:56:54 -0800 (PST) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::231 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::231; Received: by mail-ve0-f177.google.com with SMTP id sa20so3110092veb.36 for ; Thu, 06 Mar 2014 11:56:54 -0800 (PST) X-Received: by 10.58.100.100 with SMTP id ex4mr6770858veb.2.1394135814912; Thu, 06 Mar 2014 11:56:54 -0800 (PST) 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 i9csp63166vck; Thu, 6 Mar 2014 11:56:54 -0800 (PST) X-Received: by 10.68.197.99 with SMTP id it3mr16560579pbc.37.1394135813861; Thu, 06 Mar 2014 11:56:53 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yo5si5915452pab.208.2014.03.06.11.56.53; Thu, 06 Mar 2014 11:56:53 -0800 (PST) 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 S1753412AbaCFT4p (ORCPT + 26 others); Thu, 6 Mar 2014 14:56:45 -0500 Received: from mail-pb0-f48.google.com ([209.85.160.48]:48941 "EHLO mail-pb0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753358AbaCFT4m (ORCPT ); Thu, 6 Mar 2014 14:56:42 -0500 Received: by mail-pb0-f48.google.com with SMTP id md12so3066628pbc.21 for ; Thu, 06 Mar 2014 11:56:42 -0800 (PST) X-Received: by 10.68.139.39 with SMTP id qv7mr16752956pbb.77.1394135802037; Thu, 06 Mar 2014 11:56:42 -0800 (PST) Received: from galdor.websterwood.com (S0106dc9fdb80cffd.gv.shawcable.net. [96.50.97.138]) by mx.google.com with ESMTPSA id yk4sm18357931pbc.16.2014.03.06.11.56.39 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Mar 2014 11:56:40 -0800 (PST) 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, Mark Charlebois , Behan Webster , =?UTF-8?q?Vin=C3=ADcius=20Tinti?= Subject: [PATCH] net: inetfilter: LLVMLinux: vlais-netfilter Date: Thu, 6 Mar 2014 11:56:08 -0800 Message-Id: <1394135768-27621-1-git-send-email-behanw@converseincode.com> X-Mailer: git-send-email 1.8.3.2 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::231 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 (bad format) 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 | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h index 6efe4e5..c138fea 100644 --- a/net/netfilter/xt_repldata.h +++ b/net/netfilter/xt_repldata.h @@ -5,29 +5,51 @@ * they serve as the hanging-off data accessed through repl.data[]. */ +#define padbytes(offset, type) ((-offset) & (__alignof__(type)-1)) + +/* 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 = padbytes(sizeof(tbl->repl), *entries); \ + size_t entries_end = entries_offset + nhooks * sizeof(*entries); \ + size_t term_offset = entries_end \ + + padbytes(sizeof(tbl->repl) + entries_end, *term); \ + size_t term_end = term_offset + sizeof(*term); \ + size_t data_sz = term_end \ + + padbytes(sizeof(tbl->repl) + term_end, tbl->repl); \ + 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); \ } \