From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5372C4321A for ; Fri, 28 Jun 2019 15:13:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B0216208E3 for ; Fri, 28 Jun 2019 15:13:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726711AbfF1PNl (ORCPT ); Fri, 28 Jun 2019 11:13:41 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:55136 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726657AbfF1PNl (ORCPT ); Fri, 28 Jun 2019 11:13:41 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 1B1C026091A Subject: Re: [PATCH v2 1/1] iio: common: cros_ec_sensors: determine protocol version To: Fabien Lahoudere Cc: gwendal@chromium.org, egranata@chromium.org, kernel@collabora.com, Nick Vaccaro , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Benson Leung , Guenter Roeck , Alexios Zavras , Allison Randal , Thomas Gleixner , Greg Kroah-Hartman , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: From: Enric Balletbo i Serra Message-ID: <4f79e029-b708-11f5-d4c6-2760e0b694d5@collabora.com> Date: Fri, 28 Jun 2019 17:13:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Hi, Thanks for the quick respin, two few comments below On 28/6/19 16:41, Fabien Lahoudere wrote: > This patch adds a function to determine which version of the > protocol is used to communicate with EC. > > Signed-off-by: Fabien Lahoudere > Signed-off-by: Nick Vaccaro The order must be the opposite, first Nick and then you. > --- > .../cros_ec_sensors/cros_ec_sensors_core.c | 40 ++++++++++++++++++- > 1 file changed, 39 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c > index 130362ca421b..75d9b617f6c8 100644 > --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c > @@ -25,6 +25,35 @@ static char *cros_ec_loc[] = { > [MOTIONSENSE_LOC_MAX] = "unknown", > }; > > +static int cros_ec_get_host_cmd_version_mask(struct cros_ec_device *ec_dev, > + u16 cmd_offset, u16 cmd, u32 *mask) > +{ > + int ret; > + struct { > + struct cros_ec_command msg; > + union { > + struct ec_params_get_cmd_versions params; > + struct ec_response_get_cmd_versions resp; > + }; > + } __packed buf = { > + .msg = { > + .version = 0, > + .command = EC_CMD_GET_CMD_VERSIONS + cmd_offset, > + .insize = sizeof(struct ec_response_get_cmd_versions), > + .outsize = sizeof(struct ec_params_get_cmd_versions) > + }, > + .params = {.cmd = cmd} > + }; > + > + ret = cros_ec_cmd_xfer_status(ec_dev, &buf.msg); > + if (ret < 0) > + return ret; > + > + *mask = buf.resp.version_mask; > + > + return 0; > +} > + > int cros_ec_sensors_core_init(struct platform_device *pdev, > struct iio_dev *indio_dev, > bool physical_device) > @@ -33,6 +62,8 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, > struct cros_ec_sensors_core_state *state = iio_priv(indio_dev); > struct cros_ec_dev *ec = dev_get_drvdata(pdev->dev.parent); > struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev); > + u32 ver_mask; If you follow the error path in the cros_ec_get_host_cmd_version_mask there is a possible use of an uninitialized variable. u32 ver_mask = 0; > + int ret; > > platform_set_drvdata(pdev, indio_dev); > > @@ -47,8 +78,15 @@ int cros_ec_sensors_core_init(struct platform_device *pdev, > > mutex_init(&state->cmd_lock); > What about adding a comment to explain the ver_mask thing for the record? /* * If the EC is very old or misbehaving is it possible that the * communication succeed and have the version mask set to an invalid * value. So check that version mask is valid (!= 0), otherwise return * an error. */ At least this is what I understood from the previous discussion. > + ret = cros_ec_get_host_cmd_version_mask(state->ec, > + ec->cmd_offset, > + EC_CMD_MOTION_SENSE_CMD, > + &ver_mask); > + if (ret < 0 || ver_mask == 0) > + return -ENODEV; > + > /* Set up the host command structure. */ > - state->msg->version = 2; > + state->msg->version = fls(ver_mask) - 1;; > state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset; > state->msg->outsize = sizeof(struct ec_params_motion_sense); > > Thanks, ~ Enric