Re: Rust kernel policy
From: James Bottomley
Date: Wed Feb 19 2025 - 10:16:09 EST
On Wed, 2025-02-19 at 09:46 -0500, Martin K. Petersen wrote:
>
> James,
>
> > Could we possibly fix a lot of this by adopting the _cleanup_
> > annotations[1]? I've been working in systemd code recently and they
> > seem to make great use of this for error leg simplification.
>
> We already have this:
>
> include/linux/cleanup.h
>
> I like using cleanup attributes for some error handling. However, I'm
> finding that in many cases I want to do a bit more than a simple
> kfree(). And at that point things get syntactically messy in the
> variable declarations and harder to read than just doing a classic
> goto style unwind.
So the way systemd solves this is that they define a whole bunch of
_cleanup_<type>_ annotations which encode the additional logic. It
does mean you need a globally defined function for each cleanup type,
but judicious use of cleanup types seems to mean they only have a few
dozen of these.
Regards,
James