Merge tag 'iio-fixes-for-3.19a' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Jan 2015 01:59:04 +0000 (17:59 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Jan 2015 01:59:04 +0000 (17:59 -0800)
Jonathan writes:

First round of IIO fixes for the 3.19 cycle.

* ad799x fix ad7991/ad7995/ad7999 setup as they do not have a configuration
  register to write to.  It is written during the convesion sequence. As
  such we don't want to write to it at other times.
* Fix iio_channel_read utility function to return to ensure it is apparent
  if the relevant element is not there. This avoids using a wrong value
  if some channels have the element and others do not.

1  2 
drivers/iio/inkern.c

diff --combined drivers/iio/inkern.c
@@@ -100,28 -100,6 +100,28 @@@ static int iio_dev_node_match(struct de
        return dev->of_node == data && dev->type == &iio_device_type;
  }
  
 +/**
 + * __of_iio_simple_xlate - translate iiospec to the IIO channel index
 + * @indio_dev:        pointer to the iio_dev structure
 + * @iiospec:  IIO specifier as found in the device tree
 + *
 + * This is simple translation function, suitable for the most 1:1 mapped
 + * channels in IIO chips. This function performs only one sanity check:
 + * whether IIO index is less than num_channels (that is specified in the
 + * iio_dev).
 + */
 +static int __of_iio_simple_xlate(struct iio_dev *indio_dev,
 +                              const struct of_phandle_args *iiospec)
 +{
 +      if (!iiospec->args_count)
 +              return 0;
 +
 +      if (iiospec->args[0] >= indio_dev->num_channels)
 +              return -EINVAL;
 +
 +      return iiospec->args[0];
 +}
 +
  static int __of_iio_channel_get(struct iio_channel *channel,
                                struct device_node *np, int index)
  {
  
        indio_dev = dev_to_iio_dev(idev);
        channel->indio_dev = indio_dev;
 -      index = iiospec.args_count ? iiospec.args[0] : 0;
 -      if (index >= indio_dev->num_channels) {
 -              err = -EINVAL;
 +      if (indio_dev->info->of_xlate)
 +              index = indio_dev->info->of_xlate(indio_dev, &iiospec);
 +      else
 +              index = __of_iio_simple_xlate(indio_dev, &iiospec);
 +      if (index < 0)
                goto err_put;
 -      }
        channel->channel = &indio_dev->channels[index];
  
        return 0;
  
  err_put:
        iio_device_put(indio_dev);
 -      return err;
 +      return index;
  }
  
  static struct iio_channel *of_iio_channel_get(struct device_node *np, int index)
@@@ -449,6 -426,9 +449,9 @@@ static int iio_channel_read(struct iio_
        if (val2 == NULL)
                val2 = &unused;
  
+       if(!iio_channel_has_info(chan->channel, info))
+               return -EINVAL;
        if (chan->indio_dev->info->read_raw_multi) {
                ret = chan->indio_dev->info->read_raw_multi(chan->indio_dev,
                                        chan->channel, INDIO_MAX_RAW_ELEMENTS,