Re: [PATCH v7 2/2] iio: proximity: add driver for ST VL53L1X ToF sensor

From: Andy Shevchenko

Date: Thu Mar 26 2026 - 05:26:01 EST


On Wed, Mar 25, 2026 at 02:47:19PM +0000, Jonathan Cameron wrote:
> On Wed, 25 Mar 2026 12:32:23 +0600
> Siratul Islam <email@xxxxxxxx> wrote:

...

> > + trig = devm_iio_trigger_alloc(dev, "%s-dev%d", indio_dev->name,
> > + iio_device_id(indio_dev));
> > + if (!trig)
> > + return -ENOMEM;
> > +
> > + trig->ops = &vl53l1x_trigger_ops;
> > + iio_trigger_set_drvdata(trig, indio_dev);
> > + ret = devm_iio_trigger_register(dev, trig);
> > + if (ret)
> > + return ret;
> > +
> > + indio_dev->trig = iio_trigger_get(trig);
>
> So Sashiko had a comment on this that has me thinking. Don't bother fixing it
> in this driver as it true it's a common bug (and leaks a trigger structure).
> I'll look into it.

This probably can be worked around by introducing a flag devm_allocated and set
it in devm_iio_trigger_alloc(). If set, the release might automatically put the
trigger at the error cases. BUT, do all drivers that allocate trigger actually
bump its reference count?

> > + ret = vl53l1x_configure_irq(dev, client->irq, indio_dev);
> > + if (ret)
> > + return ret;
> > +
> > + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
> > + &vl53l1x_trigger_handler,
> > + NULL);
> > + if (ret)
> > + return ret;

--
With Best Regards,
Andy Shevchenko