netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] cipso: remove an unneeded NULL check in cipso_v4_doi_add()
@ 2011-10-11 13:22 Dan Carpenter
  2011-10-11 21:20 ` Paul Moore
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2011-10-11 13:22 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy, netdev, kernel-janitors

We dereference doi_def on the line before the NULL check.  It has
been this way since 2008.  I checked all the callers and doi_def is
always non-NULL here.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index 2c2a98e..86f3b88 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -476,7 +476,7 @@ int cipso_v4_doi_add(struct cipso_v4_doi *doi_def,
 	doi = doi_def->doi;
 	doi_type = doi_def->type;
 
-	if (doi_def == NULL || doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
+	if (doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
 		goto doi_add_return;
 	for (iter = 0; iter < CIPSO_V4_TAG_MAXCNT; iter++) {
 		switch (doi_def->tags[iter]) {

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

* Re: [patch] cipso: remove an unneeded NULL check in cipso_v4_doi_add()
  2011-10-11 13:22 [patch] cipso: remove an unneeded NULL check in cipso_v4_doi_add() Dan Carpenter
@ 2011-10-11 21:20 ` Paul Moore
  2011-10-11 21:55   ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Paul Moore @ 2011-10-11 21:20 UTC (permalink / raw)
  To: Dan Carpenter, netdev
  Cc: David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy, kernel-janitors

On Tue, Oct 11, 2011 at 9:22 AM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> We dereference doi_def on the line before the NULL check.  It has
> been this way since 2008.  I checked all the callers and doi_def is
> always non-NULL here.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>
> diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
> index 2c2a98e..86f3b88 100644
> --- a/net/ipv4/cipso_ipv4.c
> +++ b/net/ipv4/cipso_ipv4.c
> @@ -476,7 +476,7 @@ int cipso_v4_doi_add(struct cipso_v4_doi *doi_def,
>        doi = doi_def->doi;
>        doi_type = doi_def->type;
>
> -       if (doi_def == NULL || doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
> +       if (doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
>                goto doi_add_return;
>        for (iter = 0; iter < CIPSO_V4_TAG_MAXCNT; iter++) {
>                switch (doi_def->tags[iter]) {

I'd prefer to keep the NULL check in there as it does afford a little
bit of extra safety and this is management code after all, not
per-packet processing code, so the extra check should have no
observable performance impact.

-- 
paul moore
www.paul-moore.com

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

* Re: [patch] cipso: remove an unneeded NULL check in cipso_v4_doi_add()
  2011-10-11 21:20 ` Paul Moore
@ 2011-10-11 21:55   ` Dan Carpenter
  2011-10-11 22:42     ` David Miller
  2011-10-12 21:28     ` Paul Moore
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2011-10-11 21:55 UTC (permalink / raw)
  To: Paul Moore
  Cc: netdev, David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy, kernel-janitors

On Tue, Oct 11, 2011 at 05:20:11PM -0400, Paul Moore wrote:
> > -       if (doi_def == NULL || doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
> > +       if (doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
> >                goto doi_add_return;
> >        for (iter = 0; iter < CIPSO_V4_TAG_MAXCNT; iter++) {
> >                switch (doi_def->tags[iter]) {
> 
> I'd prefer to keep the NULL check in there as it does afford a little
> bit of extra safety and this is management code after all, not
> per-packet processing code, so the extra check should have no
> observable performance impact.

The dereferences on the lines before mean we would Oops before
reaching the check.  But I guess I can move the check forward.  The
error handling at goto doi_add_return relies on a non-NULL value for
doi_def but I could just put a return in front of the dereference.

	if (!doi_def)
		return -EINVAL;

I'll send a patch to do this tomorrow.

regards,
dan carpenter

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

* Re: [patch] cipso: remove an unneeded NULL check in cipso_v4_doi_add()
  2011-10-11 21:55   ` Dan Carpenter
@ 2011-10-11 22:42     ` David Miller
  2011-10-12 21:28     ` Paul Moore
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2011-10-11 22:42 UTC (permalink / raw)
  To: dan.carpenter
  Cc: paul, netdev, kuznet, jmorris, yoshfuji, kaber, kernel-janitors

From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 12 Oct 2011 00:55:49 +0300

> On Tue, Oct 11, 2011 at 05:20:11PM -0400, Paul Moore wrote:
>> > -       if (doi_def == NULL || doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
>> > +       if (doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
>> >                goto doi_add_return;
>> >        for (iter = 0; iter < CIPSO_V4_TAG_MAXCNT; iter++) {
>> >                switch (doi_def->tags[iter]) {
>> 
>> I'd prefer to keep the NULL check in there as it does afford a little
>> bit of extra safety and this is management code after all, not
>> per-packet processing code, so the extra check should have no
>> observable performance impact.
> 
> The dereferences on the lines before mean we would Oops before
> reaching the check.  But I guess I can move the check forward.  The
> error handling at goto doi_add_return relies on a non-NULL value for
> doi_def but I could just put a return in front of the dereference.
> 
> 	if (!doi_def)
> 		return -EINVAL;
> 
> I'll send a patch to do this tomorrow.

I think your original patch is still the best one.

Saying the NULL check should stay to provide "extra safety" is
complete garbage.  Especially since, as Dan shows, we dereference the
pointer before to damn check.

I'll therefore apply Dan's original patch.

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

* Re: [patch] cipso: remove an unneeded NULL check in cipso_v4_doi_add()
  2011-10-11 21:55   ` Dan Carpenter
  2011-10-11 22:42     ` David Miller
@ 2011-10-12 21:28     ` Paul Moore
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Moore @ 2011-10-12 21:28 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: netdev, David S. Miller, Alexey Kuznetsov, James Morris,
	Hideaki YOSHIFUJI, Patrick McHardy, kernel-janitors

On Wednesday, October 12, 2011 12:55:49 AM Dan Carpenter wrote:
> On Tue, Oct 11, 2011 at 05:20:11PM -0400, Paul Moore wrote:
> > > -       if (doi_def == NULL || doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
> > > +       if (doi_def->doi == CIPSO_V4_DOI_UNKNOWN)
> > >                goto doi_add_return;
> > >        for (iter = 0; iter < CIPSO_V4_TAG_MAXCNT; iter++) {
> > >                switch (doi_def->tags[iter]) {
> > 
> > I'd prefer to keep the NULL check in there as it does afford a little
> > bit of extra safety and this is management code after all, not
> > per-packet processing code, so the extra check should have no
> > observable performance impact.
> 
> The dereferences on the lines before mean we would Oops before
> reaching the check ...

Thanks for pointing that out, I missed that when looking at your patch.

-- 
paul moore
www.paul-moore.com

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

end of thread, other threads:[~2011-10-12 21:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-11 13:22 [patch] cipso: remove an unneeded NULL check in cipso_v4_doi_add() Dan Carpenter
2011-10-11 21:20 ` Paul Moore
2011-10-11 21:55   ` Dan Carpenter
2011-10-11 22:42     ` David Miller
2011-10-12 21:28     ` Paul Moore

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).