All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private()
@ 2014-09-23 17:05 Rob Jones
  2014-09-23 17:46   ` Ben Hutchings
  0 siblings, 1 reply; 7+ messages in thread
From: Rob Jones @ 2014-09-23 17:05 UTC (permalink / raw)
  To: davem
  Cc: netfilter, coreteam, netfilter-devel, netdev, linux-kernel,
	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.

This version 2 incorporates a minor initialisation simplification (resulting
from kzalloc() being used) requested by netfilter-devel@vger.kernel.org

 net/netfilter/x_tables.c |   31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)

diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 227aa11..393f17b 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1080,7 +1080,6 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
 	struct nf_mttg_trav *trav = seq->private;
 	unsigned int j;
 
-	trav->class = MTTG_TRAV_INIT;
 	for (j = 0; j < *pos; ++j)
 		if (xt_mttg_seq_next(seq, NULL, NULL, is_target) == NULL)
 			return NULL;
@@ -1137,22 +1136,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 +1189,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] 7+ messages in thread

* Re: [Linux-kernel] [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private()
  2014-09-23 17:05 [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private() Rob Jones
@ 2014-09-23 17:46   ` Ben Hutchings
  0 siblings, 0 replies; 7+ messages in thread
From: Ben Hutchings @ 2014-09-23 17:46 UTC (permalink / raw)
  To: Rob Jones
  Cc: davem, coreteam, netdev, linux-kernel, linux-kernel, netfilter,
	netfilter-devel

On Tue, 2014-09-23 at 18:05 +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.
> 
> 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.
> 
> This version 2 incorporates a minor initialisation simplification (resulting
> from kzalloc() being used) requested by netfilter-devel@vger.kernel.org
[...]
> --- a/net/netfilter/x_tables.c
> +++ b/net/netfilter/x_tables.c
> @@ -1080,7 +1080,6 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
>         struct nf_mttg_trav *trav = seq->private;
>         unsigned int j;
>  
> -       trav->class = MTTG_TRAV_INIT;
>         for (j = 0; j < *pos; ++j)
>                 if (xt_mttg_seq_next(seq, NULL, NULL, is_target) == NULL)
>                         return NULL;
[...]

I'm fairly sure this simplification is wrong, as xt_mttg_seq_start() is
potentially called multiple times on the same file handle.

Ben.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private()
@ 2014-09-23 17:46   ` Ben Hutchings
  0 siblings, 0 replies; 7+ messages in thread
From: Ben Hutchings @ 2014-09-23 17:46 UTC (permalink / raw)
  To: Rob Jones
  Cc: davem, coreteam, netdev, linux-kernel, linux-kernel, netfilter,
	netfilter-devel

On Tue, 2014-09-23 at 18:05 +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.
> 
> 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.
> 
> This version 2 incorporates a minor initialisation simplification (resulting
> from kzalloc() being used) requested by netfilter-devel@vger.kernel.org
[...]
> --- a/net/netfilter/x_tables.c
> +++ b/net/netfilter/x_tables.c
> @@ -1080,7 +1080,6 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
>         struct nf_mttg_trav *trav = seq->private;
>         unsigned int j;
>  
> -       trav->class = MTTG_TRAV_INIT;
>         for (j = 0; j < *pos; ++j)
>                 if (xt_mttg_seq_next(seq, NULL, NULL, is_target) == NULL)
>                         return NULL;
[...]

I'm fairly sure this simplification is wrong, as xt_mttg_seq_start() is
potentially called multiple times on the same file handle.

Ben.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-kernel] [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private()
  2014-09-23 17:46   ` Ben Hutchings
@ 2014-09-23 21:40     ` Pablo Neira Ayuso
  -1 siblings, 0 replies; 7+ messages in thread
From: Pablo Neira Ayuso @ 2014-09-23 21:40 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: Rob Jones, davem, coreteam, netdev, linux-kernel, linux-kernel,
	netfilter, netfilter-devel

On Tue, Sep 23, 2014 at 06:46:27PM +0100, Ben Hutchings wrote:
> On Tue, 2014-09-23 at 18:05 +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.
> > 
> > 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.
> > 
> > This version 2 incorporates a minor initialisation simplification (resulting
> > from kzalloc() being used) requested by netfilter-devel@vger.kernel.org
> [...]
> > --- a/net/netfilter/x_tables.c
> > +++ b/net/netfilter/x_tables.c
> > @@ -1080,7 +1080,6 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
> >         struct nf_mttg_trav *trav = seq->private;
> >         unsigned int j;
> >  
> > -       trav->class = MTTG_TRAV_INIT;
> >         for (j = 0; j < *pos; ++j)
> >                 if (xt_mttg_seq_next(seq, NULL, NULL, is_target) == NULL)
> >                         return NULL;
> [...]
> 
> I'm fairly sure this simplification is wrong, as xt_mttg_seq_start() is
> potentially called multiple times on the same file handle.

Right. I'm going to take v1 of this patch instead, sorry for the
inconvenience Rob.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private()
@ 2014-09-23 21:40     ` Pablo Neira Ayuso
  0 siblings, 0 replies; 7+ messages in thread
From: Pablo Neira Ayuso @ 2014-09-23 21:40 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: Rob Jones, davem, coreteam, netdev, linux-kernel, linux-kernel,
	netfilter, netfilter-devel

