[PATCH] cros_ec: sysfs: Fix memory leak in show/store_kb_wake_angle()

From: Jeffy Chen
Date: Fri Sep 29 2017 - 05:13:25 EST


Add missing kfree of allocated cros_ec_command.

Fixes: ff00af859354 ("platform/chrome: cros_ec: Add sysfs entry to set keyboard wake lid angle")
Signed-off-by: Jeffy Chen <jeffy.chen@xxxxxxxxxxxxxx>
---

drivers/platform/chrome/cros_ec_sysfs.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index 0fd88eb03d39..0f821dd0d5b1 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -286,10 +286,12 @@ 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,
@@ -320,8 +322,11 @@ static ssize_t store_kb_wake_angle(struct device *dev,
msg->insize = sizeof(struct ec_response_motion_sense);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0)
- return ret;
- return count;
+ goto exit;
+ ret = count;
+exit:
+ kfree(msg);
+ return ret;
}

/* Module initialization */
--
2.11.0