Skip to contentSkip to conversation

if (x) kfree(x) ?

KJ Christophe Jaillet 2 participants 2 messages Dec 1, 2005 Kernel janitors

lore
Share & tools
lore
#0 lore raw

In many places in the kernel source, piece of code such as the following can be seen :

in /net/ipv4/ip_sockglue.c
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ if (msf)

    kfree(msf);
   if (gsf)
    kfree(gsf);

+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
or ugglier in /drivers/char/istallion.c +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ if (stli_tmpwritebuf != (char *) NULL)
kfree(stli_tmpwritebuf);
if (stli_txcookbuf != (char *) NULL)
kfree(stli_txcookbuf);
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
The test againt NULL is already done in kfree, so there is aparently no need to test it before calling kfree. As I don't know if there are another issues (speed, ...) I just point it out to you and ask if you think it would be a good idea to remove these tests against NULL from the kernel source.

Any comment ?

CJ

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors

#1 lore raw
Quoted 11 lines · Christophe Jaillet

In many places in the kernel source, piece of code such as the following can be seen :

in /net/ipv4/ip_sockglue.c
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
if (msf)

    kfree(msf);
   if (gsf)
    kfree(gsf);

+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

Quoted 7 lines

or ugglier in /drivers/char/istallion.c
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
if (stli_tmpwritebuf != (char *) NULL)
kfree(stli_tmpwritebuf);
if (stli_txcookbuf != (char *) NULL)
kfree(stli_txcookbuf);
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

Both are already changed in 2.6.15-rc4.

Quoted 6 lines

The test againt NULL is already done in kfree, so there is aparently no need to test it before calling kfree. As I don't know if there are another issues (speed, ...) I just point it out to you and ask if you think it would be a good idea to remove these tests against NULL from the kernel source.

Any comment ?

Generally, there is not much reason for such a NULL check (there could in theory speed reasons in favor of "if (unlikely(foo)) kfree(foo);", but only in extremely rare cases (especially since the bigger amount of code has a negative effect on the speed)).

Jesper is already sending tons of paches in this area, and it's therefore not a good idea for you to work on the same issue.

Quoted 1 line

CJ

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors