lkml.org 
[lkml]   [2023]   [Aug]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: cleanup: Make no_free_ptr() __must_check
From
On 15/08/2023 12.52, Peter Zijlstra wrote:
>
> recent discussion brought about the realization that it makes sense for
> no_free_ptr() to have __must_check semantics in order to avoid leaking
> the resource.
>

> +static inline __must_check void * __no_free_ptr(void **pp)
> +{ void *p = *pp; *pp = NULL; return p; }
> +
> #define no_free_ptr(p) \
> - ({ __auto_type __ptr = (p); (p) = NULL; __ptr; })
> + (({ void * __maybe_unused ___t = (p); }), \
> + ((typeof(p))__no_free_ptr((void **)&(p))))

So this does seem to work as advertised, but it could perhaps use some
comments. Because at first I read this as one big statement expression,
and I had this memory of a __must_check function call being the last
expression in such had no effect at all [1]. But this is actually a
comma expression.

Also, isn't it more complicated than necessary? Can we get rid of the
inner stmt expr and tmp var by just making it

((void) (p), ((typeof(p))__no_free_ptr((void **)&(p)))

which is more or less the whole reason comma expressions is a thing.

Rasmus

[1]
https://lore.kernel.org/lkml/6d190601-68f1-c086-97ac-2ee1c08f5a34@rasmusvillemoes.dk/

\
 
 \ /
  Last update: 2023-08-15 13:29    [W:0.345 / U:0.100 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site