iio: imu: st_lsm6ds3: protect from divide by 0 errors
st_lsm6ds3_read_fifo() might be called just after sensors have been
disabled. In this situation, all cdata->*samples_in_pattern are 0, and
therefore byte_in_pattern is 0.
This triggers a divide by zero exception:
[ 75.536173] divide error: 0000 [#1] PREEMPT SMP
[ 75.536290] CPU: 1 PID: 530 Comm: Binder_1 Tainted: G W 3.10.62-268016-gf3b5e59-dirty #12
[ 75.536327] Hardware name: Intel Corporation Merrifield/GLACIER, BIOS 602 2015.10.15:18.07.11
[ 75.536364] task: ffff8800379cb240 ti: ffff880037bd6000 task.ti: ffff880037bd6000
[ 75.536396] RIP: 0010:[<ffffffff8263f249>] [<ffffffff8263f249>] st_lsm6ds3_read_fifo+0xb9/0x4e0
[ 75.536465] RSP: 0000:ffff880037bd7d60 EFLAGS: 00210246
[ 75.536496] RAX: 0000000000000000 RBX: ffff88003b67c000 RCX: 0000000000000000
[ 75.536526] RDX: 0000000000000000 RSI: 2f71808ca4948000 RDI: 0000000000000000
[ 75.536556] RBP: ffff880037bd7dc0 R08: 0000000000000001 R09: 0000000000000005
[ 75.536585] R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000001
[ 75.536616] R13: 0000000000000000 R14: 0000000000000000 R15: ffff88003b45e338
[ 75.536650] FS: 00000000f93ad8c0(004f) GS:ffff88003f300000(0063) knlGS:00000000ebccbdd0
[ 75.536681] CS: 0010 DS: 002b ES: 002b CR0: 0000000080050033
[ 75.536711] CR2: 00000000f59dd00c CR3: 0000000038413000 CR4: 00000000001007e0
[ 75.536741] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 75.536772] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
[ 75.536800] Last Branch Records: (not halted)
[ 75.536840] Stack:
[ 75.536866] 2222222222222222 2222222222222222 ffff880037bd7d68 ffff88003b67c1b0
[ 75.536959] 0000000000000000 0000000000000001 100088003b67c1b0 ffff88003b67c000
[ 75.537044] ffff88003b45e680 0000000000000001 ffff88003b67c1b0 ffff88003b45e338
[ 75.537130] Call Trace:
[ 75.537176] [<ffffffff8263c7df>] st_lsm6ds3_reconfigure_fifo+0x3f/0xf0
[ 75.537220] [<ffffffff8263eea1>] st_lsm6ds3_buffer_preenable+0x41/0x80
[ 75.537263] [<ffffffff82639117>] iio_update_buffers+0x197/0x470
[ 75.537303] [<ffffffff82639485>] iio_buffer_store_enable+0x95/0x100
[ 75.537344] [<ffffffff823c0698>] dev_attr_store+0x18/0x30
[ 75.537383] [<ffffffff821e8837>] sysfs_write_file+0xe7/0x160
[ 75.537423] [<ffffffff8217cc6e>] vfs_write+0xbe/0x1e0
[ 75.537461] [<ffffffff8217ce7d>] SyS_write+0x4d/0xa0
[ 75.537504] [<ffffffff829a8f09>] ia32_do_call+0x13/0x13
Fix it by returning from the function in this specific case, without
emptying the FIFO nor making any calculation using byte_in_pattern.
Change-Id: Ie8ac41863307a9853eb863db93d70477dff6a69b
Signed-off-by: Robert Jarzmik <robert.jarzmik@intel.com>
1 file changed