public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Denis Ciocca <denis.ciocca@st.com>
Cc: <linux-iio@vger.kernel.org>, <lorenzo@kernel.org>
Subject: Re: [PATCH 1/7] iio:common:st_sensors: add st_sensors_get_settings_index() helper function
Date: Sat, 22 Jun 2019 11:30:46 +0100	[thread overview]
Message-ID: <20190622113046.050ca914@archlinux> (raw)
In-Reply-To: <20190617234943.10669-2-denis.ciocca@st.com>

On Mon, 17 Jun 2019 16:49:37 -0700
Denis Ciocca <denis.ciocca@st.com> wrote:

> Extract from st_sensors_check_device_support() function the code that
> is used to get the specific settings for a device. This will be used
> by each driver to configure the multi-read bit at the beginning of the
> probes.
> 
> Signed-off-by: Denis Ciocca <denis.ciocca@st.com>
A few minor suggestions inline.

Jonathan

> ---
>  .../iio/common/st_sensors/st_sensors_core.c   | 45 ++++++++++++++-----
>  include/linux/iio/common/st_sensors.h         |  4 ++
>  2 files changed, 37 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
> index 8b22dc241482..243b2097c57e 100644
> --- a/drivers/iio/common/st_sensors/st_sensors_core.c
> +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
> @@ -633,28 +633,49 @@ static int st_sensors_init_interface_mode(struct iio_dev *indio_dev,
>  	return 0;
>  }
>  
> -int st_sensors_check_device_support(struct iio_dev *indio_dev,
> -			int num_sensors_list,
> -			const struct st_sensor_settings *sensor_settings)
> +/*
> + * st_sensors_get_settings_index() - get index of sensor settings
> + *				     for a specific device.
> + * @name: device name buffer reference.
> + * @list: sensor settings list.
> + * @list_length: length of sensor settings list.
> + */
> +int st_sensors_get_settings_index(const char *name,
> +				  const struct st_sensor_settings *list,
> +				  const int list_length)
>  {
> -	int i, n, err = 0;
> -	u8 wai;
> -	struct st_sensor_data *sdata = iio_priv(indio_dev);
> +	int i, n;
>  
> -	for (i = 0; i < num_sensors_list; i++) {
> +	for (i = 0; i < list_length; i++) {
>  		for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
> -			if (strcmp(indio_dev->name,
> -				sensor_settings[i].sensors_supported[n]) == 0) {
> +			if (strcmp(name, list[i].sensors_supported[n]) == 0) {
>  				break;
return i; ?

Should give a simpler flow as we only handle errors after this I think.

>  			}
>  		}
>  		if (n < ST_SENSORS_MAX_4WAI)
>  			break;

>  	}
> -	if (i == num_sensors_list) {
> -		dev_err(&indio_dev->dev, "device name %s not recognized.\n",
> -							indio_dev->name);
> +	if (i == list_length)
>  		return -ENODEV;
> +
> +	return i;
> +}
> +EXPORT_SYMBOL(st_sensors_get_settings_index);
> +
> +int st_sensors_check_device_support(struct iio_dev *indio_dev,
> +			int num_sensors_list,
> +			const struct st_sensor_settings *sensor_settings)
> +{
> +	struct st_sensor_data *sdata = iio_priv(indio_dev);
> +	int i, err = 0;

Why init err?

> +	u8 wai;
> +
> +	i = st_sensors_get_settings_index(indio_dev->name,
> +					  sensor_settings, num_sensors_list);
> +	if (i < 0) {
> +		dev_err(&indio_dev->dev, "device name %s not recognized.\n",
> +			indio_dev->name);
> +		return i;
>  	}
>  
>  	err = st_sensors_init_interface_mode(indio_dev, &sensor_settings[i]);
> diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
> index 2948ac99e2da..17fbf3e9b013 100644
> --- a/include/linux/iio/common/st_sensors.h
> +++ b/include/linux/iio/common/st_sensors.h
> @@ -334,6 +334,10 @@ int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale);
>  int st_sensors_read_info_raw(struct iio_dev *indio_dev,
>  				struct iio_chan_spec const *ch, int *val);
>  
> +int st_sensors_get_settings_index(const char *name,
> +				  const struct st_sensor_settings *list,
> +				  const int list_length);
> +
>  int st_sensors_check_device_support(struct iio_dev *indio_dev,
>  	int num_sensors_list, const struct st_sensor_settings *sensor_settings);
>  


  reply	other threads:[~2019-06-22 10:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-17 23:49 [PATCH 0/7] iio:st_sensors: make use of regmap API Denis Ciocca
2019-06-17 23:49 ` [PATCH 1/7] iio:common:st_sensors: add st_sensors_get_settings_index() helper function Denis Ciocca
2019-06-22 10:30   ` Jonathan Cameron [this message]
2019-06-17 23:49 ` [PATCH 2/7] iio:accel: introduce st_accel_multiread_bit() function Denis Ciocca
2019-06-22 10:33   ` Jonathan Cameron
2019-06-17 23:49 ` [PATCH 3/7] iio:magn: introduce st_magn_multiread_bit() function Denis Ciocca
2019-06-17 23:49 ` [PATCH 4/7] iio:gyro: introduce st_gyro_multiread_bit() function Denis Ciocca
2019-06-17 23:49 ` [PATCH 5/7] iio:pressure: introduce st_pressure_multiread_bit() function Denis Ciocca
2019-06-17 23:49 ` [PATCH 6/7] iio: make st_sensors driver use regmap Denis Ciocca
2019-06-22 10:47   ` Jonathan Cameron
2019-06-26 20:45     ` Denis CIOCCA
2019-06-17 23:49 ` [PATCH 7/7] iio:common: make st_sensors_write_data_with_mask() inline Denis Ciocca
2019-06-22 10:49   ` Jonathan Cameron
2019-06-22 10:27 ` [PATCH 0/7] iio:st_sensors: make use of regmap API Jonathan Cameron

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=20190622113046.050ca914@archlinux \
    --to=jic23@kernel.org \
    --cc=denis.ciocca@st.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    /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