cipso: remove an unneeded NULL check in cipso_v4_doi_add()
PATCH 1/1 cipso: remove an unneeded NULL check in cipso_v4_doi_add()
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.
net/ipv4/cipso_ipv4.c +1 -1
@@ -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]) {
Paul Moore
maintainerQuoted 11 lines · Dan Carpenter
We dereference
doi_defon the line before the NULL check. It has been this way since 2008. I checked all the callers anddoi_defis always non-NULL here.Signed-off-by Dan Carpenter <[email protected]>net/ipv4/cipso_ipv4.c +0
-0
net/ipv4/cipso_ipv4.c int cipso_v4_doi_add(struct cipso_v4_doi *doi_def, · line 482
Quoted 8 lines
net/ipv4/cipso_ipv4.c +1
-1@@ -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.
Signature · 6 lines
paul moore www.paul-moore.com -- To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Paul Moore
Quoted 5 lines
- if (
doi_def= NULL ||doi_def->doi=CIPSO_V4_DOI_UNKNOWN)
+ if (doi_def->doi=CIPSO_V4_DOI_UNKNOWN)
gotodoi_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
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Miller
maintainerFrom: Dan Carpenter <[email protected]>
Date: Wed, 12 Oct 2011 00:55:49 +0300
Quoted 17 lines · Paul Moore
Quoted 10 lines
Quoted 5 lines
- if (
doi_def= NULL ||doi_def->doi=CIPSO_V4_DOI_UNKNOWN)
+ if (doi_def->doi=CIPSO_V4_DOI_UNKNOWN)
gotodoi_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_returnrelies on a non-NULL value fordoi_defbut I could just put a return in front of the dereference.
Quoted 4 lines
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.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Paul Moore
maintainerQuoted 7 lines · Dan Carpenter
Quoted 6 lines · Paul Moore
Quoted 5 lines
net/ipv4/cipso_ipv4.c +1
-1-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]) {
Quoted 7 lines
Quoted 4 lines
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.
Signature · 2 lines
paul moore www.paul-moore.com