platform/chrome: cros_ec_proto: Use ec_command for check_features
authorPrashant Malani <pmalani@chromium.org>
Mon, 4 Oct 2021 17:07:12 +0000 (10:07 -0700)
committerBenson Leung <bleung@chromium.org>
Sun, 31 Oct 2021 22:52:55 +0000 (15:52 -0700)
Use the existing cros_ec_command() for cros_ec_check_features(). This
eliminates an unnecessary duplication of the memory allocation/free and
memory copy code.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Link: https://lore.kernel.org/r/20211004170716.86601-2-pmalani@chromium.org
Signed-off-by: Benson Leung <bleung@chromium.org>
drivers/platform/chrome/cros_ec_proto.c

index b908cdd680e38833165c77c549818bf538068ffb..c4caf2e2de825fda873878bd448bef3406a5f498 100644 (file)
@@ -813,33 +813,19 @@ EXPORT_SYMBOL(cros_ec_get_host_event);
 bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)
 {
        struct ec_response_get_features *features = &ec->features;
-       struct cros_ec_command *msg;
        int ret;
 
        if (features->flags[0] == -1U && features->flags[1] == -1U) {
                /* features bitmap not read yet */
-               msg = kzalloc(sizeof(*msg) + sizeof(*features), GFP_KERNEL);
-               if (!msg) {
-                       dev_err(ec->dev, "failed to allocate memory to get EC features\n");
-                       return false;
-               }
-
-               msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
-               msg->insize = sizeof(*features);
-
-               ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+               ret = cros_ec_command(ec->ec_dev, 0, EC_CMD_GET_FEATURES + ec->cmd_offset,
+                                     NULL, 0, features, sizeof(*features));
                if (ret < 0) {
-                       dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
-                                ret, msg->result);
+                       dev_warn(ec->dev, "cannot get EC features: %d\n", ret);
                        memset(features, 0, sizeof(*features));
-               } else {
-                       memcpy(features, msg->data, sizeof(*features));
                }
 
                dev_dbg(ec->dev, "EC features %08x %08x\n",
                        features->flags[0], features->flags[1]);
-
-               kfree(msg);
        }
 
        return !!(features->flags[feature / 32] & EC_FEATURE_MASK_0(feature));