Hi, In v3, I decided to drop the scope_guard_cond() usage (which meant dropping the event patch). Given the discussion on the cond_guard() patches, I think it's better to hold those conversions a bit since Linus came with a suggestion that will potentially change scope_guard_cond() - and for the better IMO. Another significant change is the __free(kfree) in all allocations in inkern.c. I have to admit that I'm not a fan of the in place declaration (too much time looking at kernel code I guess) but it makes the style more consistent (as we are doing the automatic cleanup in the locks). v1: * https://lore.kernel.org/all/20240221-iio-use-cleanup-magic-v1-0-f9c292666f26@xxxxxxxxxx/ v2: * https://lore.kernel.org/r/20240223-iio-use-cleanup-magic-v2-0-f6b4848c1f34@xxxxxxxxxx v3: - Patch 1: * Do not use scope_guard_cond(); * Directly return -ENODEV and don't initialize ret. - Patch 2: * Removed bonus space; * Used the normal error check flow in iio_trigger_get_irq(). - Patch 3: * Refactored the state and ret conditions in iio_scan_mask_query(); * Removed ternary operator check in enable_store(). - Patch 4: * Still use goto at the error patch in iio_map_array_unregister_locked(); * Used __free(kfree) + return_ptr() in places where allocations are done; * Keep the else branch in iio_read_channel_processed_scale(); * Removed the comment in iio_channel_read_min(). --- Nuno Sa (4): iio: core: move to cleanup.h magic iio: trigger: move to the cleanup.h magic iio: buffer: iio: core: move to the cleanup.h magic iio: inkern: move to the cleanup.h magic drivers/iio/industrialio-buffer.c | 122 +++++++----------- drivers/iio/industrialio-core.c | 34 ++--- drivers/iio/industrialio-trigger.c | 71 +++++------ drivers/iio/inkern.c | 255 +++++++++++++------------------------ 4 files changed, 176 insertions(+), 306 deletions(-) --- base-commit: 3cc5ebd3a2d6247aeba81873d6b040d5d87f7db1 change-id: 20240223-iio-use-cleanup-magic-9efe3b0a073d -- Thanks! - Nuno Sá