* [PATCH] net/netfilter/x_tables.c: use __seq_open_private()
@ 2014-09-19 10:27 Rob Jones
2014-09-23 14:02 ` Pablo Neira Ayuso
0 siblings, 1 reply; 5+ messages in thread
From: Rob Jones @ 2014-09-19 10:27 UTC (permalink / raw)
To: netfilter-devel; +Cc: linux-kernel, rob.jones
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 <rob.jones@codethink.co.uk>
---
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.
** I am sending this to the developers' list now. I failed to transcribe
the full cc list output by get-maintainer.pl, mea culpa, mea maxima culpa **
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;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] net/netfilter/x_tables.c: use __seq_open_private()
2014-09-19 10:27 [PATCH] net/netfilter/x_tables.c: use __seq_open_private() Rob Jones
@ 2014-09-23 14:02 ` Pablo Neira Ayuso
2014-09-23 15:32 ` Rob Jones
0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2014-09-23 14:02 UTC (permalink / raw)
To: Rob Jones; +Cc: netfilter-devel, linux-kernel
On Fri, Sep 19, 2014 at 11:27:51AM +0100, Rob Jones wrote:
> 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 <rob.jones@codethink.co.uk>
> ---
>
> This patch uses an existing variant of seq_open() to reduce the kernel code
> size.
Less code to maintain, good.
> 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.
I think you can skip
trav->class = MTTG_TRAV_INIT;
too, now that trav is set to zero.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net/netfilter/x_tables.c: use __seq_open_private()
2014-09-23 14:02 ` Pablo Neira Ayuso
@ 2014-09-23 15:32 ` Rob Jones
2014-09-23 15:36 ` Pablo Neira Ayuso
0 siblings, 1 reply; 5+ messages in thread
From: Rob Jones @ 2014-09-23 15:32 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel, linux-kernel
Would you like that change made and re-submitted? It's the work of
moments to do it.
I was only concentrating on not changing the logic so I didn't check on
whether and existing initialisation was made redundant.
On 23/09/14 15:02, Pablo Neira Ayuso wrote:
> On Fri, Sep 19, 2014 at 11:27:51AM +0100, Rob Jones wrote:
>> 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 <rob.jones@codethink.co.uk>
>> ---
>>
>> This patch uses an existing variant of seq_open() to reduce the kernel code
>> size.
>
> Less code to maintain, good.
>
>> 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.
>
> I think you can skip
>
> trav->class = MTTG_TRAV_INIT;
>
> too, now that trav is set to zero.
>
>
>
--
Rob Jones
Codethink Ltd
mailto:rob.jones@codethink.co.uk
tel:+44 161 236 5575
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net/netfilter/x_tables.c: use __seq_open_private()
2014-09-23 15:32 ` Rob Jones
@ 2014-09-23 15:36 ` Pablo Neira Ayuso
2014-09-23 15:38 ` Rob Jones
0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2014-09-23 15:36 UTC (permalink / raw)
To: Rob Jones; +Cc: netfilter-devel, linux-kernel
On Tue, Sep 23, 2014 at 04:32:39PM +0100, Rob Jones wrote:
> Would you like that change made and re-submitted? It's the work of
> moments to do it.
Yes please, send us a v2. Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] net/netfilter/x_tables.c: use __seq_open_private()
2014-09-23 15:36 ` Pablo Neira Ayuso
@ 2014-09-23 15:38 ` Rob Jones
0 siblings, 0 replies; 5+ messages in thread
From: Rob Jones @ 2014-09-23 15:38 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel, linux-kernel
Will do.
On 23/09/14 16:36, Pablo Neira Ayuso wrote:
> On Tue, Sep 23, 2014 at 04:32:39PM +0100, Rob Jones wrote:
>> Would you like that change made and re-submitted? It's the work of
>> moments to do it.
>
> Yes please, send us a v2. Thanks.
>
>
>
--
Rob Jones
Codethink Ltd
mailto:rob.jones@codethink.co.uk
tel:+44 161 236 5575
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-09-23 15:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-19 10:27 [PATCH] net/netfilter/x_tables.c: use __seq_open_private() Rob Jones
2014-09-23 14:02 ` Pablo Neira Ayuso
2014-09-23 15:32 ` Rob Jones
2014-09-23 15:36 ` Pablo Neira Ayuso
2014-09-23 15:38 ` Rob Jones
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).