From: "YOSHIFUJI Hideaki / 吉藤英明" <yoshfuji@linux-ipv6.org>
To: ralph@inputplus.co.uk
Cc: juhl-lkml@dif.dk, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] don't do pointless NULL checks and casts before kfree() in security/
Date: Sun, 20 Mar 2005 23:04:24 +0900 (JST) [thread overview]
Message-ID: <20050320.230424.60656592.yoshfuji@linux-ipv6.org> (raw)
In-Reply-To: <200503201331.j2KDVhm12383@blake.inputplus.co.uk>
In article <200503201331.j2KDVhm12383@blake.inputplus.co.uk> (at Sun, 20 Mar 2005 13:31:43 +0000), Ralph Corderoy <ralph@inputplus.co.uk> says:
> > the short version also have the real bennefits of generating shorter
> > and faster code as well as being shorter "on-screen".
>
> Faster code? I'd have thought avoiding the function call outweighed the
> overhead of checking before calling.
Modern CPU can run nicely (expecially with register parameters).
Even if even matters, we can check inline like this:
Signed-off-by: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
===== include/linux/slab.h 1.40 vs edited =====
--- 1.40/include/linux/slab.h 2005-03-12 05:32:31 +09:00
+++ edited/include/linux/slab.h 2005-03-20 22:47:57 +09:00
@@ -106,8 +106,17 @@
}
extern void *kcalloc(size_t, size_t, int);
-extern void kfree(const void *);
+extern void __kfree(const void *);
extern unsigned int ksize(const void *);
+
+static inline void kfree(const void *p)
+{
+#ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE
+ if (!p)
+ return;
+#endif
+ __kfree(p);
+}
extern int FASTCALL(kmem_cache_reap(int));
extern int FASTCALL(kmem_ptr_validate(kmem_cache_t *cachep, void *ptr));
===== mm/slab.c 1.156 vs edited =====
--- 1.156/mm/slab.c 2005-03-10 17:38:21 +09:00
+++ edited/mm/slab.c 2005-03-20 22:42:45 +09:00
@@ -2561,7 +2561,7 @@
EXPORT_SYMBOL(kcalloc);
/**
- * kfree - free previously allocated memory
+ * __kfree - free previously allocated memory
* @objp: pointer returned by kmalloc.
*
* Don't free memory not originally allocated by kmalloc()
@@ -2572,8 +2572,10 @@
kmem_cache_t *c;
unsigned long flags;
+#ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
if (!objp)
return;
+#endif
local_irq_save(flags);
kfree_debugcheck(objp);
c = GET_PAGE_CACHE(virt_to_page(objp));
@@ -2581,7 +2583,7 @@
local_irq_restore(flags);
}
-EXPORT_SYMBOL(kfree);
+EXPORT_SYMBOL(__kfree);
#ifdef CONFIG_SMP
/**
next prev parent reply other threads:[~2005-03-20 14:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-20 12:29 Jesper Juhl
2005-03-20 12:50 ` Ralph Corderoy
2005-03-20 13:18 ` Jesper Juhl
2005-03-20 13:31 ` Ralph Corderoy
2005-03-20 14:04 ` YOSHIFUJI Hideaki / 吉藤英明 [this message]
2005-03-20 14:39 ` Jesper Juhl
2005-03-21 10:17 ` Ralph Corderoy
2005-03-22 15:00 ` Stephen Smalley
2005-03-22 20:57 ` [PATCH] don't do pointless NULL checks and casts before kfree() in security/selinux/ Jesper Juhl
2005-03-22 15:34 ` [PATCH] don't do pointless NULL checks and casts before kfree() in security/ David Howells
2005-03-22 20:46 ` Jesper Juhl
[not found] <fa.p25ihnj.4026at@ifi.uio.no>
[not found] ` <fa.iqmuavi.o6kfai@ifi.uio.no>
2005-03-20 13:18 ` Bodo Eggert
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=20050320.230424.60656592.yoshfuji@linux-ipv6.org \
--to=yoshfuji@linux-ipv6.org \
--cc=juhl-lkml@dif.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=ralph@inputplus.co.uk \
/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
all inboxes | Powered by JetHome®