All of lore.kernel.org
 help / color / mirror / Atom feed
From: Prashant Malani <pmalani@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: Prashant Malani <pmalani@chromium.org>,
	Benson Leung <bleung@chromium.org>,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	Guenter Roeck <groeck@chromium.org>
Subject: [PATCH 07/17] platform/chrome: sysfs: Use send_cmd_msg()
Date: Thu, 30 Jan 2020 12:30:47 -0800	[thread overview]
Message-ID: <20200130203106.201894-8-pmalani@chromium.org> (raw)
In-Reply-To: <20200130203106.201894-1-pmalani@chromium.org>

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@chromium.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,
+				   &param, 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


  parent reply	other threads:[~2020-01-30 20:34 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-30 20:30 [PATCH 00/17] platform/chrome: Replace cros_ec_cmd_xfer_status Prashant Malani
2020-01-30 20:30 ` Prashant Malani
2020-01-30 20:30 ` [PATCH 01/17] platform/chrome: Add EC command msg wrapper Prashant Malani
2020-02-03 15:27   ` Enric Balletbo i Serra
2020-02-03 18:24     ` Prashant Malani
2020-01-30 20:30 ` [PATCH 02/17] platform/chrome: chardev: Use send_cmd_msg() Prashant Malani
2020-01-30 20:30 ` [PATCH 03/17] platform/chrome: proto: Use send_cmd_msg Prashant Malani
2020-01-30 20:30 ` [PATCH 04/17] platform/chrome: usbpd_logger: Use cmd_send_msg() Prashant Malani
2020-01-30 20:30 ` [PATCH 05/17] platform/chrome: sensorhub: Use send_cmd_msg() Prashant Malani
2020-01-30 20:30 ` [PATCH 06/17] platform/chrome: debugfs: " Prashant Malani
2020-01-30 20:30 ` Prashant Malani [this message]
2020-01-30 20:30 ` [PATCH 08/17] extcon: cros_ec: Use cros_ec_send_cmd_msg() Prashant Malani
2020-01-30 20:30 ` [PATCH 09/17] hid: google-hammer: " Prashant Malani
2020-01-30 20:30 ` [PATCH 10/17] iio: cros_ec: " Prashant Malani
2020-02-02  9:43   ` Jonathan Cameron
2020-02-03 18:31     ` Prashant Malani
2020-01-30 20:30 ` [PATCH 11/17] ASoC: cros_ec_codec: " Prashant Malani
2020-01-30 20:30   ` [alsa-devel] " Prashant Malani
2020-02-01 11:03   ` Mark Brown
2020-02-01 11:03     ` [alsa-devel] " Mark Brown
2020-02-03 18:42     ` Prashant Malani
2020-02-03 18:42       ` [alsa-devel] " Prashant Malani
2020-01-30 20:30 ` [PATCH 12/17] power: supply: cros: " Prashant Malani
2020-01-30 20:31 ` [PATCH 13/17] pwm: cros-ec: Remove cros_ec_cmd_xfer_status() Prashant Malani
2020-01-30 20:31   ` Prashant Malani
2020-02-03 15:33   ` Enric Balletbo i Serra
2020-02-03 18:26     ` Prashant Malani
2020-02-03 18:39       ` Prashant Malani
2020-01-30 20:31 ` [PATCH 14/17] rtc: cros-ec: Use cros_ec_send_cmd_msg() Prashant Malani
2020-01-30 20:31 ` [PATCH 15/17] media: cros-ec-cec: " Prashant Malani
2020-02-02 22:08   ` kbuild test robot
2020-02-02 22:08     ` kbuild test robot
2020-02-03  5:35   ` kbuild test robot
2020-02-03  5:35     ` kbuild test robot
2020-01-30 20:31 ` [PATCH 16/17] i2c: cros-ec-tunnel: " Prashant Malani
2020-01-30 20:31   ` Prashant Malani
2020-01-30 20:31 ` [PATCH 17/17] platform/chrome: Drop cros_ec_cmd_xfer_status() Prashant Malani
2020-02-03 15:35   ` Enric Balletbo i Serra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200130203106.201894-8-pmalani@chromium.org \
    --to=pmalani@chromium.org \
    --cc=bleung@chromium.org \
    --cc=enric.balletbo@collabora.com \
    --cc=groeck@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.