summaryrefslogtreecommitdiffstats
path: root/drivers/iio/magnetometer/mag3110.c
AgeCommit message (Collapse)Author
2020-12-03iio:magnetometer:mag3110: Fix alignment and data leak issues.Jonathan Cameron
One of a class of bugs pointed out by Lars in a recent review. iio_push_to_buffers_with_timestamp() assumes the buffer used is aligned to the size of the timestamp (8 bytes). This is not guaranteed in this driver which uses an array of smaller elements on the stack. As Lars also noted this anti pattern can involve a leak of data to userspace and that indeed can happen here. We close both issues by moving to a suitable structure in the iio_priv() data. This data is allocated with kzalloc() so no data can leak apart from previous readings. The explicit alignment of ts is not necessary in this case but does make the code slightly less fragile so I have included it. Fixes: 39631b5f9584 ("iio: Add Freescale mag3110 magnetometer driver") Reported-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Cc: <Stable@vger.kernel.org> Link: https://lore.kernel.org/r/20200920112742.170751-4-jic23@kernel.org
2020-09-03iio: magnetometer: mag3110: Simplify with dev_err_probe()Krzysztof Kozlowski
Common pattern of handling deferred probe can be simplified with dev_err_probe(). Less code and also it prints the error value. Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Link: https://lore.kernel.org/r/20200829064726.26268-17-krzk@kernel.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2020-06-14iio: remove explicit IIO device parent assignmentAlexandru Ardelean
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>
2019-06-05treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 330Thomas Gleixner
Based on 1 normalized pattern(s): this file is subject to the terms and conditions of version 2 of the gnu general public license see the file copying in the main directory of this archive for more details extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 55 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Alexios Zavras <alexios.zavras@intel.com> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190530000436.108941081@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-01-12iio: magnetometer: mag3110: add vdd/vddio regulator operation supportAnson Huang
The magnetometer's power supplies could be controllable on some platforms, such as i.MX6Q-SABRESD board, the mag3110's power supplies are controlled by a GPIO fixed regulator, need to make sure the regulators are enabled before any communication with mag3110, this patch adds vdd/vddio regulator operation support. Signed-off-by: Anson Huang <Anson.Huang@nxp.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-05-12iio: magnetometer: mag3110: Add ability to run in continuous modeRichard Tresidder
Adds the ability to run the Mag3110 in continuous mode to speed up the sampling rate. Depending on the sampling rate requested the device can be put in or out of continuous mode automatically. Shifting out of continuous mode requires a potential 1 / ODR wait which is also implemented. Modified the sleep method when data is not ready to allow for sampling > 50sps to work. Signed-off-by: Richard Tresidder <rtresidd@electromag.com.au> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2017-08-22iio:magnetometer: drop assign iio_info.driver_module and iio_trigger_ops.ownerJonathan Cameron
The equivalent of both of these are now done via macro magic when the relevant register calls are made. The actual structure elements will shortly go away. Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
2017-03-19iio: magnetometer: mag3110: Add OF device ID tableJavier Martinez Canillas
The driver doesn't have a struct of_device_id table but supported devices are registered via Device Trees. This is working on the assumption that a I2C device registered via OF will always match a legacy I2C device ID and that the MODALIAS reported will always be of the form i2c:<device>. But this could change in the future so the correct approach is to have an OF device ID table if the devices are registered via OF. Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2017-01-21iio: magnetometer: mag3110: claim direct mode during raw writesAlison Schofield
Driver was checking for direct mode but not locking it. Use claim/release helper functions to guarantee the device stays in direct mode during raw writes. Signed-off-by: Alison Schofield <amsfield22@gmail.com> Acked-by: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-08-21iio: magnetometer: mag3110: claim direct mode during raw readsAlison Schofield
Driver was checking for direct mode but not locking it. Use claim/release helper functions to guarantee the device stays in direct mode during raw reads. Signed-off-by: Alison Schofield <amsfield22@gmail.com> Cc: Daniel Baluta <daniel.baluta@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-06-30iio:core: timestamping clock selection supportGregor Boirie
Adds a new per-device sysfs attribute "current_timestamp_clock" to allow userspace to select a particular POSIX clock for buffered samples and events timestamping. Following clocks, as listed in clock_gettime(2), are supported: CLOCK_REALTIME, CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, CLOCK_REALTIME_COARSE, CLOCK_MONOTONIC_COARSE, CLOCK_BOOTTIME and CLOCK_TAI. Signed-off-by: Gregor Boirie <gregor.boirie@parrot.com> Acked-by: Sanchayan Maity <maitysanchayan@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2015-04-01iio: magnetometer: mag3110: Place driver on standby on errorCristina Opriceana
Place driver on standby mode on error in order to prevent wasting power. Move standby function above to be seen by the new call. Signed-off-by: Cristina Opriceana <cristina.opriceana@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2014-05-03iio:magnetometer:mag3110: Enable user offset calibrationPeter Meerwald
add IIO_CHAN_INFO_CALIBBIAS Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-05-03iio:magnetometer:mag3110: Fix initialization of ctrl_reg1Peter Meerwald
DR bits need to be shifted; since MAG3110_CTRL_DR_DEFAULT is zero, the change has no effect Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-02-25iio:magnetometer:mag3110: Fix unreachable codePeter Meerwald
drivers/iio/magnetometer/mag3110.c:197 mag3110_read_raw() info: ignoring unreachable code. drivers/iio/magnetometer/mag3110.c 185 case IIO_CHAN_INFO_SCALE: 186 switch (chan->type) { 187 case IIO_MAGN: 188 *val = 0; 189 *val2 = 1000; 190 return IIO_VAL_INT_PLUS_MICRO; 191 case IIO_TEMP: 192 *val = 1000; 193 return IIO_VAL_INT; 194 default: 195 return -EINVAL; 196 } 197 return IIO_VAL_INT_PLUS_MICRO; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ introduced by f9279d3a, mag3110: Scale factor missing Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-02-15iio:magnetometer:mag3110: Scale factor missing for temperaturePeter Meerwald
temperature is reported in milli-Celsius Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-02-08iio:magnetometer:mag3110: Fix output of decimal digits in show_int_plus_micros()Peter Meerwald
need to print leading zeros, hence "%d.%06d" Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2014-02-08iio:magnetometer:mag3110: Report busy in _read_raw() / write_raw() when ↵Peter Meerwald
buffer is enabled individual reads are not permitted concurrently with buffered reads Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-12-17iio:mag:mag3110 replaces IIO_ST macro with explicit entries to struct scan_typeJonathan Cameron
The IIO_ST macro no longer covers all the elements of struct scan_type and has this has lead to some bugs being introduced. The drivers are easier to follow with this structure being directly filled so that is now preferred. Signed-off-by: Jonathan Cameron <jic23@kernel.org> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
2013-11-09iio: Fix mag3110 scan_typePeter Meerwald
last argument of IIO_ST is shift, not endianness Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2013-10-23iio: Add Freescale mag3110 magnetometer driverPeter Meerwald
three-axis digital magnetometer with I2C interface datasheet is available from http://cache.freescale.com/files/sensors/doc/data_sheet/MAG3110.pdf Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net> Signed-off-by: Jonathan Cameron <jic23@kernel.org>