Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPI / TPM: fix memory leak when walking ACPI namespace

In function ppi_callback(), memory allocated by acpi_get_name() will get
leaked when current device isn't the desired TPM device, so fix the
memory leak.

Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Jiang Liu and committed by
Rafael J. Wysocki
df45c712 d6e0a2dd

+9 -6
+9 -6
drivers/char/tpm/tpm_ppi.c
··· 27 27 static acpi_status ppi_callback(acpi_handle handle, u32 level, void *context, 28 28 void **return_value) 29 29 { 30 - acpi_status status; 30 + acpi_status status = AE_OK; 31 31 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 32 - status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer); 33 - if (strstr(buffer.pointer, context) != NULL) { 34 - *return_value = handle; 32 + 33 + if (ACPI_SUCCESS(acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer))) { 34 + if (strstr(buffer.pointer, context) != NULL) { 35 + *return_value = handle; 36 + status = AE_CTRL_TERMINATE; 37 + } 35 38 kfree(buffer.pointer); 36 - return AE_CTRL_TERMINATE; 37 39 } 38 - return AE_OK; 40 + 41 + return status; 39 42 } 40 43 41 44 static inline void ppi_assign_params(union acpi_object params[4],