On Tue, Sep 23, 2014 at 06:46:27PM +0100, Ben Hutchings wrote:
> On Tue, 2014-09-23 at 18:05 +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.
> > 
> > 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.
> > 
> > This version 2 incorporates a minor initialisation simplification (resulting
> > from kzalloc() being used) requested by netfilter-devel@vger.kernel.org
> [...]
> > --- a/net/netfilter/x_tables.c
> > +++ b/net/netfilter/x_tables.c
> > @@ -1080,7 +1080,6 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
> >         struct nf_mttg_trav *trav = seq->private;
> >         unsigned int j;
> >  
> > -       trav->class = MTTG_TRAV_INIT;
> >         for (j = 0; j < *pos; ++j)
> >                 if (xt_mttg_seq_next(seq, NULL, NULL, is_target) == NULL)
> >                         return NULL;
> [...]
> 
> I'm fairly sure this simplification is wrong, as xt_mttg_seq_start() is
> potentially called multiple times on the same file handle.

Right. I'm going to take v1 of this patch instead, sorry for the
inconvenience Rob.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Linux-kernel] [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private()
  2014-09-23 21:40     ` Pablo Neira Ayuso
@ 2014-09-24  8:14       ` Rob Jones
  -1 siblings, 0 replies; 7+ messages in thread
From: Rob Jones @ 2014-09-24  8:14 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Ben Hutchings
  Cc: davem, coreteam, netdev, linux-kernel, linux-kernel, netfilter,
	netfilter-devel



On 23/09/14 22:40, Pablo Neira Ayuso wrote:
> On Tue, Sep 23, 2014 at 06:46:27PM +0100, Ben Hutchings wrote:
>> On Tue, 2014-09-23 at 18:05 +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.
>>>
>>> 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.
>>>
>>> This version 2 incorporates a minor initialisation simplification (resulting
>>> from kzalloc() being used) requested by netfilter-devel@vger.kernel.org
>> [...]
>>> --- a/net/netfilter/x_tables.c
>>> +++ b/net/netfilter/x_tables.c
>>> @@ -1080,7 +1080,6 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
>>>          struct nf_mttg_trav *trav = seq->private;
>>>          unsigned int j;
>>>
>>> -       trav->class = MTTG_TRAV_INIT;
>>>          for (j = 0; j < *pos; ++j)
>>>                  if (xt_mttg_seq_next(seq, NULL, NULL, is_target) == NULL)
>>>                          return NULL;
>> [...]
>>
>> I'm fairly sure this simplification is wrong, as xt_mttg_seq_start() is
>> potentially called multiple times on the same file handle.

Well spotted Ben.

>
> Right. I'm going to take v1 of this patch instead, sorry for the
> inconvenience Rob.

No problem at all. It gave me something to do on the train home last
night :-)

-- 
Rob Jones
Codethink Ltd
mailto:rob.jones@codethink.co.uk
tel:+44 161 236 5575

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private()
@ 2014-09-24  8:14       ` Rob Jones
  0 siblings, 0 replies; 7+ messages in thread
From: Rob Jones @ 2014-09-24  8:14 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Ben Hutchings
  Cc: davem, coreteam, netdev, linux-kernel, linux-kernel, netfilter,
	netfilter-devel



On 23/09/14 22:40, Pablo Neira Ayuso wrote:
> On Tue, Sep 23, 2014 at 06:46:27PM +0100, Ben Hutchings wrote:
>> On Tue, 2014-09-23 at 18:05 +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.
>>>
>>> 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.
>>>
>>> This version 2 incorporates a minor initialisation simplification (resulting
>>> from kzalloc() being used) requested by netfilter-devel@vger.kernel.org
>> [...]
>>> --- a/net/netfilter/x_tables.c
>>> +++ b/net/netfilter/x_tables.c
>>> @@ -1080,7 +1080,6 @@ static void *xt_mttg_seq_start(struct seq_file *seq, loff_t *pos,
>>>          struct nf_mttg_trav *trav = seq->private;
>>>          unsigned int j;
>>>
>>> -       trav->class = MTTG_TRAV_INIT;
>>>          for (j = 0; j < *pos; ++j)
>>>                  if (xt_mttg_seq_next(seq, NULL, NULL, is_target) == NULL)
>>>                          return NULL;
>> [...]
>>
>> I'm fairly sure this simplification is wrong, as xt_mttg_seq_start() is
>> potentially called multiple times on the same file handle.

Well spotted Ben.

>
> Right. I'm going to take v1 of this patch instead, sorry for the
> inconvenience Rob.

No problem at all. It gave me something to do on the train home last
night :-)

-- 
Rob Jones
Codethink Ltd
mailto:rob.jones@codethink.co.uk
tel:+44 161 236 5575

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-09-24  8:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-23 17:05 [PATCH v2] net/netfilter/x_tables.c: use __seq_open_private() Rob Jones
2014-09-23 17:46 ` [Linux-kernel] " Ben Hutchings
2014-09-23 17:46   ` Ben Hutchings
2014-09-23 21:40   ` [Linux-kernel] " Pablo Neira Ayuso
2014-09-23 21:40     ` Pablo Neira Ayuso
2014-09-24  8:14     ` [Linux-kernel] " Rob Jones
2014-09-24  8:14       ` Rob Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.