linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] platform: cros_ec_debugfs: control uptime information request
@ 2020-05-26 18:53 Gwendal Grignou
  2020-06-25 11:53 ` Enric Balletbo i Serra
  0 siblings, 1 reply; 2+ messages in thread
From: Gwendal Grignou @ 2020-05-26 18:53 UTC (permalink / raw)
  To: groeck, bleung, enric.balletbo, twawrzynczak
  Cc: linux-kernel, Gwendal Grignou

When EC does not support uptime command (EC_CMD_GET_UPTIME_INFO),
do not create the uptime sysfs entry point.
User space application will not probe the file needlessly.

The EC console log will not contain EC_CMD_GET_UPTIME_INFO anymore.

Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
 drivers/platform/chrome/cros_ec_debugfs.c | 24 +++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c
index 6ae484989d1f5..303a8c4686f89 100644
--- a/drivers/platform/chrome/cros_ec_debugfs.c
+++ b/drivers/platform/chrome/cros_ec_debugfs.c
@@ -243,6 +243,25 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
 				       read_buf, p - read_buf);
 }
 
+static bool cros_ec_uptime_is_supported(struct cros_ec_device *ec_dev)
+{
+	struct {
+		struct cros_ec_command cmd;
+		struct ec_response_uptime_info resp;
+	} __packed msg = {};
+	int ret;
+
+	msg.cmd.command = EC_CMD_GET_UPTIME_INFO;
+	msg.cmd.insize = sizeof(msg.resp);
+
+	ret = cros_ec_cmd_xfer_status(ec_dev, &msg.cmd);
+	if (ret == -EPROTO && msg.cmd.result == EC_RES_INVALID_COMMAND)
+		return false;
+
+	/* Other errors maybe a transient error, do not rule about support. */
+	return true;
+}
+
 static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
 				   size_t count, loff_t *ppos)
 {
@@ -445,8 +464,9 @@ 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_uptime_is_supported(ec->ec_dev))
+		debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
+				    &cros_ec_uptime_fops);
 
 	debugfs_create_x32("last_resume_result", 0444, debug_info->dir,
 			   &ec->ec_dev->last_resume_result);
-- 
2.27.0.rc0.183.gde8f92d652-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] platform: cros_ec_debugfs: control uptime information request
  2020-05-26 18:53 [PATCH v2] platform: cros_ec_debugfs: control uptime information request Gwendal Grignou
@ 2020-06-25 11:53 ` Enric Balletbo i Serra
  0 siblings, 0 replies; 2+ messages in thread
From: Enric Balletbo i Serra @ 2020-06-25 11:53 UTC (permalink / raw)
  To: Gwendal Grignou, groeck, bleung, twawrzynczak; +Cc: linux-kernel

Hi Gwendal,

Thank you for your patch.

On 26/5/20 20:53, Gwendal Grignou wrote:
> When EC does not support uptime command (EC_CMD_GET_UPTIME_INFO),
> do not create the uptime sysfs entry point.
> User space application will not probe the file needlessly.
> 
> The EC console log will not contain EC_CMD_GET_UPTIME_INFO anymore.
> 
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>

Applied for 5.9

> ---
>  drivers/platform/chrome/cros_ec_debugfs.c | 24 +++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c
> index 6ae484989d1f5..303a8c4686f89 100644
> --- a/drivers/platform/chrome/cros_ec_debugfs.c
> +++ b/drivers/platform/chrome/cros_ec_debugfs.c
> @@ -243,6 +243,25 @@ static ssize_t cros_ec_pdinfo_read(struct file *file,
>  				       read_buf, p - read_buf);
>  }
>  
> +static bool cros_ec_uptime_is_supported(struct cros_ec_device *ec_dev)
> +{
> +	struct {
> +		struct cros_ec_command cmd;
> +		struct ec_response_uptime_info resp;
> +	} __packed msg = {};
> +	int ret;
> +
> +	msg.cmd.command = EC_CMD_GET_UPTIME_INFO;
> +	msg.cmd.insize = sizeof(msg.resp);
> +
> +	ret = cros_ec_cmd_xfer_status(ec_dev, &msg.cmd);
> +	if (ret == -EPROTO && msg.cmd.result == EC_RES_INVALID_COMMAND)
> +		return false;
> +
> +	/* Other errors maybe a transient error, do not rule about support. */
> +	return true;
> +}
> +
>  static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf,
>  				   size_t count, loff_t *ppos)
>  {
> @@ -445,8 +464,9 @@ 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_uptime_is_supported(ec->ec_dev))
> +		debugfs_create_file("uptime", 0444, debug_info->dir, debug_info,
> +				    &cros_ec_uptime_fops);
>  
>  	debugfs_create_x32("last_resume_result", 0444, debug_info->dir,
>  			   &ec->ec_dev->last_resume_result);
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-25 11:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 18:53 [PATCH v2] platform: cros_ec_debugfs: control uptime information request Gwendal Grignou
2020-06-25 11:53 ` Enric Balletbo i Serra

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).