Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: light: tcs3472: do not free unallocated IRQ

Allocating an IRQ is conditional to the IRQ existence, but freeing it
was not. If no IRQ was allocate, the driver would still try to free
IRQ 0. Add the missing checks.

This fixes the following trace when the driver is removed:

[ 100.667788] Trying to free already-free IRQ 0
[ 100.667793] WARNING: CPU: 0 PID: 2315 at kernel/irq/manage.c:1826 free_irq+0x1fd/0x370
...
[ 100.667914] Call Trace:
[ 100.667920] tcs3472_remove+0x3a/0x90 [tcs3472]
[ 100.667927] i2c_device_remove+0x2b/0xa0

Signed-off-by: frank zago <frank@zago.net>
Link: https://lore.kernel.org/r/20210427022017.19314-2-frank@zago.net
Fixes: 9d2f715d592e ("iio: light: tcs3472: support out-of-threshold events")
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

frank zago and committed by
Jonathan Cameron
7cd04c86 e2a73c4e

+4 -2
+4 -2
drivers/iio/light/tcs3472.c
··· 535 535 return 0; 536 536 537 537 free_irq: 538 - free_irq(client->irq, indio_dev); 538 + if (client->irq) 539 + free_irq(client->irq, indio_dev); 539 540 buffer_cleanup: 540 541 iio_triggered_buffer_cleanup(indio_dev); 541 542 return ret; ··· 564 563 struct iio_dev *indio_dev = i2c_get_clientdata(client); 565 564 566 565 iio_device_unregister(indio_dev); 567 - free_irq(client->irq, indio_dev); 566 + if (client->irq) 567 + free_irq(client->irq, indio_dev); 568 568 iio_triggered_buffer_cleanup(indio_dev); 569 569 tcs3472_powerdown(iio_priv(indio_dev)); 570 570