diff options
| author | Thomas Gleixner <tglx@linutronix.de> | 2025-03-13 16:03:38 +0300 | 
|---|---|---|
| committer | Thomas Gleixner <tglx@linutronix.de> | 2025-03-13 20:57:59 +0300 | 
| commit | 08549ff3e53b9c7bc55724d660ca733041a8bd5f (patch) | |
| tree | 327e786a661fca148da577c405993def2467f4a7 /tools/perf/scripts/python | |
| parent | 537625233537179cb2e8293b2c0dc9c989363f41 (diff) | |
| download | linux-08549ff3e53b9c7bc55724d660ca733041a8bd5f.tar.xz | |
cleanup: Provide retain_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_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>
Link: https://lore.kernel.org/all/20250313130321.442025758@linutronix.de
Diffstat (limited to 'tools/perf/scripts/python')
0 files changed, 0 insertions, 0 deletions
