Re: [PATCH v2 1/8] iio: proximity: ping: pass reference to IIO device via call-stack

From: Jonathan Cameron
Date: Sat May 16 2020 - 13:13:09 EST


On Thu, 14 May 2020 16:17:03 +0300
Alexandru Ardelean <alexandru.ardelean@xxxxxxxxxx> wrote:

> Since there will be some changes to how iio_priv_to_dev() is implemented,
> it could be that the helper becomes a bit slower, as it will be hidden away
> in the IIO core.
>
> For this driver, the IIO device can be passed directly as a parameter to
> the ping_read() function, thus making it immune to the change of
> iio_priv_to_dev().
>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@xxxxxxxxxx>

Patch makes sense and I should have spotted this one during original
review :( Going backwards and forwards is never a good idea even without
the rework you have.

But... (you knew that was coming :), there is no need to pass
data to the the read function. It is the structure returned by
iio_priv() and not used anywhere else in the read_raw callback.
So might as well just pass the iio_dev and get the data structure
with in the read function via iio_priv(indio_dev)

Thanks,

J

> ---
> drivers/iio/proximity/ping.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/proximity/ping.c b/drivers/iio/proximity/ping.c
> index 12b893c5b0ee..ddc43a5a2ef8 100644
> --- a/drivers/iio/proximity/ping.c
> +++ b/drivers/iio/proximity/ping.c
> @@ -89,14 +89,13 @@ static irqreturn_t ping_handle_irq(int irq, void *dev_id)
> return IRQ_HANDLED;
> }
>
> -static int ping_read(struct ping_data *data)
> +static int ping_read(struct iio_dev *indio_dev, struct ping_data *data)
> {
> int ret;
> ktime_t ktime_dt;
> s64 dt_ns;
> u32 time_ns, distance_mm;
> struct platform_device *pdev = to_platform_device(data->dev);
> - struct iio_dev *indio_dev = iio_priv_to_dev(data);
>
> /*
> * just one read-echo-cycle can take place at a time
> @@ -236,7 +235,7 @@ static int ping_read_raw(struct iio_dev *indio_dev,
>
> switch (info) {
> case IIO_CHAN_INFO_RAW:
> - ret = ping_read(data);
> + ret = ping_read(indio_dev, data);
> if (ret < 0)
> return ret;
> *val = ret;