History

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.

Paul E. McKenney committed 7 years ago

Commit 12edff01 parent 3ae976a1 file · +8 −4Browse files

Showing the changes to include/linux (1 of 1 file). Show all

Unified · Split

include/linux/rcupdate.h+8−4
@@ -805,7 +805,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) · 804 unmodified lines
805/**805/**
806 * kfree_rcu() - kfree an object after a grace period.806 * kfree_rcu() - kfree an object after a grace period.
807 * @ptr: pointer to kfree807 * @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.
809 *809 *
810 * Many rcu callbacks functions just call kfree() on the base structure.810 * Many rcu callbacks functions just call kfree() on the base structure.
811 * These functions are trivial, but their size adds up, and furthermore811 * 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) · 16 unmodified lines
828 * The BUILD_BUG_ON check must not involve any function calls, hence the828 * The BUILD_BUG_ON check must not involve any function calls, hence the
829 * checks are done in macros here.829 * checks are done in macros here.
830 */830 */
831#define kfree_rcu(ptr, rcu_head) \831#define kfree_rcu(ptr, rhf) \
832 __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head))832do { \
833 833 typeof (ptr) ___p = (ptr); \
834 \
835 if (___p) \
836 __kfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \
837} while (0)
834 838
835/*839/*
836 * Place this after a lock-acquisition primitive to guarantee that840 * Place this after a lock-acquisition primitive to guarantee that

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t