summaryrefslogtreecommitdiffstats
path: root/drivers/platform/chrome/cros_ec_debugfs.c
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2023-04-10 18:58:17 +0200
committerTzung-Bi Shih <tzungbi@kernel.org>2023-04-24 07:35:12 +0200
commit26e1dc1bef42a699734056271e790982e2ba8092 (patch)
treed866a8be6cfd601c46a83a0ba817ff710ba088d5 /drivers/platform/chrome/cros_ec_debugfs.c
parentplatform/chrome: cros_typec_switch: Add missing fwnode_handle_put() (diff)
downloadlinux-26e1dc1bef42a699734056271e790982e2ba8092.tar.xz
linux-26e1dc1bef42a699734056271e790982e2ba8092.zip
platform/chrome: cros_ec: Separate logic for getting panic info
Create a separate function called cros_ec_get_panicinfo for getting panic info from EC. Currently cros_ec_create_panicinfo is the only caller. Signed-off-by: Rob Barnes <robbarnes@google.com> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org> Link: https://lore.kernel.org/r/20230410165817.932449-1-robbarnes@google.com
Diffstat (limited to 'drivers/platform/chrome/cros_ec_debugfs.c')
-rw-r--r--drivers/platform/chrome/cros_ec_debugfs.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c
index a98c529d8c69..414ebfffcf83 100644
--- a/drivers/platform/chrome/cros_ec_debugfs.c
+++ b/drivers/platform/chrome/cros_ec_debugfs.c
@@ -400,24 +400,48 @@ static void cros_ec_cleanup_console_log(struct cros_ec_debugfs *debug_info)
}
}
-static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
+/**
+ * Returns the size of the panicinfo data fetched from the EC
+ */
+static int cros_ec_get_panicinfo(struct cros_ec_device *ec_dev, uint8_t *data,
+ int data_size)
{
- struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
int ret;
struct cros_ec_command *msg;
- int insize;
- insize = ec_dev->max_response;
+ if (!data || data_size <= 0 || data_size > ec_dev->max_response)
+ return -EINVAL;
- msg = devm_kzalloc(debug_info->ec->dev,
- sizeof(*msg) + insize, GFP_KERNEL);
+ msg = kzalloc(sizeof(*msg) + data_size, GFP_KERNEL);
if (!msg)
return -ENOMEM;
msg->command = EC_CMD_GET_PANIC_INFO;
- msg->insize = insize;
+ msg->insize = data_size;
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
+ if (ret < 0)
+ goto free;
+
+ memcpy(data, msg->data, data_size);
+
+free:
+ kfree(msg);
+ return ret;
+}
+
+static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
+{
+ struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
+ int ret;
+ void *data;
+
+ data = devm_kzalloc(debug_info->ec->dev, ec_dev->max_response,
+ GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ ret = cros_ec_get_panicinfo(ec_dev, data, ec_dev->max_response);
if (ret < 0) {
ret = 0;
goto free;
@@ -427,7 +451,7 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
if (ret == 0)
goto free;
- debug_info->panicinfo_blob.data = msg->data;
+ debug_info->panicinfo_blob.data = data;
debug_info->panicinfo_blob.size = ret;
debugfs_create_blob("panicinfo", S_IFREG | 0444, debug_info->dir,
@@ -436,7 +460,7 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
return 0;
free:
- devm_kfree(debug_info->ec->dev, msg);
+ devm_kfree(debug_info->ec->dev, data);
return ret;
}