All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Bianconi <lorenzo@kernel.org>
To: jic23@kernel.org
Cc: linux-iio@vger.kernel.org, sean@geanix.com, martin@geanix.com,
	rjones@gateworks.com, lorenzo.bianconi@redhat.com,
	devicetree@vger.kernel.org
Subject: [PATCH 02/13] iio: imu: st_lsm6dsx: add sanity check for read_fifo pointer
Date: Sun,  6 Oct 2019 15:21:56 +0200	[thread overview]
Message-ID: <fce5585e5b81f9d2dc2b38bdef0b60631bb713ec.1570367532.git.lorenzo@kernel.org> (raw)
In-Reply-To: <cover.1570367532.git.lorenzo@kernel.org>

Check read_fifo pointer before using it since we can't assume it
is always set adding new sensors. This patch fixes the following crash:

irq 277: nobody cared (try booting with the "irqpoll" option)
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.3.0-rc5-00322-g792b824-dirty #7
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[<c0112750>] (unwind_backtrace) from [<c010d018>] (show_stack+0x10/0x14)
[<c010d018>] (show_stack) from [<c0c2bfc8>] (dump_stack+0xd8/0x10c)
[<c0c2bfc8>] (dump_stack) from [<c01923fc>] (__report_bad_irq+0x24/0xc0)
[<c01923fc>] (__report_bad_irq) from [<c0192820>] (note_interrupt+0x27c/0x2dc)
[<c0192820>] (note_interrupt) from [<c018f174>] (handle_irq_event_percpu+0x54/0x7c)
[<c018f174>] (handle_irq_event_percpu) from [<c018f1d4>] (handle_irq_event+0x38/0x5c)
[<c018f1d4>] (handle_irq_event) from [<c0193664>] (handle_level_irq+0xc8/0x154)
[<c0193664>] (handle_level_irq) from [<c018df58>] (generic_handle_irq+0x20/0x34)
[<c018df58>] (generic_handle_irq) from [<c053c348>] (mxc_gpio_irq_handler+0xc4/0xf8)
[<c053c348>] (mxc_gpio_irq_handler) from [<c053c3e0>] (mx3_gpio_irq_handler+0x64/0xb8)
[<c053c3e0>] (mx3_gpio_irq_handler) from [<c018df58>] (generic_handle_irq+0x20/0x34)
[<c018df58>] (generic_handle_irq) from [<c018e550>] (__handle_domain_irq+0x64/0xe0)
[<c018e550>] (__handle_domain_irq) from [<c0529610>] (gic_handle_irq+0x4c/0xa0)
[<c0529610>] (gic_handle_irq) from [<c0101a70>] (__irq_svc+0x70/0x98)
Exception stack(0xc1301f10 to 0xc1301f58
1f00: 00000001 00000006 00000000 c130c340
1f20: c1300000 c1308928 00000001 c1308960 00000000 c12b9db0 c1308908 00000000
1f40: 00000000 c1301f60 c0182010 c0109508 20000013 ffffffff
[<c0101a70>] (__irq_svc) from [<c0109508>] (arch_cpu_idle+0x20/0x3c)
[<c0109508>] (arch_cpu_idle) from [<c015ed70>] (do_idle+0x1bc/0x2bc)
[<c015ed70>] (do_idle) from [<c015f204>] (cpu_startup_entry+0x18/0x1c)
[<c015f204>] (cpu_startup_entry) from [<c1200e68>] (start_kernel+0x440/0x504)
[<c1200e68>] (start_kernel) from [<00000000>] (0x0)
handlers:
[<62052c0d>] st_lsm6dsx_handler_irq threaded
[<f2004b92>] st_lsm6dsx_handler_thread

Fixes: 52f4b1f19679 ("iio: imu: st_lsm6dsx: add support for accel/gyro unit of lsm9ds1")
Tested-by: Bobby Jones <rjones@gateworks.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 3 +++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c   | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
index ef579650fd52..cabd4bfeab17 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -586,6 +586,9 @@ int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw)
 {
 	int err;
 
+	if (!hw->settings->fifo_ops.read_fifo)
+		return -ENOTSUPP;
+
 	mutex_lock(&hw->fifo_lock);
 
 	hw->settings->fifo_ops.read_fifo(hw);
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index df270905f21d..eac695663b6f 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1815,6 +1815,9 @@ static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
 
 	event = st_lsm6dsx_report_motion_event(hw);
 
+	if (!hw->settings->fifo_ops.read_fifo)
+		return event ? IRQ_HANDLED : IRQ_NONE;
+
 	mutex_lock(&hw->fifo_lock);
 	count = hw->settings->fifo_ops.read_fifo(hw);
 	mutex_unlock(&hw->fifo_lock);
-- 
2.21.0


  parent reply	other threads:[~2019-10-06 13:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-06 13:21 [PATCH 00/13] various st_lsm6dsx fixes and missing bits Lorenzo Bianconi
2019-10-06 13:21 ` [PATCH 01/13] iio: imu: st_lsm6dsx: use st_lsm6dsx_read_locked in st_lsm6dsx_report_motion_event Lorenzo Bianconi
2019-10-07  7:54   ` Sean Nyekjaer
2019-10-12 12:08   ` Jonathan Cameron
2019-10-06 13:21 ` Lorenzo Bianconi [this message]
2019-10-06 13:21 ` [PATCH 03/13] iio: imu: st_lsm6dsx: move irq related definitions in irq_config Lorenzo Bianconi
2019-10-07  7:54   ` Sean Nyekjaer
2019-10-12 12:13     ` Jonathan Cameron
2019-10-06 13:21 ` [PATCH 04/13] iio: imu: st_lsm6dsx: do not access active-low/open-drain regs if not supported Lorenzo Bianconi
2019-10-12 12:14   ` Jonathan Cameron
2019-10-06 13:21 ` [PATCH 05/13] iio: imu: st_lsm6dsx: move bdu/boot and reset register info in hw_settings Lorenzo Bianconi
2019-10-12 12:19   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup Lorenzo Bianconi
2019-10-07  7:55   ` Sean Nyekjaer
2019-10-12 12:21     ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 07/13] iio: imu: st_lsm6dsx: rely on st_lsm6dsx_update_bits_locked configuring events Lorenzo Bianconi
2019-10-12 12:22   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 08/13] iio: imu: st_lsm6dsx: grab conf mutex in st_lsm6dsx_write_event_config Lorenzo Bianconi
2019-10-12 12:23   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 09/13] iio: imu: st_lsm6dsx: fix checkpatch warning Lorenzo Bianconi
2019-10-12 12:24   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 10/13] iio: imu: st_lsm6dsx: add wakeup_source in st_sensors_platform_data Lorenzo Bianconi
2019-10-12 12:25   ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 11/13] iio: imu: st_lsm6dsx: add missing kernel documenation Lorenzo Bianconi
2019-10-07  7:56   ` Sean Nyekjaer
2019-10-12 12:26     ` Jonathan Cameron
2019-10-06 13:22 ` [PATCH 12/13] dt-bindings: iio: imu: st_lsm6dsx: document missing wakeup-source property Lorenzo Bianconi
2019-10-07  7:56   ` Sean Nyekjaer
2019-10-15 20:34   ` Rob Herring
2019-10-06 13:22 ` [PATCH 13/13] iio: imu: st_lsm6dsx: enable wake-up event for LSM6DSO Lorenzo Bianconi
2019-10-12 12:28   ` Jonathan Cameron
2019-10-12 12:20 ` [PATCH 00/13] various st_lsm6dsx fixes and missing bits Jonathan Cameron
2019-10-12 12:26   ` Lorenzo Bianconi
2019-10-12 13:26     ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fce5585e5b81f9d2dc2b38bdef0b60631bb713ec.1570367532.git.lorenzo@kernel.org \
    --to=lorenzo@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=martin@geanix.com \
    --cc=rjones@gateworks.com \
    --cc=sean@geanix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.