Skip to content

Commit 12edff0

Browse files
author
Paul E. McKenney
committed
rcu: Make kfree_rcu() ignore NULL pointers
This commit makes the kfree_rcu() macro's semantics be consistent with the likes of kfree() by adding a check for NULL pointers, so that kfree_rcu(NULL, ...) is a no-op. Reported-by: Andriy Shevchenko <[email protected]> Reported-by: Christoph Hellwig <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Andriy Shevchenko <[email protected]>
1 parent 3ae976a commit 12edff0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

include/linux/rcupdate.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
805805
/**
806806
* kfree_rcu() - kfree an object after a grace period.
807807
* @ptr: pointer to kfree
808-
* @rcu_head: the name of the struct rcu_head within the type of @ptr.
808+
* @rhf: the name of the struct rcu_head within the type of @ptr.
809809
*
810810
* Many rcu callbacks functions just call kfree() on the base structure.
811811
* These functions are trivial, but their size adds up, and furthermore
@@ -828,9 +828,13 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
828828
* The BUILD_BUG_ON check must not involve any function calls, hence the
829829
* checks are done in macros here.
830830
*/
831-
#define kfree_rcu(ptr, rcu_head) \
832-
__kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))
833-
831+
#define kfree_rcu(ptr, rhf) \
832+
do { \
833+
typeof (ptr) ___p = (ptr); \
834+
\
835+
if (___p) \
836+
__kfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \
837+
} while (0)
834838

835839
/*
836840
* Place this after a lock-acquisition primitive to guarantee that

0 commit comments

Comments
 (0)