Commit 6261ddee70174372d6a75601f40719b7a5392f3f

Authored by Greg Kroah-Hartman
1 parent 3c8ed88974

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: Stephen 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: Greg Kroah-Hartman <gregkh@suse.de>

Showing 1 changed file with 10 additions and 5 deletions Side-by-side Diff

include/linux/kref.h
... ... @@ -15,8 +15,8 @@
15 15 #ifndef _KREF_H_
16 16 #define _KREF_H_
17 17  
18   -#include <linux/types.h>
19   -#include <linux/slab.h>
  18 +#include <linux/bug.h>
  19 +#include <linux/atomic.h>
20 20  
21 21 struct kref {
22 22 atomic_t refcount;
... ... @@ -48,7 +48,10 @@
48 48 * @release: pointer to the function that will clean up the object when the
49 49 * last reference to the object is released.
50 50 * This pointer is required, and it is not acceptable to pass kfree
51   - * in as this function.
  51 + * in as this function. If the caller does pass kfree to this
  52 + * function, you will be publicly mocked mercilessly by the kref
  53 + * maintainer, and anyone else who happens to notice it. You have
  54 + * been warned.
52 55 *
53 56 * Subtract @count from the refcount, and if 0, call release().
54 57 * Return 1 if the object was removed, otherwise return 0. Beware, if this
... ... @@ -60,7 +63,6 @@
60 63 void (*release)(struct kref *kref))
61 64 {
62 65 WARN_ON(release == NULL);
63   - WARN_ON(release == (void (*)(struct kref *))kfree);
64 66  
65 67 if (atomic_sub_and_test((int) count, &kref->refcount)) {
66 68 release(kref);
... ... @@ -75,7 +77,10 @@
75 77 * @release: pointer to the function that will clean up the object when the
76 78 * last reference to the object is released.
77 79 * This pointer is required, and it is not acceptable to pass kfree
78   - * in as this function.
  80 + * in as this function. If the caller does pass kfree to this
  81 + * function, you will be publicly mocked mercilessly by the kref
  82 + * maintainer, and anyone else who happens to notice it. You have
  83 + * been warned.
79 84 *
80 85 * Decrement the refcount, and if 0, call release().
81 86 * Return 1 if the object was removed, otherwise return 0. Beware, if this