diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-07 15:03:30 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-01-07 15:03:30 -0500 |
commit | 7affca3537d74365128e477b40c529d6f2fe86c8 (patch) | |
tree | 20be92bd240029182fc89c2c4f25401b7715dcae /lib/kref.c | |
parent | 356b95424cfb456e14a59eaa579422ce014c424b (diff) | |
parent | ff4b8a57f0aaa2882d444ca44b2b9b333d22a4df (diff) |
Merge branch 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
* 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (73 commits)
arm: fix up some samsung merge sysdev conversion problems
firmware: Fix an oops on reading fw_priv->fw in sysfs loading file
Drivers:hv: Fix a bug in vmbus_driver_unregister()
driver core: remove __must_check from device_create_file
debugfs: add missing #ifdef HAS_IOMEM
arm: time.h: remove device.h #include
driver-core: remove sysdev.h usage.
clockevents: remove sysdev.h
arm: convert sysdev_class to a regular subsystem
arm: leds: convert sysdev_class to a regular subsystem
kobject: remove kset_find_obj_hinted()
m86k: gpio - convert sysdev_class to a regular subsystem
mips: txx9_sram - convert sysdev_class to a regular subsystem
mips: 7segled - convert sysdev_class to a regular subsystem
sh: dma - convert sysdev_class to a regular subsystem
sh: intc - convert sysdev_class to a regular subsystem
power: suspend - convert sysdev_class to a regular subsystem
power: qe_ic - convert sysdev_class to a regular subsystem
power: cmm - convert sysdev_class to a regular subsystem
s390: time - convert sysdev_class to a regular subsystem
...
Fix up conflicts with 'struct sysdev' removal from various platform
drivers that got changed:
- arch/arm/mach-exynos/cpu.c
- arch/arm/mach-exynos/irq-eint.c
- arch/arm/mach-s3c64xx/common.c
- arch/arm/mach-s3c64xx/cpu.c
- arch/arm/mach-s5p64x0/cpu.c
- arch/arm/mach-s5pv210/common.c
- arch/arm/plat-samsung/include/plat/cpu.h
- arch/powerpc/kernel/sysfs.c
and fix up cpu_is_hotpluggable() as per Greg in include/linux/cpu.h
Diffstat (limited to 'lib/kref.c')
-rw-r--r-- | lib/kref.c | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/lib/kref.c b/lib/kref.c deleted file mode 100644 index 3efb882b11d..00000000000 --- a/lib/kref.c +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | /* | ||
2 | * kref.c - library routines for handling generic reference counted objects | ||
3 | * | ||
4 | * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com> | ||
5 | * Copyright (C) 2004 IBM Corp. | ||
6 | * | ||
7 | * based on lib/kobject.c which was: | ||
8 | * Copyright (C) 2002-2003 Patrick Mochel <mochel@osdl.org> | ||
9 | * | ||
10 | * This file is released under the GPLv2. | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #include <linux/kref.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/slab.h> | ||
17 | |||
18 | /** | ||
19 | * kref_init - initialize object. | ||
20 | * @kref: object in question. | ||
21 | */ | ||
22 | void kref_init(struct kref *kref) | ||
23 | { | ||
24 | atomic_set(&kref->refcount, 1); | ||
25 | smp_mb(); | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * kref_get - increment refcount for object. | ||
30 | * @kref: object. | ||
31 | */ | ||
32 | void kref_get(struct kref *kref) | ||
33 | { | ||
34 | WARN_ON(!atomic_read(&kref->refcount)); | ||
35 | atomic_inc(&kref->refcount); | ||
36 | smp_mb__after_atomic_inc(); | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * kref_put - decrement refcount for object. | ||
41 | * @kref: object. | ||
42 | * @release: pointer to the function that will clean up the object when the | ||
43 | * last reference to the object is released. | ||
44 | * This pointer is required, and it is not acceptable to pass kfree | ||
45 | * in as this function. | ||
46 | * | ||
47 | * Decrement the refcount, and if 0, call release(). | ||
48 | * Return 1 if the object was removed, otherwise return 0. Beware, if this | ||
49 | * function returns 0, you still can not count on the kref from remaining in | ||
50 | * memory. Only use the return value if you want to see if the kref is now | ||
51 | * gone, not present. | ||
52 | */ | ||
53 | int kref_put(struct kref *kref, void (*release)(struct kref *kref)) | ||
54 | { | ||
55 | WARN_ON(release == NULL); | ||
56 | WARN_ON(release == (void (*)(struct kref *))kfree); | ||
57 | |||
58 | if (atomic_dec_and_test(&kref->refcount)) { | ||
59 | release(kref); | ||
60 | return 1; | ||
61 | } | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | |||
66 | /** | ||
67 | * kref_sub - subtract a number of refcounts for object. | ||
68 | * @kref: object. | ||
69 | * @count: Number of recounts to subtract. | ||
70 | * @release: pointer to the function that will clean up the object when the | ||
71 | * last reference to the object is released. | ||
72 | * This pointer is required, and it is not acceptable to pass kfree | ||
73 | * in as this function. | ||
74 | * | ||
75 | * Subtract @count from the refcount, and if 0, call release(). | ||
76 | * Return 1 if the object was removed, otherwise return 0. Beware, if this | ||
77 | * function returns 0, you still can not count on the kref from remaining in | ||
78 | * memory. Only use the return value if you want to see if the kref is now | ||
79 | * gone, not present. | ||
80 | */ | ||
81 | int kref_sub(struct kref *kref, unsigned int count, | ||
82 | void (*release)(struct kref *kref)) | ||
83 | { | ||
84 | WARN_ON(release == NULL); | ||
85 | WARN_ON(release == (void (*)(struct kref *))kfree); | ||
86 | |||
87 | if (atomic_sub_and_test((int) count, &kref->refcount)) { | ||
88 | release(kref); | ||
89 | return 1; | ||
90 | } | ||
91 | return 0; | ||
92 | } | ||
93 | |||
94 | EXPORT_SYMBOL(kref_init); | ||
95 | EXPORT_SYMBOL(kref_get); | ||
96 | EXPORT_SYMBOL(kref_put); | ||
97 | EXPORT_SYMBOL(kref_sub); | ||