Commit e4467fb6 authored by Wenwen Wang's avatar Wenwen Wang Committed by Greg Kroah-Hartman

ACPI: custom_method: fix memory leaks

[ Upstream commit 03d1571d ]

In cm_write(), 'buf' is allocated through kzalloc(). In the following
execution, if an error occurs, 'buf' is not deallocated, leading to memory
leaks. To fix this issue, free 'buf' before returning the error.

Fixes: 526b4af4 ("ACPI: Split out custom_method functionality into an own driver")
Signed-off-by: default avatarWenwen Wang <wenwen@cs.uga.edu>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 6fceb241
...@@ -48,8 +48,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf, ...@@ -48,8 +48,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
if ((*ppos > max_size) || if ((*ppos > max_size) ||
(*ppos + count > max_size) || (*ppos + count > max_size) ||
(*ppos + count < count) || (*ppos + count < count) ||
(count > uncopied_bytes)) (count > uncopied_bytes)) {
kfree(buf);
return -EINVAL; return -EINVAL;
}
if (copy_from_user(buf + (*ppos), user_buf, count)) { if (copy_from_user(buf + (*ppos), user_buf, count)) {
kfree(buf); kfree(buf);
...@@ -69,6 +71,7 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf, ...@@ -69,6 +71,7 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE); add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
} }
kfree(buf);
return count; return count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment