lib: Update hash.h documentation to warn of a possible crash

Multiple deletions from the hash_walk or hash_iteration calls
during a single invocation of the passed in function can and
will cause the program to crash.  Warn against doing such a
thing.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit 341743ac5b)
This commit is contained in:
Donald Sharp 2021-12-01 17:03:38 -05:00 committed by mergify-bot
parent c32c32c931
commit 21ab672e6c

View File

@ -235,9 +235,10 @@ extern void *hash_release(struct hash *hash, void *data);
/* /*
* Iterate over the elements in a hash table. * Iterate over the elements in a hash table.
* *
* It is safe to delete items passed to the iteration function from the hash * The passed in arg to the handler function is the only safe
* table during iteration. More than one item cannot be deleted during each * item to delete from the hash.
* iteration. Please note that adding entries to the hash *
* Please note that adding entries to the hash
* during the walk will cause undefined behavior in that some new entries * during the walk will cause undefined behavior in that some new entries
* will be walked and some will not. So do not do this. * will be walked and some will not. So do not do this.
* *
@ -258,8 +259,10 @@ extern void hash_iterate(struct hash *hash,
/* /*
* Iterate over the elements in a hash table, stopping on condition. * Iterate over the elements in a hash table, stopping on condition.
* *
* It is safe to delete items passed to the iteration function from the hash * The passed in arg to the handler function is the only safe item
* table during iteration. Please note that adding entries to the hash * to delete from the hash.
*
* Please note that adding entries to the hash
* during the walk will cause undefined behavior in that some new entries * during the walk will cause undefined behavior in that some new entries
* will be walked and some will not. So do not do this. * will be walked and some will not. So do not do this.
* *