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

Dave Hansen
2025-11-18T19:09:13Z

On 11/16/25 18:22, Xu Yilun wrote:
...> + struct tdx_page_array *array __free(kfree) = kzalloc(sizeof(*array),
> + GFP_KERNEL);
> + if (!array)
> + return NULL;

I just reworked this to use normal goto's. It looks a billion times
better. Please remove all these __free()'s unless you have specific
evidence that they make the code better.

Maybe I'm old fashioned, but I don't see anything wrong with:

static struct tdx_pglist *tdx_pglist_alloc(unsigned int nr_pages)
{
struct tdx_page_array *array = NULL;
struct page **pages = NULL;
struct page *root = NULL;
int ret;

if (!nr_pages)
return NULL;

array = kzalloc(sizeof(*array), GFP_KERNEL);
if (!array)
goto out_free;

root = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!root)
goto out_free;

pages = kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL);
if (!pages)
goto out_free;

ret = tdx_alloc_pages_bulk(nr_pages, pages);
if (ret)
goto out_free;

array->nr_pages = nr_pages;
array->pages = pages;
array->root = root;

return array;

out_free:
kfree(array);
kfree(root);
kfree(pages);

return NULL;
}