From: Enric Balletbo i Serra <enric.balletbo@collabora.com>
To: Fabien Lahoudere <fabien.lahoudere@collabora.com>
Cc: gwendal@chromium.org, egranata@chromium.org,
kernel@collabora.com, Nick Vaccaro <nvaccaro@chromium.org>,
Jonathan Cameron <jic23@kernel.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>,
Alexios Zavras <alexios.zavras@intel.com>,
Allison Randal <allison@lohutok.net>,
Thomas Gleixner <tglx@linutronix.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] iio: common: cros_ec_sensors: determine protocol version
Date: Fri, 28 Jun 2019 17:13:35 +0200 [thread overview]
Message-ID: <4f79e029-b708-11f5-d4c6-2760e0b694d5@collabora.com> (raw)
In-Reply-To: <f5e824de2c423b310c4981b723bba4945a6512d4.1561731659.git.fabien.lahoudere@collabora.com>
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 <fabien.lahoudere@collabora.com>
> Signed-off-by: Nick Vaccaro <nvaccaro@chromium.org>
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
next prev parent reply other threads:[~2019-06-28 15:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-28 14:40 [PATCH v2 0/1] iio: common: cros_ec_sensors: Add protocol v3 support Fabien Lahoudere
2019-06-28 14:41 ` [PATCH v2 1/1] iio: common: cros_ec_sensors: determine protocol version Fabien Lahoudere
2019-06-28 15:13 ` Enric Balletbo i Serra [this message]
2019-07-01 20:53 ` [PATCH] iio: common: cros_ec_sensors: fix semicolon.cocci warnings kbuild test robot
2019-07-01 20:53 ` [PATCH v2 1/1] iio: common: cros_ec_sensors: determine protocol version kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4f79e029-b708-11f5-d4c6-2760e0b694d5@collabora.com \
--to=enric.balletbo@collabora.com \
--cc=alexios.zavras@intel.com \
--cc=allison@lohutok.net \
--cc=bleung@chromium.org \
--cc=egranata@chromium.org \
--cc=fabien.lahoudere@collabora.com \
--cc=gregkh@linuxfoundation.org \
--cc=groeck@chromium.org \
--cc=gwendal@chromium.org \
--cc=jic23@kernel.org \
--cc=kernel@collabora.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nvaccaro@chromium.org \
--cc=pmeerw@pmeerw.net \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).