From patchwork Thu Sep 18 16:48:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Jones X-Patchwork-Id: 390862 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C5F931401AD for ; Fri, 19 Sep 2014 02:49:05 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932173AbaIRQsq (ORCPT ); Thu, 18 Sep 2014 12:48:46 -0400 Received: from ducie-dc1.codethink.co.uk ([185.25.241.215]:36886 "EHLO ducie-dc1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756218AbaIRQsp (ORCPT ); Thu, 18 Sep 2014 12:48:45 -0400 Received: from localhost (localhost [127.0.0.1]) by ducie-dc1.codethink.co.uk (Postfix) with ESMTP id 4040146743C; Thu, 18 Sep 2014 17:48:43 +0100 (BST) X-Virus-Scanned: Debian amavisd-new at ducie-dc1.codethink.co.uk Received: from ducie-dc1.codethink.co.uk ([127.0.0.1]) by localhost (ducie-dc1.codethink.co.uk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2CdsysBehJnP; Thu, 18 Sep 2014 17:48:40 +0100 (BST) Received: from localhost.localdomain (unknown [213.205.241.225]) by ducie-dc1.codethink.co.uk (Postfix) with ESMTPSA id 6D11A466D5F; Thu, 18 Sep 2014 17:48:39 +0100 (BST) From: Rob Jones To: davem@davemloft.net Cc: netfilter@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel@codethink.co.uk, rob.jones@codethink.co.uk Subject: [PATCH] net/netfilter/x_tables.c: use __seq_open_private() Date: Thu, 18 Sep 2014 17:48:31 +0100 Message-Id: <1411058911-17655-1-git-send-email-rob.jones@codethink.co.uk> X-Mailer: git-send-email 1.7.10.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Reduce boilerplate code by using __seq_open_private() instead of seq_open() in xt_match_open() and xt_target_open(). Signed-off-by: Rob Jones --- This patch uses an existing variant of seq_open() to reduce the kernel code size. The only significant variation from the pre-existing code is the fact that __seq_open_private() calls kzalloc() rather than kmalloc(), which could conceivably have an impact on timing. net/netfilter/x_tables.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c index 227aa11..89aa680 100644 --- a/net/netfilter/x_tables.c +++ b/net/netfilter/x_tables.c @@ -1137,22 +1137,11 @@ static const struct seq_operations xt_match_seq_ops = { static int xt_match_open(struct inode *inode, struct file *file) { - struct seq_file *seq; struct nf_mttg_trav *trav; - int ret; - - trav = kmalloc(sizeof(*trav), GFP_KERNEL); - if (trav == NULL) + trav = __seq_open_private(file, &xt_match_seq_ops, sizeof(*trav)); + if (!trav) return -ENOMEM; - ret = seq_open(file, &xt_match_seq_ops); - if (ret < 0) { - kfree(trav); - return ret; - } - - seq = file->private_data; - seq->private = trav; trav->nfproto = (unsigned long)PDE_DATA(inode); return 0; } @@ -1201,22 +1190,11 @@ static const struct seq_operations xt_target_seq_ops = { static int xt_target_open(struct inode *inode, struct file *file) { - struct seq_file *seq; struct nf_mttg_trav *trav; - int ret; - - trav = kmalloc(sizeof(*trav), GFP_KERNEL); - if (trav == NULL) + trav = __seq_open_private(file, &xt_target_seq_ops, sizeof(*trav)); + if (!trav) return -ENOMEM; - ret = seq_open(file, &xt_target_seq_ops); - if (ret < 0) { - kfree(trav); - return ret; - } - - seq = file->private_data; - seq->private = trav; trav->nfproto = (unsigned long)PDE_DATA(inode); return 0; }