Re: [PATCH v3 4/5] iio: light: vcnl4000: Add IRQ disable callback on cleanup

From: Andy Shevchenko

Date: Thu Sep 03 2026 - 04:30:50 EST


On Thu, Sep 03, 2026 at 02:53:49PM +1000, Tsz Shan Chan wrote:
> During driver unbind, devm cleans up resources in LIFO order. The IRQ
> handler is freed before the device is powered down. This can lead to
> unhandled interrupts.
>
> Register a devm action to disable interrupt explicitly after
> devm_request_threaded_irq(), so that the interrupt is disabled before
> the IRQ handler is freed. This prevents any unhandled interrupts.
>
> Add a disable_irq callback to chip info structure. This allows each chip
> type to implement its own disable sequence.

...

> +static int vcnl4010_disable_irq(struct vcnl4000_data *data)
> +{
> + int ret;
> +
> + guard(mutex)(&data->vcnl4000_lock);
> +
> + ret = vcnl4010_stop(data);
> + if (ret < 0)
> + return ret;
> +
> + ret = i2c_smbus_read_byte_data(data->client, VCNL4010_ISR);
> + if (ret < 0)
> + return ret;

> + ret &= VCNL4010_INT_THR | VCNL4010_INT_DRDY;
> + if (!ret)
> + return 0;
> +
> + return i2c_smbus_write_byte_data(data->client, VCNL4010_ISR, ret);

Since ret is in use it's better to follow regular pattern

ret &= VCNL4010_INT_THR | VCNL4010_INT_DRDY;
if (ret)
return i2c_smbus_write_byte_data(data->client, VCNL4010_ISR, ret);

return 0;

BUT, since ret doesn't care an error code at this point, it's even better to
use proper typing.

u8 byte;
...

byte = ret & (VCNL4010_INT_THR | VCNL4010_INT_DRDY);
if (!byte)
return 0;

return i2c_smbus_write_byte_data(data->client, VCNL4010_ISR, byte);

> +}

--
With Best Regards,
Andy Shevchenko