Re: [PATCH v7 6/6] iio: adc: ad7192: Add AD7194 support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 30, 2024 at 7:30 PM Alisa-Dariana Roman
<alisadariana@xxxxxxxxx> wrote:
>
> Unlike the other AD719Xs, AD7194 has configurable channels. The user can
> dynamically configure them in the devicetree.
>
> Also modify config AD7192 description for better scaling.

...

> +static int ad7194_parse_channels(struct iio_dev *indio_dev)
> +{
> +       struct device *dev = indio_dev->dev.parent;
> +       struct iio_chan_spec *ad7194_channels;
> +       struct fwnode_handle *child;
> +       struct iio_chan_spec ad7194_chan = AD7193_CHANNEL(0, 0, 0);
> +       struct iio_chan_spec ad7194_chan_diff = AD7193_DIFF_CHANNEL(0, 0, 0, 0);
> +       struct iio_chan_spec ad7194_chan_temp = AD719x_TEMP_CHANNEL(0, 0);
> +       struct iio_chan_spec ad7194_chan_timestamp = IIO_CHAN_SOFT_TIMESTAMP(0);
> +       unsigned int num_channels, index = 0;
> +       u32 ain[2];
> +       int ret;
> +
> +       num_channels = device_get_child_node_count(dev);
> +       if (num_channels > AD7194_CH_MAX_NR)
> +               return dev_err_probe(dev, -EINVAL,
> +                                    "Too many channels: %u\n", num_channels);
> +
> +       num_channels += AD7194_CH_BASE_NR;
> +
> +       ad7194_channels = devm_kcalloc(dev, num_channels,
> +                                      sizeof(*ad7194_channels), GFP_KERNEL);
> +       if (!ad7194_channels)
> +               return -ENOMEM;
> +
> +       indio_dev->channels = ad7194_channels;
> +       indio_dev->num_channels = num_channels;
> +
> +       device_for_each_child_node(dev, child) {

You wanted _scoped version...

> +               ret = fwnode_property_read_u32_array(child, "diff-channels",
> +                                                    ain, ARRAY_SIZE(ain));
> +               if (ret == 0) {
> +                       ret = ad7194_validate_ain_channel(dev, ain[0]);
> +                       if (ret)

...otherwise here is the reference count leakage.

> +                               return ret;
> +
> +                       ret = ad7194_validate_ain_channel(dev, ain[1]);
> +                       if (ret)

Or here.

> +                               return ret;
> +
> +                       *ad7194_channels = ad7194_chan_diff;
> +                       ad7194_channels->scan_index = index++;
> +                       ad7194_channels->channel = ain[0];
> +                       ad7194_channels->channel2 = ain[1];
> +                       ad7194_channels->address = AD7194_CH(ain[0], ain[1]);
> +               } else {
> +                       ret = fwnode_property_read_u32(child, "single-channel",
> +                                                      &ain[0]);
> +                       if (ret) {
> +                               fwnode_handle_put(child);
> +                               return ret;
> +                       }
> +
> +                       ret = ad7194_validate_ain_channel(dev, ain[0]);
> +                       if (ret)

Or here.

> +                               return ret;
> +
> +                       *ad7194_channels = ad7194_chan;
> +                       ad7194_channels->scan_index = index++;
> +                       ad7194_channels->channel = ain[0];
> +                       ad7194_channels->address = AD7194_CH(ain[0], 0);
> +               }
> +               ad7194_channels++;
> +       }
> +
> +       *ad7194_channels = ad7194_chan_temp;
> +       ad7194_channels->scan_index = index++;
> +       ad7194_channels->address = AD7194_CH_TEMP;
> +       ad7194_channels++;
> +
> +       *ad7194_channels = ad7194_chan_timestamp;
> +       ad7194_channels->scan_index = index;
> +
> +       return 0;
> +}

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux