[PATCH] cros_ec: Fix a memory leak in show/store sysfs callbacks

From: Thierry Escande
Date: Tue Oct 24 2017 - 05:34:41 EST


This patch fixes a memory leak in the sysfs show/store callbacks of the
keyboard wake angle attribute. The EC message structure was allocated
but never freed.

Signed-off-by: Thierry Escande <thierry.escande@xxxxxxxxxxxxx>
---
drivers/platform/chrome/cros_ec_sysfs.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index 0fd88eb..cc72bd0 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -286,10 +286,14 @@ static ssize_t show_kb_wake_angle(struct device *dev,
msg->insize = sizeof(*resp);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0)
- return ret;
+ goto exit;
+
resp = (struct ec_response_motion_sense *)msg->data;
- return scnprintf(buf, PAGE_SIZE, "%d\n",
- resp->kb_wake_angle.ret);
+ ret = scnprintf(buf, PAGE_SIZE, "%d\n", resp->kb_wake_angle.ret);
+
+exit:
+ kfree(msg);
+ return ret;
}

static ssize_t store_kb_wake_angle(struct device *dev,
@@ -319,6 +323,7 @@ static ssize_t store_kb_wake_angle(struct device *dev,
msg->outsize = sizeof(*param);
msg->insize = sizeof(struct ec_response_motion_sense);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+ kfree(msg);
if (ret < 0)
return ret;
return count;
--
2.7.4