diff mbox series

ACPI: custom_method: fix a possible memory leak

Message ID 20231111132402.4142-1-shiqiang.deng213@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series ACPI: custom_method: fix a possible memory leak | expand

Commit Message

shiqiang.deng Nov. 11, 2023, 1:24 p.m. UTC
In the cm_write() function, memory is allocated,
and at the end of the function when uncopied_bytes is 0,
the memory is freed. If uncopied_bytes is not equal to 0,
a memory leak occurs.

Signed-off-by: shiqiang.deng <shiqiang.deng213@gmail.com>
---
 drivers/acpi/custom_method.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Rafael J. Wysocki Nov. 12, 2023, 2:43 p.m. UTC | #1
On Sat, Nov 11, 2023 at 2:25 PM shiqiang.deng
<shiqiang.deng213@gmail.com> wrote:
>
> In the cm_write() function, memory is allocated,
> and at the end of the function when uncopied_bytes is 0,
> the memory is freed. If uncopied_bytes is not equal to 0,
> a memory leak occurs.
>
> Signed-off-by: shiqiang.deng <shiqiang.deng213@gmail.com>
> ---
>  drivers/acpi/custom_method.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
> index d39a9b474727..5103c7c3a6ce 100644
> --- a/drivers/acpi/custom_method.c
> +++ b/drivers/acpi/custom_method.c
> @@ -77,6 +77,9 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
>                 if (ACPI_FAILURE(status))
>                         return -EINVAL;
>                 add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
> +       } else {
> +               kfree(buf);
> +               buf = NULL;
>         }
>
>         return count;
> --

That was discussed in the past and I still would rather drop this I/F
completely instead of patching it for minor issues.
diff mbox series

Patch

diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
index d39a9b474727..5103c7c3a6ce 100644
--- a/drivers/acpi/custom_method.c
+++ b/drivers/acpi/custom_method.c
@@ -77,6 +77,9 @@  static ssize_t cm_write(struct file *file, const char __user *user_buf,
 		if (ACPI_FAILURE(status))
 			return -EINVAL;
 		add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
+	} else {
+		kfree(buf);
+		buf = NULL;
 	}
 
 	return count;