diff --git a/[refs] b/[refs] index 68a89353f72e..496c38b54c4b 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: a6e8dc46ff0b7defbfa4f29a71aee263377ec573 +refs/heads/master: e4a683c899cd5a49f8d684a054c95bd115a0c005 diff --git a/trunk/include/linux/kref.h b/trunk/include/linux/kref.h index 6cc38fc07ab7..90b9e44abf54 100644 --- a/trunk/include/linux/kref.h +++ b/trunk/include/linux/kref.h @@ -23,6 +23,7 @@ struct kref { void kref_init(struct kref *kref); void kref_get(struct kref *kref); +int kref_test_and_get(struct kref *kref); int kref_put(struct kref *kref, void (*release) (struct kref *kref)); #endif /* _KREF_H_ */ diff --git a/trunk/lib/kref.c b/trunk/lib/kref.c index d3d227a08a4b..e7a6e1067122 100644 --- a/trunk/lib/kref.c +++ b/trunk/lib/kref.c @@ -36,6 +36,18 @@ void kref_get(struct kref *kref) smp_mb__after_atomic_inc(); } +/** + * kref_test_and_get - increment refcount for object only if refcount is not + * zero. + * @kref: object. + * + * Return non-zero if the refcount was incremented, 0 otherwise + */ +int kref_test_and_get(struct kref *kref) +{ + return atomic_inc_not_zero(&kref->refcount); +} + /** * kref_put - decrement refcount for object. * @kref: object.