Re: cleanup: Make no_free_ptr() __must_check

From: Peter Zijlstra
Date: Wed Aug 16 2023 - 05:18:13 EST


On Wed, Aug 16, 2023 at 08:00:17AM +0000, Linus Torvalds wrote:

> So I think it needs to be something like
>
> #define __get_and_free_ptr(p) \
> ({ __auto_type __ptr = &(p); \
> __auto_type __val = *__ptr; \
> *__ptr = NULL; __val; })
>
> static inline __must_check
> const volatile void * __must_check_fn(const volatile void *val)
> { return val; }
>
> #define no_free_ptr(p) \
> ((typeof(p)) __must_check_fn(__get_and_free_ptr(p)))
>
> the above is entirely untested. Of course.

That works and is *much* saner than the horrible thing I did.