aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/magnetometer/mag3110.c
AgeCommit message (Collapse)Author
2021-01-09iio:magnetometer:mag3110: Fix alignment and data leak issues.Jonathan Cameron
commit 89deb1334252ea4a8491d47654811e28b0790364 upstream 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 [sudip: adjust context] Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
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>