mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] acer-wmi: fix memory leaks in wmab_execute error path
@ 2010-07-09  3:51 Axel Lin
  2010-07-09 20:53 ` Carlos Corbacho
  0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2010-07-09  3:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: Carlos Corbacho, Matthew Garrett, Thomas Renninger, Alan Jenkins,
	platform-driver-x86

When acpi_evaluate_object() is passed ACPI_ALLOCATE_BUFFER,
the caller must kfree the returned buffer if AE_OK is returned.

Call Trace:
wmab_execute
  -> wmi_evaluate_method
    -> acpi_evaluate_object

Thus if callers of wmab_execute() pass ACPI_ALLOCATE_BUFFER,
the return buffer must be kfreed if wmab_execute return AE_OK.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/platform/x86/acer-wmi.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index 1ea6c43..a158d39 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -555,6 +555,7 @@ static acpi_status AMW0_find_mailled(void)
 	obj->buffer.length == sizeof(struct wmab_ret)) {
 		ret = *((struct wmab_ret *) obj->buffer.pointer);
 	} else {
+		kfree(out.pointer);
 		return AE_ERROR;
 	}
 
@@ -598,6 +599,7 @@ static acpi_status AMW0_set_capabilities(void)
 	obj->buffer.length == sizeof(struct wmab_ret)) {
 		ret = *((struct wmab_ret *) obj->buffer.pointer);
 	} else {
+		kfree(out.pointer);
 		return AE_ERROR;
 	}
 
@@ -607,15 +609,24 @@ static acpi_status AMW0_set_capabilities(void)
 	args.ebx = 2 << 8;
 	args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
 
+	/*
+	 * It's ok to use existing buffer for next wmab_execute call.
+	 * But we need to kfree(out.pointer) if next wmab_execute call
+	 * returns AE_BUFFER_OVERFLOW.
+	 */
 	status = wmab_execute(&args, &out);
-	if (ACPI_FAILURE(status))
+	if (ACPI_FAILURE(status)) {
+		if (status == AE_BUFFER_OVERFLOW)
+			kfree(out.pointer);
 		return status;
+	}
 
 	obj = (union acpi_object *) out.pointer;
 	if (obj && obj->type == ACPI_TYPE_BUFFER
 	&& obj->buffer.length == sizeof(struct wmab_ret)) {
 		ret = *((struct wmab_ret *) obj->buffer.pointer);
 	} else {
+		kfree(out.pointer);
 		return AE_ERROR;
 	}
 
-- 
1.5.4.3




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] acer-wmi: fix memory leaks in wmab_execute error path
  2010-07-09  3:51 [PATCH] acer-wmi: fix memory leaks in wmab_execute error path Axel Lin
@ 2010-07-09 20:53 ` Carlos Corbacho
  0 siblings, 0 replies; 2+ messages in thread
From: Carlos Corbacho @ 2010-07-09 20:53 UTC (permalink / raw)
  To: Axel Lin
  Cc: linux-kernel, Matthew Garrett, Thomas Renninger, Alan Jenkins,
	platform-driver-x86

On Friday 09 July 2010 04:51:15 Axel Lin wrote:
> When acpi_evaluate_object() is passed ACPI_ALLOCATE_BUFFER,
> the caller must kfree the returned buffer if AE_OK is returned.
> 
> Call Trace:
> wmab_execute
>   -> wmi_evaluate_method
>     -> acpi_evaluate_object
> 
> Thus if callers of wmab_execute() pass ACPI_ALLOCATE_BUFFER,
> the return buffer must be kfreed if wmab_execute return AE_OK.
> 
> Signed-off-by: Axel Lin <axel.lin@gmail.com>

Acked-by: Carlos Corbacho <carlos@strangeworlds.co.uk>
-- 
E-Mail: carlos@strangeworlds.co.uk
Web: strangeworlds.co.uk
GPG Key ID: 0x23EE722D

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-09 20:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-09  3:51 [PATCH] acer-wmi: fix memory leaks in wmab_execute error path Axel Lin
2010-07-09 20:53 ` Carlos Corbacho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome