Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

doc/RCU/listRCU: refine example code for eliminating stale data

This patch adjust the example code with following two purpose:

* reduce the confusion on not releasing e->lock
* emphasize e is valid and not stale with e->lock held

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Boqun Feng <boqun.feng@gmail.com>
CC: Alan Huang <mmpgouride@gmail.com>
Reviewed-by: Alan Huang <mmpgouride@gmail.com>
Link: https://lore.kernel.org/r/20250218005047.27258-1-richard.weiyang@gmail.com
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>

authored by

Wei Yang and committed by
Joel Fernandes
79ea7f43 1708bf2c

+6 -4
+6 -4
Documentation/RCU/listRCU.rst
··· 334 334 to accomplish this would be to add a ``deleted`` flag and a ``lock`` spinlock to the 335 335 ``audit_entry`` structure, and modify audit_filter_task() as follows:: 336 336 337 - static enum audit_state audit_filter_task(struct task_struct *tsk) 337 + static struct audit_entry *audit_filter_task(struct task_struct *tsk, char **key) 338 338 { 339 339 struct audit_entry *e; 340 340 enum audit_state state; ··· 346 346 if (e->deleted) { 347 347 spin_unlock(&e->lock); 348 348 rcu_read_unlock(); 349 - return AUDIT_BUILD_CONTEXT; 349 + return NULL; 350 350 } 351 351 rcu_read_unlock(); 352 352 if (state == AUDIT_STATE_RECORD) 353 353 *key = kstrdup(e->rule.filterkey, GFP_ATOMIC); 354 - return state; 354 + /* As long as e->lock is held, e is valid and 355 + * its value is not stale */ 356 + return e; 355 357 } 356 358 } 357 359 rcu_read_unlock(); 358 - return AUDIT_BUILD_CONTEXT; 360 + return NULL; 359 361 } 360 362 361 363 The ``audit_del_rule()`` function would need to set the ``deleted`` flag under the