Re: [PATCH 2/5] mm: remove unlikly NULL from kfree

From: Steven Rostedt
Date: Wed Mar 25 2009 - 11:27:28 EST



On Wed, 25 Mar 2009, Steven Rostedt wrote:
>
> # cat /debug/tracing/trace | sort -u
>
> record_nulls: ptr=(null) (ext3_get_acl+0x1e0/0x3f0 [ext3])
> record_nulls: ptr=(null) (free_bitmap+0x29/0x70)
> record_nulls: ptr=(null) (free_tty_struct+0x1d/0x40)
> record_nulls: ptr=(null) (ftrace_graph_exit_task+0x1e/0x20)
> record_nulls: ptr=(null) (inet_sock_destruct+0x1cb/0x2a0)
> record_nulls: ptr=(null) (ip_cork_release+0x24/0x50)
> record_nulls: ptr=(null) (keyctl_join_session_keyring+0x5a/0x70)
> record_nulls: ptr=(null) (key_user_lookup+0x183/0x220)
> record_nulls: ptr=(null) (kobject_set_name_vargs+0x43/0x50)
> record_nulls: ptr=(null) (netlink_release+0x1a4/0x2f0)
> record_nulls: ptr=(null) (release_sysfs_dirent+0x20/0xc0)
> record_nulls: ptr=(null) (sysfs_open_file+0x1c8/0x3e0)
> record_nulls: ptr=(null) (tty_write+0x16a/0x290)
>

Hmm, it is looking like the patter of calling kfree(NULL) is due to this:

struct some_struct *some_init_function(int some_option)
{
some_pointer = kzalloc(sizeof(struct some_struct));

if (some_option)
some_pointer->some_item = kmalloc();

return some_pointer;
}

some_destructor(struct some_struct *some_pointer)
{
kfree(some_pointer->some_item);
kfree(some_pointer);
}

That is, a structure may or may not allocate memory for various items in
the structure. They may stay as NULL. On the destructor side, instead of
testing if the items are NULL, we simply call kfree on them.

This explains why the object is not unlikely to be NULL in kfree.

Note, likely is not the same as majority of the time. If I were to say, 7%
of the next 100 days will snow. Can you say it is unlikely that it will
snow? Perhaps on a certain day it may be unlikely, but it is very likely
it will eventually snow. The same should go with the macros. If you say,
unlikely, it really should mean, I do not expect this to ever happen.
Not, the majority of the times it will not happen.

-- Steve

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/