diff mbox series

iio: pressure: bmp280: Fix NULL pointer exception

Message ID 20230811155829.51208-1-phil@raspberrypi.com (mailing list archive)
State Accepted
Headers show
Series iio: pressure: bmp280: Fix NULL pointer exception | expand

Commit Message

Phil Elwell Aug. 11, 2023, 3:58 p.m. UTC
The bmp085 EOC IRQ support is optional, but the driver's common probe
function queries the IRQ properties whether or not it exists, which
can trigger a NULL pointer exception. Avoid any exception by making
the query conditional on the possession of a valid IRQ.

Fixes: aae953949651 ("iio: pressure: bmp280: add support for BMP085 EOC interrupt")
Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 drivers/iio/pressure/bmp280-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Linus Walleij Aug. 11, 2023, 5:38 p.m. UTC | #1
On Fri, Aug 11, 2023 at 5:58 PM Phil Elwell <phil@raspberrypi.com> wrote:

> The bmp085 EOC IRQ support is optional, but the driver's common probe
> function queries the IRQ properties whether or not it exists, which
> can trigger a NULL pointer exception. Avoid any exception by making
> the query conditional on the possession of a valid IRQ.
>
> Fixes: aae953949651 ("iio: pressure: bmp280: add support for BMP085 EOC interrupt")
> Signed-off-by: Phil Elwell <phil@raspberrypi.com>

Looks like a logic mistake.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
Jonathan Cameron Aug. 28, 2023, 11:37 a.m. UTC | #2
On Fri, 11 Aug 2023 19:38:09 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Fri, Aug 11, 2023 at 5:58 PM Phil Elwell <phil@raspberrypi.com> wrote:
> 
> > The bmp085 EOC IRQ support is optional, but the driver's common probe
> > function queries the IRQ properties whether or not it exists, which
> > can trigger a NULL pointer exception. Avoid any exception by making
> > the query conditional on the possession of a valid IRQ.
> >
> > Fixes: aae953949651 ("iio: pressure: bmp280: add support for BMP085 EOC interrupt")
> > Signed-off-by: Phil Elwell <phil@raspberrypi.com>  
> 
> Looks like a logic mistake.
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
I've applied this locally but given my tree is currently ahead of its
parent ready for the merge to happen, I won't push this out until
char-misc-next has been merged upstream.

Thanks,

Jonathan

> 
> Yours,
> Linus Walleij
diff mbox series

Patch

diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index 6089f3f9d8f4b..a2ef1373a274e 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -2179,7 +2179,7 @@  int bmp280_common_probe(struct device *dev,
 	 * however as it happens, the BMP085 shares the chip ID of BMP180
 	 * so we look for an IRQ if we have that.
 	 */
-	if (irq > 0 || (chip_id  == BMP180_CHIP_ID)) {
+	if (irq > 0 && (chip_id  == BMP180_CHIP_ID)) {
 		ret = bmp085_fetch_eoc_irq(dev, name, irq, data);
 		if (ret)
 			return ret;