linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Enric Balletbo i Serra <enric.balletbo@collabora.com>
To: linux-kernel@vger.kernel.org
Cc: groeck@chromium.org, bleung@chromium.org, gwendal@chromium.org,
	kernel@collabora.com, dtor@chromium.org
Subject: [PATCH] platform/chrome: cros_ec_proto: Also return invalid command in cros_ec_cmd_xfer_status
Date: Wed,  3 Apr 2019 15:51:23 +0200	[thread overview]
Message-ID: <20190403135123.8723-1-enric.balletbo@collabora.com> (raw)

The commit 9798ac6d32c1 ("mfd: cros_ec: Add cros_ec_cmd_xfer_status()
helper") was introduced to remove duplicated code in several users of
the cros_ec_cmd_xfer function. The idea behind that commit is mask all
the EC errors as protocol error when the EC command fails, what is
really useful because as a user you probably don't care of the exact
error reported by the EC, you only want to know if the command succeeded
or not.

That works for most of the errors returned by the EC, but we might be
also interested on report the EC_RES_INVALID_COMMAND, which happens when
the command is not supported by the EC. An use case for this is when you
need to show/hide a sysfs attribute for a specific command and you don't
have a EC feature flag that tells you that the command is supported or
not.

While here, also document properly the cros_ec_cmd_xfer_status
function.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
---

 drivers/platform/chrome/cros_ec_proto.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 97a068dff192..a4e0d3a6d891 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -478,6 +478,16 @@ int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
 }
 EXPORT_SYMBOL(cros_ec_cmd_xfer);
 
+/**
+ * cros_ec_cmd_xfer_status() - Send EC command.
+ * @ec_dev: EC device.
+ * @msg: EC message data for request and response.
+ *
+ * Return:
+ * 0 - OK
+ * -EINVAL - Invalid command.
+ * -EPROTO - Protocol error.
+ */
 int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
 			    struct cros_ec_command *msg)
 {
@@ -486,6 +496,11 @@ int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
 	ret = cros_ec_cmd_xfer(ec_dev, msg);
 	if (ret < 0) {
 		dev_err(ec_dev->dev, "Command xfer error (err:%d)\n", ret);
+	} else if (msg->result == EC_RES_INVALID_COMMAND) {
+		dev_dbg(ec_dev->dev,
+			"Command %d not supported for this device\n",
+			msg->command);
+		return -EINVAL;
 	} else if (msg->result != EC_RES_SUCCESS) {
 		dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result);
 		return -EPROTO;
-- 
2.20.1


             reply	other threads:[~2019-04-03 13:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-03 13:51 Enric Balletbo i Serra [this message]
2019-04-03 16:25 ` [PATCH] platform/chrome: cros_ec_proto: Also return invalid command in cros_ec_cmd_xfer_status Guenter Roeck
2019-04-11 15:40   ` Enric Balletbo 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=20190403135123.8723-1-enric.balletbo@collabora.com \
    --to=enric.balletbo@collabora.com \
    --cc=bleung@chromium.org \
    --cc=dtor@chromium.org \
    --cc=groeck@chromium.org \
    --cc=gwendal@chromium.org \
    --cc=kernel@collabora.com \
    --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).