platform/chrome: cros_ec_proto: check `msg->result` in getting cmd mask
authorTzung-Bi Shih <tzungbi@kernel.org>
Thu, 9 Jun 2022 08:49:52 +0000 (08:49 +0000)
committerTzung-Bi Shih <tzungbi@kernel.org>
Fri, 10 Jun 2022 02:31:44 +0000 (02:31 +0000)
cros_ec_get_host_command_version_mask() should check if EC wasn't happy
by checking `msg->result`.

Use cros_ec_map_error() and return the error code if any.

Reviewed-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://lore.kernel.org/r/20220609084957.3684698-17-tzungbi@kernel.org
drivers/platform/chrome/cros_ec_proto.c

index 1df22eb29e95c153c0c182c37f708f932f1dfb60..b152f2902b32af855a34c9dcc28a910d9fce91a0 100644 (file)
@@ -428,13 +428,12 @@ exit:
  * the caller has ec_dev->lock mutex or the caller knows there is
  * no other command in progress.
  */
-static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev,
-       u16 cmd, u32 *mask)
+static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev, u16 cmd, u32 *mask)
 {
        struct ec_params_get_cmd_versions *pver;
        struct ec_response_get_cmd_versions *rver;
        struct cros_ec_command *msg;
-       int ret;
+       int ret, mapped;
 
        msg = kmalloc(sizeof(*msg) + max(sizeof(*rver), sizeof(*pver)),
                      GFP_KERNEL);
@@ -450,14 +449,20 @@ static int cros_ec_get_host_command_version_mask(struct cros_ec_device *ec_dev,
        pver->cmd = cmd;
 
        ret = send_command(ec_dev, msg);
-       if (ret > 0) {
-               rver = (struct ec_response_get_cmd_versions *)msg->data;
-               *mask = rver->version_mask;
-               ret = 0;
+       if (ret < 0)
+               goto exit;
+
+       mapped = cros_ec_map_error(msg->result);
+       if (mapped) {
+               ret = mapped;
+               goto exit;
        }
 
+       rver = (struct ec_response_get_cmd_versions *)msg->data;
+       *mask = rver->version_mask;
+       ret = 0;
+exit:
        kfree(msg);
-
        return ret;
 }