diff options
author | 2025-03-19 11:56:38 +0100 | |
---|---|---|
committer | 2025-04-09 20:47:29 +0200 | |
commit | 092d00ead733563f6d278295e0b5c5f97558b726 (patch) | |
tree | 9b5e7e94b40f758ec02c4be122c18487b2006d82 /scripts/lib/kdoc/kdoc_files.py | |
parent | Linux 6.15-rc1 (diff) | |
download | linux-rng-092d00ead733563f6d278295e0b5c5f97558b726.tar.xz linux-rng-092d00ead733563f6d278295e0b5c5f97558b726.zip |
cleanup: Provide retain_and_null_ptr()
In cases where an allocation is consumed by another function, the
allocation needs to be retained on success or freed on failure. The code
pattern is usually:
struct foo *f = kzalloc(sizeof(*f), GFP_KERNEL);
struct bar *b;
,,,
// Initialize f
...
if (ret)
goto free;
...
bar = bar_create(f);
if (!bar) {
ret = -ENOMEM;
goto free;
}
...
return 0;
free:
kfree(f);
return ret;
This prevents using __free(kfree) on @f because there is no canonical way
to tell the cleanup code that the allocation should not be freed.
Abusing no_free_ptr() by force ignoring the return value is not really a
sensible option either.
Provide an explicit macro retain_and_null_ptr(), which NULLs the cleanup
pointer. That makes it easy to analyze and reason about.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Link: https://lore.kernel.org/all/20250319105506.083538907@linutronix.de
Diffstat (limited to 'scripts/lib/kdoc/kdoc_files.py')
0 files changed, 0 insertions, 0 deletions