Re: [PATCH v4 1/6] ACPI: Move DEFINE_FREE(acpi_free) to global header

From: Rafael J. Wysocki

Date: Fri May 08 2026 - 14:40:41 EST


On Fri, May 8, 2026 at 8:18 AM Marco Scardovi <mscardovi95@xxxxxxxxx> wrote:
>
> Introduce DEFINE_FREE(acpi_free) in include/linux/acpi.h to provide
> a standard way to perform automated memory deallocation for ACPI
> objects. This enables the use of the __free(acpi_free) attribute
> wherever ACPI_FREE() is required.

This goes a bit overboard because the objects needing ACPI_FREE() for
freeing are most of the time allocated in a way that precludes using
__free().

Note that you are expected to initialize the pointer at declaration
time when using __free() and that cannot be done with objects
allocated by ACPICA code in many cases.

> Signed-off-by: Marco Scardovi <mscardovi95@xxxxxxxxx>
> ---
> include/linux/acpi.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 67effb91fa98..f58e704ee850 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -234,6 +234,8 @@ static inline struct acpi_table_header *acpi_get_table_pointer(char *signature,
> }
> DEFINE_FREE(acpi_put_table, struct acpi_table_header *, if (!IS_ERR_OR_NULL(_T)) acpi_put_table(_T))
>
> +DEFINE_FREE(acpi_free, void *, if (_T) ACPI_FREE(_T))
> +
> int acpi_table_parse(char *id, acpi_tbl_table_handler handler);
> int __init_or_acpilib acpi_table_parse_entries(char *id,
> unsigned long table_size, int entry_id,
> --
> 2.54.0
>
>