platform/chrome: cros_ec_lightbar: Use cros_ec_cmd_xfer_status helper
authorEnric Balletbo i Serra <enric.balletbo@collabora.com>
Thu, 20 Feb 2020 15:58:57 +0000 (16:58 +0100)
committerEnric Balletbo i Serra <enric.balletbo@collabora.com>
Mon, 2 Mar 2020 10:04:05 +0000 (11:04 +0100)
This patch makes use of cros_ec_cmd_xfer_status() instead of
cros_ec_cmd_xfer(). It allows us to remove some redundand code. In this
case, though, we are changing a bit the behaviour because of returning
-EINVAL on protocol error we propagate the error return for
cros_ec_cmd_xfer_status() function, but I think it will be fine, even
more clear as we don't mask the Linux error code.

Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>
Tested-by: Prashant Malani <pmalani@chromium.org>
drivers/platform/chrome/cros_ec_lightbar.c

index b4c110c5fee0fce61a54c00e1cc43592caea4b28..b59180bff5a3e067cbfc5ac3d37d40204f9d4a18 100644 (file)
@@ -116,7 +116,7 @@ static int get_lightbar_version(struct cros_ec_dev *ec,
 
        param = (struct ec_params_lightbar *)msg->data;
        param->cmd = LIGHTBAR_CMD_VERSION;
-       ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+       ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
        if (ret < 0) {
                ret = 0;
                goto exit;
@@ -193,15 +193,10 @@ static ssize_t brightness_store(struct device *dev,
        if (ret)
                goto exit;
 
-       ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+       ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
        if (ret < 0)
                goto exit;
 
-       if (msg->result != EC_RES_SUCCESS) {
-               ret = -EINVAL;
-               goto exit;
-       }
-
        ret = count;
 exit:
        kfree(msg);
@@ -258,13 +253,10 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr,
                                        goto exit;
                        }
 
-                       ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+                       ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
                        if (ret < 0)
                                goto exit;
 
-                       if (msg->result != EC_RES_SUCCESS)
-                               goto exit;
-
                        i = 0;
                        ok = 1;
                }
@@ -305,14 +297,13 @@ static ssize_t sequence_show(struct device *dev,
        if (ret)
                goto exit;
 
-       ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
-       if (ret < 0)
-               goto exit;
-
-       if (msg->result != EC_RES_SUCCESS) {
+       ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+       if (ret == -EPROTO) {
                ret = scnprintf(buf, PAGE_SIZE,
                                "ERROR: EC returned %d\n", msg->result);
                goto exit;
+       } else if (ret < 0) {
+               goto exit;
        }
 
        resp = (struct ec_response_lightbar *)msg->data;
@@ -344,13 +335,10 @@ static int lb_send_empty_cmd(struct cros_ec_dev *ec, uint8_t cmd)
        if (ret)
                goto error;
 
-       ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+       ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
        if (ret < 0)
                goto error;
-       if (msg->result != EC_RES_SUCCESS) {
-               ret = -EINVAL;
-               goto error;
-       }
+
        ret = 0;
 error:
        kfree(msg);
@@ -377,13 +365,10 @@ static int lb_manual_suspend_ctrl(struct cros_ec_dev *ec, uint8_t enable)
        if (ret)
                goto error;
 
-       ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+       ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
        if (ret < 0)
                goto error;
-       if (msg->result != EC_RES_SUCCESS) {
-               ret = -EINVAL;
-               goto error;
-       }
+
        ret = 0;
 error:
        kfree(msg);
@@ -425,15 +410,10 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr,
        if (ret)
                goto exit;
 
-       ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+       ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
        if (ret < 0)
                goto exit;
 
-       if (msg->result != EC_RES_SUCCESS) {
-               ret = -EINVAL;
-               goto exit;
-       }
-
        ret = count;
 exit:
        kfree(msg);
@@ -487,13 +467,9 @@ static ssize_t program_store(struct device *dev, struct device_attribute *attr,
         */
        msg->outsize = count + extra_bytes;
 
-       ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
+       ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
        if (ret < 0)
                goto exit;
-       if (msg->result != EC_RES_SUCCESS) {
-               ret = -EINVAL;
-               goto exit;
-       }
 
        ret = count;
 exit: