Skip to contentSkip to conversation

vfio/platform: Remove the ACPI buffer memory to fix memory leak

PATCH In review Hanjun Guo 3 participants 4 messages Nov 22, 2022 – Nov 30, 2022

Subsystems (3)
lore
Share & tools
lore

Hanjun Guo

author
#0 lore raw

PATCH 1/1 vfio/platform: Remove the ACPI buffer memory to fix memory leak

The ACPI buffer memory (buffer.pointer) returned by acpi_evaluate_object() is not used after the call of _RST method, so it leads to memory leak.

For the calling of ACPI _RST method, we don't need to pass a buffer for acpi_evaluate_object(), we can just pass NULL and remove the ACPI buffer memory in vfio_platform_acpi_call_reset(), then we don't need to free the memory and no memory leak.

Fixes d30daa33ec1d ("vfio: platform: call _RST method when using ACPI")
---
 drivers/vfio/platform/vfio_platform_common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +1 -2
index 55dc4f4..1a0a238 100644
@@ -72,12 +72,11 @@ static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev,
 				  const char **extra_dbg)
 {
 #ifdef CONFIG_ACPI
-	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 	struct device *dev = vdev->device;
 	acpi_handle handle = ACPI_HANDLE(dev);
 	acpi_status acpi_ret;
 
-	acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, &buffer);
+	acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, NULL);
 	if (ACPI_FAILURE(acpi_ret)) {
 		if (extra_dbg)
 			*extra_dbg = acpi_format_exception(acpi_ret);
Signature · 1 line
1.7.12.4
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 22 lines · Hanjun Guo

The ACPI buffer memory (buffer.pointer) returned by acpi_evaluate_object() is not used after the call of _RST method, so it leads to memory leak.

For the calling of ACPI _RST method, we don't need to pass a buffer for acpi_evaluate_object(), we can just pass NULL and remove the ACPI buffer memory in vfio_platform_acpi_call_reset(), then we don't need to free the memory and no memory leak.

Fixes d30daa33ec1d ("vfio: platform: call _RST method when using ACPI")
---
 drivers/vfio/platform/vfio_platform_common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +0 -0
index 55dc4f4..1a0a238 100644
@@ -72,12 +72,11 @@ static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev,
 				  const char **extra_dbg)
 {
 #ifdef CONFIG_ACPI

drivers/vfio/platform/vfio_platform_common.c static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev, · line 82

Quoted 10 lines
drivers/vfio/platform/vfio_platform_common.c +1 -2
-	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 	struct device *dev = vdev->device;
 	acpi_handle handle = ACPI_HANDLE(dev);
 	acpi_status acpi_ret;
 
-	acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, &buffer);
+	acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, NULL);
 	if (ACPI_FAILURE(acpi_ret)) {
 		if (extra_dbg)
 			*extra_dbg = acpi_format_exception(acpi_ret);

Thank you for the fix!

Eric

#2 lore raw
In reply to Hanjun Guo
Quoted 22 lines · On Tue, 22 Nov 2022 19:29:58 +0800 Hanjun Guo <[email protected]> wrote:

The ACPI buffer memory (buffer.pointer) returned by acpi_evaluate_object() is not used after the call of _RST method, so it leads to memory leak.

For the calling of ACPI _RST method, we don't need to pass a buffer for acpi_evaluate_object(), we can just pass NULL and remove the ACPI buffer memory in vfio_platform_acpi_call_reset(), then we don't need to free the memory and no memory leak.

Fixes d30daa33ec1d ("vfio: platform: call _RST method when using ACPI")
---
 drivers/vfio/platform/vfio_platform_common.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +0 -0
index 55dc4f4..1a0a238 100644
@@ -72,12 +72,11 @@ static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev,
 				  const char **extra_dbg)
 {
 #ifdef CONFIG_ACPI

drivers/vfio/platform/vfio_platform_common.c static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev, · line 82

Quoted 10 lines
drivers/vfio/platform/vfio_platform_common.c +1 -2
-	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 	struct device *dev = vdev->device;
 	acpi_handle handle = ACPI_HANDLE(dev);
 	acpi_status acpi_ret;
 
-	acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, &buffer);
+	acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, NULL);
 	if (ACPI_FAILURE(acpi_ret)) {
 		if (extra_dbg)
 			*extra_dbg = acpi_format_exception(acpi_ret);

An identical change was already posted and accepted into the vfio next branch, see:

https://lore.kernel.org/all/[email protected]/

In linux-next as:

e67e070632a6 ("vfio: platform: Do not pass return buffer to ACPI _RST method")

Thanks,
Alex

author
#3 lore raw
Quoted 39 lines · Alex Williamson
Quoted 22 lines · On Tue, 22 Nov 2022 19:29:58 +0800 Hanjun Guo <[email protected]> wrote:

The ACPI buffer memory (buffer.pointer) returned by acpi_evaluate_object() is not used after the call of _RST method, so it leads to memory leak.

For the calling of ACPI _RST method, we don't need to pass a buffer for acpi_evaluate_object(), we can just pass NULL and remove the ACPI buffer memory in vfio_platform_acpi_call_reset(), then we don't need to free the memory and no memory leak.

Fixes d30daa33ec1d ("vfio: platform: call _RST method when using ACPI")
---
  drivers/vfio/platform/vfio_platform_common.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/vfio/platform/vfio_platform_common.c +0 -0
index 55dc4f4..1a0a238 100644
@@ -72,12 +72,11 @@ static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev,
  				  const char **extra_dbg)
  {
  #ifdef CONFIG_ACPI

drivers/vfio/platform/vfio_platform_common.c static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev, · line 82

Quoted 10 lines
drivers/vfio/platform/vfio_platform_common.c +1 -2
-	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  	struct device *dev = vdev->device;
  	acpi_handle handle = ACPI_HANDLE(dev);
  	acpi_status acpi_ret;
 
-	acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, &buffer);
+	acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, NULL);
  	if (ACPI_FAILURE(acpi_ret)) {
  		if (extra_dbg)
  			*extra_dbg = acpi_format_exception(acpi_ret);

An identical change was already posted and accepted into the vfio next branch, see:

Quoted 5 lines

https://lore.kernel.org/all/[email protected]/

In linux-next as:

e67e070632a6 ("vfio: platform: Do not pass return buffer to ACPI _RST method")

Thanks, I missed this patch, please drop this one.

Thanks
Hanjun