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.
Showing the changes to include/linux (1 of 1 file). Show all
Unified · Split
| @@ -805,7 +805,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) · 804 unmodified lines | ||
| 805 | 805 | /** |
| 806 | 806 | * kfree_rcu() - kfree an object after a grace period. |
| 807 | 807 | * @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 | 810 | * Many rcu callbacks functions just call kfree() on the base structure. |
| 811 | 811 | * 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 | 828 | * The BUILD_BUG_ON check must not involve any function calls, hence the |
| 829 | 829 | * checks are done in macros here. |
| 830 | 830 | */ |
| 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) | |
| 834 | 838 | |
| 835 | 839 | /* |
| 836 | 840 | * Place this after a lock-acquisition primitive to guarantee that |