linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eizan Miyamoto <eizan@chromium.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Eizan Miyamoto <eizan@chromium.org>,
	Benson Leung <bleung@chromium.org>,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	Guenter Roeck <groeck@chromium.org>
Subject: [PATCH v1] platform/chrome: cros_ec_debugfs: conditionally create uptime node
Date: Wed,  8 Jul 2020 14:53:00 +1000	[thread overview]
Message-ID: <20200708145215.v1.1.I9d49b374536424fcc98bc6bd935cdab8fac2ae71@changeid> (raw)

Before creating an 'uptime' node in debugfs, this change adds a check to
see if a EC_CMD_GET_UPTIME_INFO command can be successfully run.

If the uptime node is created, userspace programs may periodically poll
it (e.g., timberslide), causing commands to be sent to the EC each time.
If the EC doesn't support EC_CMD_GET_UPTIME_INFO, an error will be
emitted in the EC console, producing noise.

Signed-off-by: Eizan Miyamoto <eizan@chromium.org>
---

 drivers/platform/chrome/cros_ec_debugfs.c | 35 +++++++++++++++++------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c
index ecfada00e6c51..8708fe12f8ca8 100644
--- a/drivers/platform/chrome/cros_ec_debugfs.c
+++ b/drivers/platform/chrome/cros_ec_debugfs.c
@@ -242,17 +242,14 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
 				       read_buf, p - read_buf);
 }
 
-static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
-				   size_t count, loff_t *ppos)
+static int cros_ec_get_uptime(struct cros_ec_device *ec_dev,
+			      uint32_t *uptime)
 {
-	struct cros_ec_debugfs *debug_info = file->private_data;
-	struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
 	struct {
 		struct cros_ec_command cmd;
 		struct ec_response_uptime_info resp;
 	} __packed msg = {};
 	struct ec_response_uptime_info *resp;
-	char read_buf[32];
 	int ret;
 
 	resp = (struct ec_response_uptime_info *)&msg.resp;
@@ -264,8 +261,24 @@ static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
 	if (ret < 0)
 		return ret;
 
-	ret = scnprintf(read_buf, sizeof(read_buf), "%u\n",
-			resp->time_since_ec_boot_ms);
+	*uptime = resp->time_since_ec_boot_ms;
+	return 0;
+}
+
+static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
+				   size_t count, loff_t *ppos)
+{
+	struct cros_ec_debugfs *debug_info = file->private_data;
+	struct cros_ec_device *ec_dev = debug_info->ec->ec_dev;
+	char read_buf[32];
+	int ret;
+	uint32_t uptime;
+
+	ret = cros_ec_get_uptime(ec_dev, &uptime);
+	if (ret < 0)
+		return ret;
+
+	ret = scnprintf(read_buf, sizeof(read_buf), "%u\n", uptime);
 
 	return simple_read_from_buffer(user_buf, count, ppos, read_buf, ret);
 }
@@ -425,6 +438,7 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
 	const char *name = ec_platform->ec_name;
 	struct cros_ec_debugfs *debug_info;
 	int ret;
+	uint32_t uptime;
 
 	debug_info = devm_kzalloc(ec->dev, sizeof(*debug_info), GFP_KERNEL);
 	if (!debug_info)
@@ -444,8 +458,11 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
 	debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info,
 			    &cros_ec_pdinfo_fops);
 
-	debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
-			    &cros_ec_uptime_fops);
+	if (cros_ec_get_uptime(debug_info->ec->ec_dev, &uptime) >= 0)
+		debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
+				    &cros_ec_uptime_fops);
+	else
+		dev_dbg(ec->dev, "EC does not provide uptime");
 
 	debugfs_create_x32("last_resume_result", 0444, debug_info->dir,
 			   &ec->ec_dev->last_resume_result);
-- 
2.27.0.383.g050319c2ae-goog


             reply	other threads:[~2020-07-08  4:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-08  4:53 Eizan Miyamoto [this message]
2020-07-09  7:25 ` [PATCH v1] platform/chrome: cros_ec_debugfs: conditionally create uptime node 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=20200708145215.v1.1.I9d49b374536424fcc98bc6bd935cdab8fac2ae71@changeid \
    --to=eizan@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).