Re: [PATCH v1 06/26] x86/virt/tdx: Add tdx_page_array helpers for new TDX Module objects

Dave Hansen
2025-11-19T18:05:41Z

On 11/19/25 08:20, dan.j.williams@intel.com wrote:
> Please document that tip prefers that goto be used in cases where a
> single goto target can be used.

I don't think it's that hard and fast of a rule. It's really just a more
general: use the best tool for the job. For instance, if your line of
code was already on the long side, the additional __free(foo) might be
the straw that breaks the camel's back.

So it all depends.

In this case, we have very linear code flow, very long lines, and quite
uniform allocator use (they can all be kfree()). That tips the scales
squarely in the direction of goto.

Dan, you were also concerned about the mental load of ensuring that the
error goto code frees objects in reverse allocation order. I certainly
understand that inclination.

But there's already code that takes that allocation order into account.
It's also going to be in this patch whether or not __free() is utilized:

> +void tdx_page_array_free(struct tdx_page_array *array)
> +{
> + if (!array)
> + return;
> +
> + __free_page(array->root);
> + tdx_free_pages_bulk(array->nr_pages, array->pages);
> + kfree(array->pages);
> + kfree(array);
> +}
Ideally, we'd be able to define the free ordering requirements in a
single bit of code and use it in both paths.