Commit 6261ddee authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

kref: fix up the kfree build problems

It turns out that some memory allocators use kobjects, which use krefs,
and kref.h was wanting to figure out the address of kfree(), which ended
up in a loop.

kfree was only being needed for a warning to tell the caller that they
were doing something stupid.  Now we just move that warning into the
comments for the functions, which results in a bit more fun as everyone
enjoys digging for people to mock at times of boredom.

So, remove the dependancy of slab.h on kref.h, and fix up the other
include file as well (we really only need bug.h and atomic.h, not
types.h).
Reported-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Oliver Neukum <oneukum@suse.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 3c8ed889
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#ifndef _KREF_H_ #ifndef _KREF_H_
#define _KREF_H_ #define _KREF_H_
#include <linux/types.h> #include <linux/bug.h>
#include <linux/slab.h> #include <linux/atomic.h>
struct kref { struct kref {
atomic_t refcount; atomic_t refcount;
...@@ -48,7 +48,10 @@ static inline void kref_get(struct kref *kref) ...@@ -48,7 +48,10 @@ static inline void kref_get(struct kref *kref)
* @release: pointer to the function that will clean up the object when the * @release: pointer to the function that will clean up the object when the
* last reference to the object is released. * last reference to the object is released.
* This pointer is required, and it is not acceptable to pass kfree * This pointer is required, and it is not acceptable to pass kfree
* in as this function. * in as this function. If the caller does pass kfree to this
* function, you will be publicly mocked mercilessly by the kref
* maintainer, and anyone else who happens to notice it. You have
* been warned.
* *
* Subtract @count from the refcount, and if 0, call release(). * Subtract @count from the refcount, and if 0, call release().
* Return 1 if the object was removed, otherwise return 0. Beware, if this * Return 1 if the object was removed, otherwise return 0. Beware, if this
...@@ -60,7 +63,6 @@ static inline int kref_sub(struct kref *kref, unsigned int count, ...@@ -60,7 +63,6 @@ static inline int kref_sub(struct kref *kref, unsigned int count,
void (*release)(struct kref *kref)) void (*release)(struct kref *kref))
{ {
WARN_ON(release == NULL); WARN_ON(release == NULL);
WARN_ON(release == (void (*)(struct kref *))kfree);
if (atomic_sub_and_test((int) count, &kref->refcount)) { if (atomic_sub_and_test((int) count, &kref->refcount)) {
release(kref); release(kref);
...@@ -75,7 +77,10 @@ static inline int kref_sub(struct kref *kref, unsigned int count, ...@@ -75,7 +77,10 @@ static inline int kref_sub(struct kref *kref, unsigned int count,
* @release: pointer to the function that will clean up the object when the * @release: pointer to the function that will clean up the object when the
* last reference to the object is released. * last reference to the object is released.
* This pointer is required, and it is not acceptable to pass kfree * This pointer is required, and it is not acceptable to pass kfree
* in as this function. * in as this function. If the caller does pass kfree to this
* function, you will be publicly mocked mercilessly by the kref
* maintainer, and anyone else who happens to notice it. You have
* been warned.
* *
* Decrement the refcount, and if 0, call release(). * Decrement the refcount, and if 0, call release().
* Return 1 if the object was removed, otherwise return 0. Beware, if this * Return 1 if the object was removed, otherwise return 0. Beware, if this
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment