diff mbox series

[v3,18/23] platform/chrome: cros_ec_proto: check `msg->result` in getting cmd mask

Message ID 20220608110734.2928245-19-tzungbi@kernel.org (mailing list archive)
State Superseded
Headers show
Series platform/chrome: Kunit tests and refactor for cros_ec_query_all() | expand

Commit Message

Tzung-Bi Shih June 8, 2022, 11:07 a.m. UTC
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.

Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
No v2.  New and separated from the original series.

 drivers/platform/chrome/cros_ec_proto.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

Comments

Guenter Roeck June 8, 2022, 4:23 p.m. UTC | #1
On Wed, Jun 8, 2022 at 4:08 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> 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.
>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
> ---
> No v2.  New and separated from the original series.
>
>  drivers/platform/chrome/cros_ec_proto.c | 21 +++++++++++++--------
>  1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
> index 06bc7db1213e..6a5771361383 100644
> --- a/drivers/platform/chrome/cros_ec_proto.c
> +++ b/drivers/platform/chrome/cros_ec_proto.c
> @@ -428,13 +428,12 @@ static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev)
>   * 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;
>         }
>
What if ret == 0 ? Is that valid ?

Thanks,
Guenter

> +       rver = (struct ec_response_get_cmd_versions *)msg->data;
> +       *mask = rver->version_mask;
> +       ret = 0;
> +exit:
>         kfree(msg);
> -
>         return ret;
>  }
>
> --
> 2.36.1.255.ge46751e96f-goog
>
Guenter Roeck June 8, 2022, 4:27 p.m. UTC | #2
On Wed, Jun 8, 2022 at 9:23 AM Guenter Roeck <groeck@google.com> wrote:
>
> On Wed, Jun 8, 2022 at 4:08 AM Tzung-Bi Shih <tzungbi@kernel.org> wrote:
> >
> > 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.
> >
> > Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
> > ---
> > No v2.  New and separated from the original series.
> >
> >  drivers/platform/chrome/cros_ec_proto.c | 21 +++++++++++++--------
> >  1 file changed, 13 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
> > index 06bc7db1213e..6a5771361383 100644
> > --- a/drivers/platform/chrome/cros_ec_proto.c
> > +++ b/drivers/platform/chrome/cros_ec_proto.c
> > @@ -428,13 +428,12 @@ static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev)
> >   * 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;
> >         }
> >
> What if ret == 0 ? Is that valid ?
>

Never mind, addressed in a follow-up patch.

Reviewed-by: Guenter Roeck <groeck@chromium.org>

> Thanks,
> Guenter
>
> > +       rver = (struct ec_response_get_cmd_versions *)msg->data;
> > +       *mask = rver->version_mask;
> > +       ret = 0;
> > +exit:
> >         kfree(msg);
> > -
> >         return ret;
> >  }
> >
> > --
> > 2.36.1.255.ge46751e96f-goog
> >
diff mbox series

Patch

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 06bc7db1213e..6a5771361383 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -428,13 +428,12 @@  static int cros_ec_get_proto_info_legacy(struct cros_ec_device *ec_dev)
  * 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;
 }