[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200130203106.201894-8-pmalani@chromium.org>
Date: Thu, 30 Jan 2020 12:30:47 -0800
From: Prashant Malani <pmalani@...omium.org>
To: linux-kernel@...r.kernel.org
Cc: Prashant Malani <pmalani@...omium.org>,
Benson Leung <bleung@...omium.org>,
Enric Balletbo i Serra <enric.balletbo@...labora.com>,
Guenter Roeck <groeck@...omium.org>
Subject: [PATCH 07/17] platform/chrome: sysfs: Use send_cmd_msg()
Replace cros_ec_cmd_xfer_status() calls to the new function
cros_ec_send_cmd_msg() which is more readable and does the message setup code.
Signed-off-by: Prashant Malani <pmalani@...omium.org>
---
drivers/platform/chrome/cros_ec_sysfs.c | 106 ++++++++++--------------
1 file changed, 42 insertions(+), 64 deletions(-)
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index 74d36b8d4f46c7..87d5bfa1fcfa61 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -52,20 +52,13 @@ static ssize_t reboot_store(struct device *dev,
{"hibernate", EC_REBOOT_HIBERNATE, 0},
{"at-shutdown", -1, EC_REBOOT_FLAG_ON_AP_SHUTDOWN},
};
- struct cros_ec_command *msg;
- struct ec_params_reboot_ec *param;
+ struct ec_params_reboot_ec param = {0};
int got_cmd = 0, offset = 0;
int i;
int ret;
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
- msg = kmalloc(sizeof(*msg) + sizeof(*param), GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
-
- param = (struct ec_params_reboot_ec *)msg->data;
-
- param->flags = 0;
+ param.flags = 0;
while (1) {
/* Find word to start scanning */
while (buf[offset] && isspace(buf[offset]))
@@ -77,9 +70,9 @@ static ssize_t reboot_store(struct device *dev,
if (!strncasecmp(words[i].str, buf+offset,
strlen(words[i].str))) {
if (words[i].flags) {
- param->flags |= words[i].flags;
+ param.flags |= words[i].flags;
} else {
- param->cmd = words[i].cmd;
+ param.cmd = words[i].cmd;
got_cmd = 1;
}
break;
@@ -96,15 +89,12 @@ static ssize_t reboot_store(struct device *dev,
goto exit;
}
- msg->version = 0;
- msg->command = EC_CMD_REBOOT_EC + ec->cmd_offset;
- msg->outsize = sizeof(*param);
- msg->insize = 0;
- ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+ ret = cros_ec_send_cmd_msg(ec->ec_dev, 0,
+ EC_CMD_REBOOT_EC + ec->cmd_offset,
+ ¶m, sizeof(param), NULL, 0);
if (ret < 0)
count = ret;
exit:
- kfree(msg);
return count;
}
@@ -116,25 +106,24 @@ static ssize_t version_show(struct device *dev,
struct ec_response_get_chip_info *r_chip;
struct ec_response_board_version *r_board;
struct cros_ec_command *msg;
+ void *ec_buf;
int ret;
int count = 0;
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
- msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
- if (!msg)
+ ec_buf = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
+ if (!ec_buf)
return -ENOMEM;
/* Get versions. RW may change. */
- msg->version = 0;
- msg->command = EC_CMD_GET_VERSION + ec->cmd_offset;
- msg->insize = sizeof(*r_ver);
- msg->outsize = 0;
- ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+ ret = cros_ec_send_cmd_msg(ec->ec_dev, 0,
+ EC_CMD_GET_VERSION + ec->cmd_offset,
+ NULL, 0, ec_buf, sizeof(*r_ver));
if (ret < 0) {
count = ret;
goto exit;
}
- r_ver = (struct ec_response_get_version *)msg->data;
+ r_ver = (struct ec_response_get_version *)ec_buf;
/* Strings should be null-terminated, but let's be sure. */
r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0';
r_ver->version_string_rw[sizeof(r_ver->version_string_rw) - 1] = '\0';
@@ -146,8 +135,10 @@ static ssize_t version_show(struct device *dev,
"Firmware copy: %s\n",
(r_ver->current_image < ARRAY_SIZE(image_names) ?
image_names[r_ver->current_image] : "?"));
+ memset(ec_buf, 0, sizeof(*msg) + EC_HOST_PARAM_SIZE);
/* Get build info. */
+ msg = (struct cros_ec_command *)ec_buf;
msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset;
msg->insize = EC_HOST_PARAM_SIZE;
ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
@@ -206,40 +197,29 @@ static ssize_t version_show(struct device *dev,
}
exit:
- kfree(msg);
+ kfree(ec_buf);
return count;
}
static ssize_t flashinfo_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
- struct ec_response_flash_info *resp;
- struct cros_ec_command *msg;
+ struct ec_response_flash_info resp = {0};
int ret;
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
- msg = kmalloc(sizeof(*msg) + sizeof(*resp), GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
-
- /* The flash info shouldn't ever change, but ask each time anyway. */
- msg->version = 0;
- msg->command = EC_CMD_FLASH_INFO + ec->cmd_offset;
- msg->insize = sizeof(*resp);
- msg->outsize = 0;
- ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+ ret = cros_ec_send_cmd_msg(ec->ec_dev, 0,
+ EC_CMD_FLASH_INFO + ec->cmd_offset,
+ NULL, 0, &resp, sizeof(resp));
if (ret < 0)
goto exit;
- resp = (struct ec_response_flash_info *)msg->data;
-
ret = scnprintf(buf, PAGE_SIZE,
"FlashSize %d\nWriteSize %d\n"
"EraseSize %d\nProtectSize %d\n",
- resp->flash_size, resp->write_block_size,
- resp->erase_block_size, resp->protect_block_size);
+ resp.flash_size, resp.write_block_size,
+ resp.erase_block_size, resp.protect_block_size);
exit:
- kfree(msg);
return ret;
}
@@ -250,29 +230,27 @@ static ssize_t kb_wake_angle_show(struct device *dev,
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct ec_response_motion_sense *resp;
struct ec_params_motion_sense *param;
- struct cros_ec_command *msg;
+ void *ec_buf;
int ret;
- msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
- if (!msg)
+ ec_buf = kmalloc(EC_HOST_PARAM_SIZE, GFP_KERNEL);
+ if (!ec_buf)
return -ENOMEM;
- param = (struct ec_params_motion_sense *)msg->data;
- msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
- msg->version = 2;
+ param = (struct ec_params_motion_sense *)ec_buf;
+ resp = (struct ec_response_motion_sense *)ec_buf;
param->cmd = MOTIONSENSE_CMD_KB_WAKE_ANGLE;
param->kb_wake_angle.data = EC_MOTION_SENSE_NO_VALUE;
- msg->outsize = sizeof(*param);
- msg->insize = sizeof(*resp);
- ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+ ret = cros_ec_send_cmd_msg(ec->ec_dev, 2,
+ EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset,
+ param, sizeof(*param), resp, sizeof(*resp));
if (ret < 0)
goto exit;
- resp = (struct ec_response_motion_sense *)msg->data;
ret = scnprintf(buf, PAGE_SIZE, "%d\n", resp->kb_wake_angle.ret);
exit:
- kfree(msg);
+ kfree(ec_buf);
return ret;
}
@@ -282,7 +260,8 @@ static ssize_t kb_wake_angle_store(struct device *dev,
{
struct cros_ec_dev *ec = to_cros_ec_dev(dev);
struct ec_params_motion_sense *param;
- struct cros_ec_command *msg;
+ struct ec_response_motion_sense *resp;
+ void *ec_buf;
u16 angle;
int ret;
@@ -290,20 +269,19 @@ static ssize_t kb_wake_angle_store(struct device *dev,
if (ret)
return ret;
- msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
- if (!msg)
+ ec_buf = kmalloc(EC_HOST_PARAM_SIZE, GFP_KERNEL);
+ if (!ec_buf)
return -ENOMEM;
- param = (struct ec_params_motion_sense *)msg->data;
- msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
- msg->version = 2;
+ param = (struct ec_params_motion_sense *)ec_buf;
+ resp = (struct ec_response_motion_sense *)ec_buf;
param->cmd = MOTIONSENSE_CMD_KB_WAKE_ANGLE;
param->kb_wake_angle.data = angle;
- msg->outsize = sizeof(*param);
- msg->insize = sizeof(struct ec_response_motion_sense);
- ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
- kfree(msg);
+ ret = cros_ec_send_cmd_msg(ec->ec_dev, 2,
+ EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset,
+ param, sizeof(*param), resp, sizeof(*resp));
+ kfree(ec_buf);
if (ret < 0)
return ret;
return count;
--
2.25.0.341.g760bfbb309-goog
Powered by blists - more mailing lists