From: Andrew Morton <akpm@osdl.org>
To: Hua Zhong <hzhong@gmail.com>
Cc: jmorris@namei.org, dwalker@mvista.com, linux-kernel@vger.kernel.org
Subject: Re: kfree(NULL)
Date: Fri, 21 Apr 2006 14:42:33 -0700 [thread overview]
Message-ID: <20060421144233.1201cf07.akpm@osdl.org> (raw)
In-Reply-To: <4449486F.8020108@gmail.com>
Hua Zhong <hzhong@gmail.com> wrote:
>
> +#define __check_likely(x, v, uv) \
those single-char identifiers are not nice.
> + ({ static int _ckl_print_nr = 0; \
> + static unsigned int _ckl_s[2]; \
> + int _ckl_r = !!(x); \
> + _ckl_s[_ckl_r]++; \
> + if ((_ckl_s[v] == _ckl_s[uv]) && (_ckl_s[v] > debug_likely_count_min_thresh) \
> + && (_ckl_print_nr < debug_likely_print_max_thresh)) { \
> + _ckl_print_nr++; \
> + printk_debug_likely("possible (un)likely misuse at %s:%d/%s()\n", \
> + __FILE__, __LINE__, __FUNCTION__); \
> + } \
> + _ckl_r; })
Kinda. It would be better to put all the counters into a linked list
struct likeliness {
char *file;
int line;
atomic_t true_count;
atomic_t false_count;
struct likeliness *next;
};
then
#define __check_likely(expr, value)
({
static struct likeliness likeliness;
do_check_likely(__FILE__, __LINE__, &likeliness, value);
})
...
static struct likeliness *likeliness_list;
void do_check_likely(char *file, int line, struct likeliness *likeliness,
int value)
{
static DEFINE_SPINLOCK(lock);
unsigned long flags;
if (!likeliness->next) {
if (!spin_trylock_irqsave(&lock, flags))
return; /* Can be called from NMI */
if (!likeliness->next) {
likeliness->next = likeliness_list;
likeliness_list = likeliness;
likeliness->file = file;
likeliness->line = line;
}
spin_unlock_irqsave(&lock, flags);
}
if (value)
atomic_inc(&likeliness->true_count);
else
atomic_inc(&likeliness->false_count);
}
EXPORT_SYMBOL(do_check_likely);
then write a thingy to dump the linked list (sysrq&printk if it's a hack,
/proc handler if not).
It'll crash if a module gets registered then unloaded.
CONFIG_MODULE_UNLOAD=n would be required.
next prev parent reply other threads:[~2006-04-21 21:40 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-21 21:02 kfree(NULL) Hua Zhong
2006-04-21 21:11 ` kfree(NULL) Daniel Walker
2006-04-21 21:36 ` kfree(NULL) Michael Buesch
2006-04-21 21:42 ` Andrew Morton [this message]
2006-04-21 21:48 ` kfree(NULL) Andrew Morton
2006-04-21 22:53 ` kfree(NULL) Hua Zhong
2006-04-21 22:58 ` kfree(NULL) Daniel Walker
2006-04-21 23:03 ` kfree(NULL) Hua Zhong
2006-04-21 23:25 ` kfree(NULL) Andrew Morton
2006-04-21 23:27 ` kfree(NULL) Andrew Morton
2006-04-22 11:18 ` kfree(NULL) Jan Engelhardt
-- strict thread matches above, loose matches on Subject: below --
2006-04-22 12:05 kfree(NULL) linux
[not found] <63XWg-1IL-5@gated-at.bofh.it>
[not found] ` <63YfP-26I-11@gated-at.bofh.it>
[not found] ` <63ZEY-45n-27@gated-at.bofh.it>
2006-04-21 15:25 ` kfree(NULL) Tilman Schmidt
2006-04-21 16:03 ` kfree(NULL) Daniel Walker
2006-04-21 17:48 ` kfree(NULL) Jörn Engel
2006-04-21 18:00 ` kfree(NULL) Steven Rostedt
2006-04-21 18:42 ` kfree(NULL) Daniel Walker
2006-04-21 18:56 ` kfree(NULL) Steven Rostedt
2006-04-21 19:26 ` kfree(NULL) Andrew Morton
2006-04-21 7:03 kfree(NULL) Daniel Walker
2006-04-21 7:22 ` kfree(NULL) James Morris
2006-04-21 8:54 ` kfree(NULL) Andrew Morton
2006-04-21 13:56 ` kfree(NULL) Vernon Mauery
2006-04-21 14:07 ` kfree(NULL) Dmitry Fedorov
2006-04-21 15:07 ` kfree(NULL) Jan Engelhardt
2006-04-21 19:22 ` kfree(NULL) Adrian Bunk
2006-04-21 20:30 ` kfree(NULL) Vernon Mauery
2006-04-21 20:54 ` kfree(NULL) Steven Rostedt
2006-04-21 21:38 ` kfree(NULL) Adrian Bunk
2006-04-22 11:56 ` kfree(NULL) Jörn Engel
2006-04-21 23:55 ` kfree(NULL) Paul Mackerras
2006-04-22 7:43 ` kfree(NULL) Pekka Enberg
2006-04-22 8:48 ` kfree(NULL) Paul Mackerras
2006-04-22 15:02 ` kfree(NULL) Pekka Enberg
2006-04-22 18:57 ` kfree(NULL) Hua Zhong
2006-04-22 19:05 ` kfree(NULL) Nick Piggin
2006-04-22 19:22 ` kfree(NULL) Hua Zhong
2006-04-22 19:25 ` kfree(NULL) Nick Piggin
2006-04-22 20:18 ` kfree(NULL) Jan Engelhardt
2006-04-23 16:50 ` kfree(NULL) Steven Rostedt
2006-04-22 11:34 ` kfree(NULL) Jesper Juhl
2006-04-21 14:06 ` kfree(NULL) Daniel Walker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060421144233.1201cf07.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=dwalker@mvista.com \
--cc=hzhong@gmail.com \
--cc=jmorris@namei.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox