Re: [PATCH v4 4/4] iio: vcnl4000: Add buffer support for VCNL4010/20.

From: Jonathan Cameron
Date: Sat Apr 25 2020 - 12:09:19 EST


On Wed, 22 Apr 2020 10:14:21 +0200
Mathieu Othacehe <m.othacehe@xxxxxxxxx> wrote:

> >> +static int vcnl4010_buffer_predisable(struct iio_dev *indio_dev)
> >> +{
> >> + struct vcnl4000_data *data = iio_priv(indio_dev);
> >> + int ret, ret_disable;
> >> +
> >> + ret = i2c_smbus_write_byte_data(data->client, VCNL4010_INT_CTRL, 0);
> >> + if (ret < 0)
> >> + goto end;
> >> +
> >> + ret = i2c_smbus_write_byte_data(data->client, VCNL4000_COMMAND, 0);
> >> +
> >> +end:
> >
> >> + ret_disable = iio_triggered_buffer_predisable(indio_dev);
> >> + if (ret == 0)
> >> + ret = ret_disable;
> >
> > What is this?
> >
> > Can't you rather call IIO API first, and then try to handle the rest?
>
> Well, iio_triggered_buffer_predisable will call free_irq which requires
> that the interruption source is disabled, hence this strange pattern.
>
> However, this may be some misunderstanding from me, but I noticed
> something strange here. In a configuration with one CPU and
> CONFIG_PREEMPT disabled, I have kernel lockups when disabling the
> buffer.
>
> This is because free_irq calls synchronize_irq that will wait for any
> IRQ handler to be over. If the kthread handling the interruption is
> still running, it has no chances to terminate, and synchronize_irq waits
> forever. So maybe I'm missing something.

That is indeed worrying. The synchronize_irq is documented as
sleeping if we have a threaded interrupt. From a quick look I'd have
expected the wait in there to result in the interrupt thread being able
to complete whether or not we had preemption enabled.

I wonder what I'm missing...

Jonathan


>
> Anyway, I'll send a v5 addressing your remarks.
>
> Thanks,
>
> Mathieu