summaryrefslogtreecommitdiff
path: root/drivers/iio/magnetometer/rm3100-core.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-22iio: magnetometer: rm3100: add boundary check for the value read from ↵zhili.liu1-2/+8
RM3100_REG_TMRC Recently, we encounter kernel crash in function rm3100_common_probe caused by out of bound access of array rm3100_samp_rates (because of underlying hardware failures). Add boundary check to prevent out of bound access. Fixes: 121354b2eceb ("iio: magnetometer: Add driver support for PNI RM3100") Suggested-by: Zhouyi Zhou <zhouzhouyi@gmail.com> Signed-off-by: zhili.liu <zhili.liu@ucas.com.cn> Link: https://lore.kernel.org/r/1704157631-3814-1-git-send-email-zhouzhouyi@gmail.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2022-07-16iio: magnetometer: rm3100: do not explicity set INDIO_BUFFER_TRIGGERED modeMarcus Folkesson1-1/+1
The core sets INDIO_BUFFER_TRIGGERED as part of devm_iio_triggered_buffer_setup(). Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com> Link: https://lore.kernel.org/r/20220702085005.31666-1-marcus.folkesson@gmail.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2022-04-10iio: magnetometer: rm3100: Stop abusing the ->currentmodeMiquel Raynal1-12/+3
This is an internal variable for the core, here it is set to a "default" value by the driver in order to later be able to perform checks against it. None of this is needed because this check actually cares about the buffers being enabled or not. So it is an unproper side-channel access to the information "are the buffers enabled?", returned officially by the iio_buffer_enabled() helper. Use this helper instead. Cc: Song Qiang <songqiang1304521@gmail.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/r/20220207143840.707510-3-miquel.raynal@bootlin.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2022-02-18iio:magnetometer:rm3100: Move exports to IIO_RM3100 namespaceJonathan Cameron1-4/+4
In order to avoid unnecessary pollution of the global symbol namespace move the common/library functions into a specific namespace and import that into the bus specific device drivers that use them. For more information see https://lwn.net/Articles/760045/ Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Song Qiang <songqiang1304521@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20220130205701.334592-13-jic23@kernel.org
2021-06-14iio: magn: rm3100: Fix alignment of buffer in ↵Jonathan Cameron1-1/+2
iio_push_to_buffers_with_timestamp() Add __aligned(8) to ensure the buffer passed to iio_push_to_buffers_with_timestamp() is suitable for the naturally aligned timestamp that will be inserted. Here an explicit structure is not used, because this buffer is used in a non-trivial way for data repacking. Fixes: 121354b2eceb ("iio: magnetometer: Add driver support for PNI RM3100") Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Cc: Song Qiang <songqiang1304521@gmail.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20210613152301.571002-6-jic23@kernel.org
2021-05-17iio: core: move @id from struct iio_dev to struct iio_dev_opaqueJonathan Cameron1-1/+1
Continuing from Alexandru Ardelean's introduction of the split between driver modifiable fields and those that should only be set by the core. This could have been done in two steps to make the actual move after introducing iio_device_id() but there seemed limited point to that given how mechanical the majority of the patch is. Includes fixup from Alex for missing mxs-lradc-adc conversion. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com> Link: https://lore.kernel.org/r/20210426174911.397061-2-jic23@kernel.org
2021-03-25iio: fix devm_iio_trigger_alloc with parent.cocciGwendal Grignou1-1/+0
Use cocci semantic patch: @@ expression trigger, P; @@ trigger = devm_iio_trigger_alloc(P, ...); ... - trigger->dev.parent = P; To remove trigger->dev.parent, since it is set by default. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20210309193620.2176163-3-gwendal@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-06-20iio: Move attach/detach of the poll func to the coreLars-Peter Clausen1-2/+0
All devices using a triggered buffer need to attach and detach the trigger to the device in order to properly work. Instead of doing this in each and every driver by hand move this into the core. At this point in time, all drivers should have been resolved to attach/detach the poll-function in the same order. This patch removes all explicit calls of iio_triggered_buffer_postenable() & iio_triggered_buffer_predisable() in all drivers, since the core handles now the pollfunc attach/detach. The more peculiar change is for the 'at91-sama5d2_adc' driver, since it's not immediately obvious that removing the hooks doesn't break anything. Eugen was able to test on at91-sama5d2-adc driver, sama5d2-xplained board. All seems to be fine. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Tested-by: Eugen Hristev <eugen.hristev@microchip.com> #for at91-sama5d2-adc Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-06-14iio: remove explicit IIO device parent assignmentAlexandru Ardelean1-1/+0
This patch applies the semantic patch: @@ expression I, P, SP; @@ I = devm_iio_device_alloc(P, SP); ... - I->dev.parent = P; It updates 302 files and does 307 deletions. This semantic patch also removes some comments like '/* Establish that the iio_dev is a child of the i2c device */' But this is is only done in case where the block is left empty. The patch does not seem to cover all cases. It looks like in some cases a different variable is used in some cases to assign the parent, but it points to the same reference. In other cases, the block covered by ... may be just too big to be covered by the semantic patch. However, this looks pretty good as well, as it does cover a big bulk of the drivers that should remove the parent assignment. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-05-03iio: magnetometer: rm3100: Use get_unaligned_be24()Andy Shevchenko1-2/+3
This makes the driver code slightly easier to read. Cc: Song Qiang <songqiang1304521@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-11-16iio: magnetometer: Add driver support for PNI RM3100Song Qiang1-0/+616
PNI RM3100 is a high resolution, large signal immunity magnetometer, composed of 3 single sensors and a processing chip with a MagI2C interface. Following functions are available: - Single-shot measurement from /sys/bus/iio/devices/iio:deviceX/in_magn_{axis}_raw - Triggerd buffer measurement. - DRDY pin for data ready trigger. - Both i2c and spi interface are supported. - Both interrupt and polling measurement is supported, depends on if the 'interrupts' in DT is declared. Signed-off-by: Song Qiang <songqiang1304521@gmail.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>