Now that all users are using the proper accessors, we can mark
masklength as __private so that no one tries to write. We also get help
from checkers in warning us in case someone does it.
To access the private field from IIO core code, we need to use the
ACCESS_PRIVATE() macro.
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240726-dev-iio-masklength-private3-v1-23-82913fc0fb87@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Use iio_get_masklength() to access '.masklength' so it can be annotated
as __private when there are no more direct users of it.
While at it, remove some unneeded line breaks.
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Reviewed-by: Alexandru Ardelean <aardelean@baylibre.com>
Link: https://patch.msgid.link/20240702-dev-iio-masklength-private-v1-3-98193bf536a6@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Add the necessary infrastructure to the IIO core to support a new
optional DMABUF based interface.
With this new interface, DMABUF objects (externally created) can be
attached to a IIO buffer, and subsequently used for data transfer.
A userspace application can then use this interface to share DMABUF
objects between several interfaces, allowing it to transfer data in a
zero-copy fashion, for instance between IIO and the USB stack.
The userspace application can also memory-map the DMABUF objects, and
access the sample data directly. The advantage of doing this vs. the
read() interface is that it avoids an extra copy of the data between the
kernel and userspace. This is particularly userful for high-speed
devices which produce several megabytes or even gigabytes of data per
second.
As part of the interface, 3 new IOCTLs have been added:
IIO_BUFFER_DMABUF_ATTACH_IOCTL(int fd):
Attach the DMABUF object identified by the given file descriptor to the
buffer.
IIO_BUFFER_DMABUF_DETACH_IOCTL(int fd):
Detach the DMABUF object identified by the given file descriptor from
the buffer. Note that closing the IIO buffer's file descriptor will
automatically detach all previously attached DMABUF objects.
IIO_BUFFER_DMABUF_ENQUEUE_IOCTL(struct iio_dmabuf *):
Request a data transfer to/from the given DMABUF object. Its file
descriptor, as well as the transfer size and flags are provided in the
"iio_dmabuf" structure.
These three IOCTLs have to be performed on the IIO buffer's file
descriptor, obtained using the IIO_BUFFER_GET_FD_IOCTL() ioctl.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Co-developed-by: Nuno Sa <nuno.sa@analog.com>
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Link: https://patch.msgid.link/20240620122726.41232-4-paul@crapouillou.net
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This adds new fields to the iio_channel structure to support multiple
scan types per channel. This is useful for devices that support multiple
resolution modes or other modes that require different data formats of
the raw data.
To make use of this, drivers need to implement the new callback
get_current_scan_type() to resolve the scan type for a given channel
based on the current state of the driver. There is a new scan_type_ext
field in the iio_channel structure that should be used to store the
scan types for any channel that has more than one. There is also a new
flag has_ext_scan_type that acts as a type discriminator for the
scan_type/ext_scan_type union. A union is used so that we don't grow
the size of the iio_channel structure and also makes it clear that
scan_type and ext_scan_type are mutually exclusive.
The buffer code is the only code in the IIO core code that is using the
scan_type field. This patch updates the buffer code to use the new
iio_channel_validate_scan_type() function to ensure it is returning the
correct scan type for the current state of the device when reading the
sysfs attributes. The buffer validation code is also update to validate
any additional scan types that are set in the scan_type_ext field. Part
of that code is refactored to a new function to avoid duplication.
Some userspace tools may need to be updated to re-read the scan type
after writing any other attribute. During testing, we noticed that we
had to restart iiod to get it to re-read the scan type after enabling
oversampling on the ad7380 driver.
Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20240530-iio-add-support-for-multiple-scan-types-v3-3-cbc4acea2cfa@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
By using struct iio_scan_type, we can simplify the code by removing
lots of duplicate pointer dereferences. This make the code a bit easier
to read.
This also prepares for a future where channels may have more than one
scan_type.
Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20240530-iio-add-support-for-multiple-scan-types-v3-2-cbc4acea2cfa@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Since masklength is marked as [INTERN], no drivers should assign it and
the value will always be 0. Therefore, the local ml accumulator variable
in iio_buffers_alloc_sysfs_and_mask() will always start out as 0.
This changes the code to explicitly set ml to 0 to make it clear that
drivers should not be trying to override the masklength field.
Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://lore.kernel.org/r/20240425-b4-iio-masklength-cleanup-v1-3-d3d16318274d@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Use an explicit IIO_SEPARATE instead of 0 for the 'shared_by' parameter
when calling __iio_add_chan_devattr().
For some reason, commit 3704432fb1 ("iio: refactor info mask and ext_info
attribute creation.") updated only 1 place out of 4.
Update the remaining ones now.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/1d17f57423172fcb9d9797cfe7c8282f356049c2.1702831285.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Add documentation explaining why the code which scans all available scan
masks is checking only a single long worth of bits even though the code
was intended to be supporting masks wider than single long.
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/ef61c2c1e9a1c5e9f713f656871fdcb1652afdc2.1697452986.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Just cosmetics. No functional change intended...
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20230216101452.591805-4-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
For output buffers, there's no guarantee that the buffer won't be full
in the first iteration of the loop in which case we would block
independently of userspace passing O_NONBLOCK or not. Fix it by always
checking the flag before going to sleep.
While at it (and as it's a bit related), refactored the loop so that the
stop condition is 'written != n', i.e, run the loop until all data has
been copied into the IIO buffers. This makes the code a bit simpler.
Fixes: 9eeee3b0bf ("iio: Add output buffer support")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20230216101452.591805-3-nuno.sa@analog.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
If for some reason 'rb->access->write()' does not write the full
requested data and the O_NONBLOCK is set, we would return 'n' to
userspace which is not really truth. Hence, let's return the number of
bytes we effectively wrote.
Fixes: 9eeee3b0bf ("iio: Add output buffer support")
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20230216101452.591805-2-nuno.sa@analog.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
The iio_triggered_buffer_setup_ext() and the
devm_iio_kfifo_buffer_setup_ext() were changed by
commit 15097c7a1a ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
to silently expect that all attributes given in buffer_attrs array are
device-attributes. This expectation was not forced by the API - and some
drivers did register attributes created by IIO_CONST_ATTR().
When using IIO_CONST_ATTRs the added attribute "wrapping" does not copy
the pointer to stored string constant and when the sysfs file is read the
kernel will access to invalid location.
Change the function signatures to expect an array of iio_dev_attrs to
avoid similar errors in the future.
Merge conflict resolved whilst applying due to patch crossing with
two new drivers (kx022a accelerometer and ad4130 ADC).
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Tested-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Link: https://lore.kernel.org/r/63f54787a684eb1232f1c5d275a09c786987fe4a.1664782676.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Now that there are no more users accessing 'mlock' directly, we can move
it to the iio_dev private structure. Hence, it's now explicit that new
driver's should not directly use this lock.
Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20221012151620.1725215-5-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
As reported by checkpatch.pl. Where possible use DEVICE_ATTR_RO(),
DEVICE_ATTR_RW(), and __ATTR_RO(). Change function names to be
<var>_show() for read and <var>_store() for write.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Joe Simmons-Talbott <joetalbott@gmail.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220601185414.251571-1-joetalbott@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
strtobool() is deprecated and just a wrapper around kstrtobool().Replace
it with kstrtobool() so the deprecated function can be removed eventually.
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220409105812.2113895-1-lars@metafoo.de
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This entry should, under no situation, be modified by device
drivers. Now that we have limited its read access to device drivers
really needing it and did so through a dedicated helper, we can
easily move this variable to the opaque structure in order to
prevent any further modification from non-authorized code (out of the
core, basically).
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Link: https://lore.kernel.org/r/20220207143840.707510-12-miquel.raynal@bootlin.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Add runtime check to verify whether storagebits are at least as big
as shifted realbits. This should help spot broken drivers which may
set realbits + shift above storagebits.
Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://lore.kernel.org/r/20220328195307.154422-1-marex@denx.de
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
In preparation to limit the scope of the list iterator variable to the
list traversal loop, use a dedicated pointer to iterate through the
list [1].
Since that variable should not be used past the loop iteration, a
separate variable is used to 'remember the current location within the
loop'.
To either continue iterating from that position or start a new
iteration (if the previous iteration was complete) list_prepare_entry()
is used.
Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20220331230632.957634-1-jakobkoschel@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This cycle we had quite a few series that applied similar changes
to lots of drivers. To keep this description manageable I have
called those out in their own section rather than per driver.
Particularly pleased to see the long running AFE precision series
going in this cycle.
Series includes some late breaking fixes.
New device support
* adi,ada4250 amplifier
- New driver and dt bindings for this programmable gain amplifier.
* adi,admv1014 microwave down-converter
- New driver, dt bindings and some device specific ABI that
may be generalized as more drivers for devices similar to this
are added.
* adi,admv4420 K Band down-converter.
- New driver and dt bindings.
* adi,adxl367 accelerometer driver.
- New driver, dt-bindings + some new IIO ABI definitions to support
reference magnitude events where an estimate of the acceleration
due to gravity has been removed.
- A few fixes as follow up patches.
* adi,ltc2688 DAC with toggle and dither modes.
- New driver and bindings. Includes some new driver specific (for now)
ABI for handling toggle mode and the addition of a dither waveform to
the DAC output.
* AFE (analog front end) add support for additional types of analog device
in front of an ADC.
- RTD temperature sensors with dt bindings.
- Temperature transducers wit dt bindings.
- Related cleanup and features listed in other sections below.
* maxim,ds3502 potentiometer.
- Add support to ds1803 driver which required significant rework.
* mediatek,mt2701-auxadc driver
- Add mediatek,mt8186-auxadc - id table and chip specific info only.
* semtech,sx9324, semtech,ax9360
- Substantial refactoring of sx9310 to extract core logic for reuse
into a separate module
- New driver using this supporting sx9324 proximity sensors.
- New driver using this supporting sx9360 proximity sensors.
* silan,sc7a20
- Compatible with the st,lis2dh (or nearly anyway) so add ID and
chip specific info to enable support. Also silan vendor ID added
for dt-bindings.
Staging graduation
* adi,ad7280a monitoring ADC for stacked lithium-ion batteries in
electric cars and similar.
- Substantial rework of driver required to bring inline with current
IIO best practice. An unusual device in IIO so some interesting features
we may see more of in future.
Multiple driver/core cleanup
- Use sysfs_emit() in simple locations where there is no path to change
to various core created attributes.
- Trivial white space fixes around inconsistency between space after { and
before } in id tables.
- Introduce new handling for fractional types to avoid repeated similar
implementations. Use this in 3 drivers. Note this is also targeted
at future use in the AFE driver and was motivated by discussions
around the precision related work on that driver.
- of related header cleanups - drop of*.h and add mod_devicetable.h as
appropriate.
- Move a number of symbol exports into IIO_* namespaces. Two categories,
1) Library used by multiple drivers e.g. st_sensors
2) Core driver module exporting functions used by bus specific modules.
A few related cleanups in this set.
- Switch from CONFIG_PM_* guards to new DEFINE_SIMPLE_DEV_PM_OPS() and
similar to simplify drivers and take advantage of these new macros
allowing the compiler to do the job or removing unused code without
the need for __maybe_unused markings. Conversion of other drivers to
these new macros ongoing.
Features
* adi,adf4350
- Switch from of specific to generic device properties enabling use with
other firmware types.
* adi,adx345
- Switch from of specific to generic device properties.
- Add ACPI ID ADS0345
- Related driver cleanup.
* adi,hmc425a
- Switch from of specific to generic device properties.
* afe analog rescaler driver
- Wider range of types supported for scale.
- Support offset.
- Kunit tests.
* atlas,ezo-sensor
- Convert from of to device properties.
* fsl,mma8452
- Support mount matrix.
* infineon,dps310:
- Add ACPI ID IFX3100.
* invensense,mpu6050
- Convert to generic device properties.
* maxim,ds1803
- Add out_raw_available before supporting more devices.
- Convert from of specific to device properties.
* samsung,ssp_sensors
- Convert from of specific to device properties.
* st,stm32-timer trigger
- Convert from of specific to device properties.
* ti,hdc101x
- Add ACPI ID TXNW1010.
* ti,tsc2046:
- Add read_raw support to enable use of iio_hwmon and similar.
Fixes / cleanup.
* mailmap
- Update for Cai Huoqing
* MAINTAINERS
- Fix Analog Devices related links.
- Add entry for ADRF6780
- Add entry for ADMV1013
- Add entry for AD7293
- Add entry for ADMV8818
- Update files listed for adis-lib
* iio core:
- Fix wrong comment about current_mode being something a driver should
ever access.
- Use struct_size() rather than open coding in industrialio-hw-consumer
* adi,axl355
- Use units.h definitions instead of local versions.
* adi,adis-lib
- Simplify *updated_bits() macro
- Whitespace cleanup.
* afe - Note many of these fixes only apply to particular configurations
so the problems have probably not been seen in the wild, but will be
visible with new usecases enabled this cycle.
- Fix application of consumer scale for IIO_VAL_INT.
- Apply a scale of 1 when no scale is provided.
- Make best effort to establish a valid offset value for fractional
cases.
- Use s64 for scale calculations where parameters may be signed.
- Tidy up include order.
- Improve accuracy for small fractional sales
- Reduce risk of integer overflow.
* ams,as3935
- Use devm_delayed_work_autocancel() to replace open coded equivalent.
* aspeed,adc
- Fix wrong use of divider flag.
* atmel,sama5d2-adc
- Relax atmel,trigger-edge-type to optional.
- Drop Ludovic Desroches from listed maintainers of the dt-binding
inline with previous MAINTAINERS entry update.
* fsl,mma8452
- Fix probing when i2c_device_id used.
- dev_get_drvdata() on the iio_dev->dev, no longer returns iio_dev.
Use dev_to_iio_dev() instead. Note the original path in here
worked more by luck than design.
* invensense,mpu6050
- Drop ACPI_PTR() protection to avoid an unused warning.
- Use fact ACPI_COMPANION() returns null when ACPI_HANDLE() does to
simplify handling.
* motorola,cpcap-adc
- Drop unused assignment.
* qcom,spmi-adc
- Fix wrong example of 'reg' in binding document.
* renesas,rzg2l-adc
- Trivial typo fix.
* semtech,sx9360
- Fix wrong register handling for event generation.
* st_sensors
- Allow manual disabling of I2C or SPI module if not needed for a particular
board. Default is still to enable the bus specific module if
appropriate bus is supported.
* st,lsm6dsx
- dev_get_drvdata() on the iio_dev->dev, no longer returns iio_dev.
Use dev_to_iio_dev() instead.
* ti,palmas-gpadc
- Split the interrupt fields in the dt-binding example
* ti,tsc2046
- Rework state machine to improve readability after recent debugging of
an issue fixed elsewhere.
- Add a sanity check to avoid very large memory allocations if a crazy
delay is specified.
* ti,twl6030
- Add error handling if devm_request_threaded_irq() fails.
* xilinx,ams
- Use devm_delayed_work_autocancel() instead of open coding equivalent.
- Fix missing required clock entry in dt-binding.
- Fix miss counting of channels resulting in ps channels not
being enabled.
- Fix incorrect values written to sequencer registers.
- Fix sequence for single channel reading.
-----BEGIN PGP SIGNATURE-----
iQJFBAABCAAvFiEEbilms4eEBlKRJoGxVIU0mcT0FogFAmIfdM8RHGppYzIzQGtl
cm5lbC5vcmcACgkQVIU0mcT0FoiGlQ//UyRpMX9Bv97LAbMDnqIHLYroTLJA3WFQ
AaL/DKB1cVjBCoHlp24qaQrmncvifPF7sKJGKWf7yCHL5fraAYL/kHsCo/jECTho
QOk9QaPAMP9ChOoVoP8iz5qrdF2qyoFUG69bX+QYeKhSKzcK1QPRTQ13LIL43d9p
OJX47Cu7FfFwuAs5VKSVgpcII0tctv+Fdo6BkkeI+6w/vx2sFSzRaqRtc1ZU4Uav
s51dM9JMos52e/G8yQAEOC24QUId4EHxo7QR8WjzZ47yIHRulpYwM6pWAtvOqEy9
eV++yz581+Uqs/qaDDk8nJdpa8aEv/NvfAK6gufB9UOWziMoR3G1pPFWoOLbcyIt
IcUG+QyyEiIlmlwDE/m2OcSMzsxgrkEHNb3SE7ZkWZKP8OasGdVMHa7yEKCgLmzM
S8EY9TsNA50A2VtowAPrdk74TVG2WeIDvEH2MMAUMjgW2DzsW9cmwFrziyj7ZPLX
onoEjd/kpL2zzAArEadvzD1z1lLJcOUWn8ST2kbPQG8n/rp5y2u5PvgWRoO9zJlD
ztX614XYRgRUhMrgb0q0nCTi07mnBZrR3P8Hnx1HOoZon/DIqPSL7NumITG09cQc
fHqewQOU/WqoTH4tNvfywnBL/VAcxKFlc0B2rWIvp6dD5b0TU34ZdebcjLT1zYeC
6YQKbRaRjVg=
=UnWv
-----END PGP SIGNATURE-----
Merge tag 'iio-for-5.18a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next
Jonathan writes:
First set of new device support, fixes, cleanups and features for IIO in 5.18
This cycle we had quite a few series that applied similar changes
to lots of drivers. To keep this description manageable I have
called those out in their own section rather than per driver.
Particularly pleased to see the long running AFE precision series
going in this cycle.
Series includes some late breaking fixes.
New device support
* adi,ada4250 amplifier
- New driver and dt bindings for this programmable gain amplifier.
* adi,admv1014 microwave down-converter
- New driver, dt bindings and some device specific ABI that
may be generalized as more drivers for devices similar to this
are added.
* adi,admv4420 K Band down-converter.
- New driver and dt bindings.
* adi,adxl367 accelerometer driver.
- New driver, dt-bindings + some new IIO ABI definitions to support
reference magnitude events where an estimate of the acceleration
due to gravity has been removed.
- A few fixes as follow up patches.
* adi,ltc2688 DAC with toggle and dither modes.
- New driver and bindings. Includes some new driver specific (for now)
ABI for handling toggle mode and the addition of a dither waveform to
the DAC output.
* AFE (analog front end) add support for additional types of analog device
in front of an ADC.
- RTD temperature sensors with dt bindings.
- Temperature transducers wit dt bindings.
- Related cleanup and features listed in other sections below.
* maxim,ds3502 potentiometer.
- Add support to ds1803 driver which required significant rework.
* mediatek,mt2701-auxadc driver
- Add mediatek,mt8186-auxadc - id table and chip specific info only.
* semtech,sx9324, semtech,ax9360
- Substantial refactoring of sx9310 to extract core logic for reuse
into a separate module
- New driver using this supporting sx9324 proximity sensors.
- New driver using this supporting sx9360 proximity sensors.
* silan,sc7a20
- Compatible with the st,lis2dh (or nearly anyway) so add ID and
chip specific info to enable support. Also silan vendor ID added
for dt-bindings.
Staging graduation
* adi,ad7280a monitoring ADC for stacked lithium-ion batteries in
electric cars and similar.
- Substantial rework of driver required to bring inline with current
IIO best practice. An unusual device in IIO so some interesting features
we may see more of in future.
Multiple driver/core cleanup
- Use sysfs_emit() in simple locations where there is no path to change
to various core created attributes.
- Trivial white space fixes around inconsistency between space after { and
before } in id tables.
- Introduce new handling for fractional types to avoid repeated similar
implementations. Use this in 3 drivers. Note this is also targeted
at future use in the AFE driver and was motivated by discussions
around the precision related work on that driver.
- of related header cleanups - drop of*.h and add mod_devicetable.h as
appropriate.
- Move a number of symbol exports into IIO_* namespaces. Two categories,
1) Library used by multiple drivers e.g. st_sensors
2) Core driver module exporting functions used by bus specific modules.
A few related cleanups in this set.
- Switch from CONFIG_PM_* guards to new DEFINE_SIMPLE_DEV_PM_OPS() and
similar to simplify drivers and take advantage of these new macros
allowing the compiler to do the job or removing unused code without
the need for __maybe_unused markings. Conversion of other drivers to
these new macros ongoing.
Features
* adi,adf4350
- Switch from of specific to generic device properties enabling use with
other firmware types.
* adi,adx345
- Switch from of specific to generic device properties.
- Add ACPI ID ADS0345
- Related driver cleanup.
* adi,hmc425a
- Switch from of specific to generic device properties.
* afe analog rescaler driver
- Wider range of types supported for scale.
- Support offset.
- Kunit tests.
* atlas,ezo-sensor
- Convert from of to device properties.
* fsl,mma8452
- Support mount matrix.
* infineon,dps310:
- Add ACPI ID IFX3100.
* invensense,mpu6050
- Convert to generic device properties.
* maxim,ds1803
- Add out_raw_available before supporting more devices.
- Convert from of specific to device properties.
* samsung,ssp_sensors
- Convert from of specific to device properties.
* st,stm32-timer trigger
- Convert from of specific to device properties.
* ti,hdc101x
- Add ACPI ID TXNW1010.
* ti,tsc2046:
- Add read_raw support to enable use of iio_hwmon and similar.
Fixes / cleanup.
* mailmap
- Update for Cai Huoqing
* MAINTAINERS
- Fix Analog Devices related links.
- Add entry for ADRF6780
- Add entry for ADMV1013
- Add entry for AD7293
- Add entry for ADMV8818
- Update files listed for adis-lib
* iio core:
- Fix wrong comment about current_mode being something a driver should
ever access.
- Use struct_size() rather than open coding in industrialio-hw-consumer
* adi,axl355
- Use units.h definitions instead of local versions.
* adi,adis-lib
- Simplify *updated_bits() macro
- Whitespace cleanup.
* afe - Note many of these fixes only apply to particular configurations
so the problems have probably not been seen in the wild, but will be
visible with new usecases enabled this cycle.
- Fix application of consumer scale for IIO_VAL_INT.
- Apply a scale of 1 when no scale is provided.
- Make best effort to establish a valid offset value for fractional
cases.
- Use s64 for scale calculations where parameters may be signed.
- Tidy up include order.
- Improve accuracy for small fractional sales
- Reduce risk of integer overflow.
* ams,as3935
- Use devm_delayed_work_autocancel() to replace open coded equivalent.
* aspeed,adc
- Fix wrong use of divider flag.
* atmel,sama5d2-adc
- Relax atmel,trigger-edge-type to optional.
- Drop Ludovic Desroches from listed maintainers of the dt-binding
inline with previous MAINTAINERS entry update.
* fsl,mma8452
- Fix probing when i2c_device_id used.
- dev_get_drvdata() on the iio_dev->dev, no longer returns iio_dev.
Use dev_to_iio_dev() instead. Note the original path in here
worked more by luck than design.
* invensense,mpu6050
- Drop ACPI_PTR() protection to avoid an unused warning.
- Use fact ACPI_COMPANION() returns null when ACPI_HANDLE() does to
simplify handling.
* motorola,cpcap-adc
- Drop unused assignment.
* qcom,spmi-adc
- Fix wrong example of 'reg' in binding document.
* renesas,rzg2l-adc
- Trivial typo fix.
* semtech,sx9360
- Fix wrong register handling for event generation.
* st_sensors
- Allow manual disabling of I2C or SPI module if not needed for a particular
board. Default is still to enable the bus specific module if
appropriate bus is supported.
* st,lsm6dsx
- dev_get_drvdata() on the iio_dev->dev, no longer returns iio_dev.
Use dev_to_iio_dev() instead.
* ti,palmas-gpadc
- Split the interrupt fields in the dt-binding example
* ti,tsc2046
- Rework state machine to improve readability after recent debugging of
an issue fixed elsewhere.
- Add a sanity check to avoid very large memory allocations if a crazy
delay is specified.
* ti,twl6030
- Add error handling if devm_request_threaded_irq() fails.
* xilinx,ams
- Use devm_delayed_work_autocancel() instead of open coding equivalent.
- Fix missing required clock entry in dt-binding.
- Fix miss counting of channels resulting in ps channels not
being enabled.
- Fix incorrect values written to sequencer registers.
- Fix sequence for single channel reading.
* tag 'iio-for-5.18a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (245 commits)
iio: adc: xilinx-ams: Fix single channel switching sequence
iio: adc: xilinx-ams: Fixed wrong sequencer register settings
iio: adc: xilinx-ams: Fixed missing PS channels
dt-bindings: iio: adc: zynqmp_ams: Add clock entry
iio: accel: mma8452: use the correct logic to get mma8452_data
iio: adc: aspeed: Add divider flag to fix incorrect voltage reading.
iio: imu: st_lsm6dsx: use dev_to_iio_dev() to get iio_dev struct
dt-bindings: iio: Add ltc2688 documentation
iio: ABI: add ABI file for the LTC2688 DAC
iio: dac: add support for ltc2688
dt-bindings: iio: afe: add bindings for temperature transducers
dt-bindings: iio: afe: add bindings for temperature-sense-rtd
iio: afe: rescale: add temperature transducers
iio: afe: rescale: add RTD temperature sensor support
iio: test: add basic tests for the iio-rescale driver
iio: afe: rescale: reduce risk of integer overflow
iio: afe: rescale: fix accuracy for small fractional scales
iio: afe: rescale: add offset support
iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support
iio: afe: rescale: expose scale processing function
...
If we fail to copy the just created file descriptor to userland, we
try to clean up by putting back 'fd' and freeing 'ib'. The code uses
put_unused_fd() for the former which is wrong, as the file descriptor
was already published by fd_install() which gets called internally by
anon_inode_getfd().
This makes the error handling code leaving a half cleaned up file
descriptor table around and a partially destructed 'file' object,
allowing userland to play use-after-free tricks on us, by abusing
the still usable fd and making the code operate on a dangling
'file->private_data' pointer.
Instead of leaving the kernel in a partially corrupted state, don't
attempt to explicitly clean up and leave this to the process exit
path that'll release any still valid fds, including the one created
by the previous call to anon_inode_getfd(). Simply return -EFAULT to
indicate the error.
Fixes: f73f7f4da5 ("iio: buffer: add ioctl() to support opening extra buffers for IIO device")
Cc: stable@kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>
Cc: Alexandru Ardelean <ardeleanalex@gmail.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Nuno Sa <Nuno.Sa@analog.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Mathias Krause <minipli@grsecurity.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in checks for
size and alignment.
This patch converts the places in the IIO core that follow the pattern of
return s*printf(...)
to
return sysfs_emit(...)
This covers the new places that have been introduced where sprintf() is
used for formatting sysfs output since the last time this was done in
commit 83ca56b663 ("iio: core: Use sysfs_emit() (trivial bits)").
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20211216185217.1054495-2-lars@metafoo.de
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Use dedicated variable for index in the loop in the
iio_buffers_alloc_sysfs_and_mask(). This will make code cleaner and
less error prone as proved by previous changes done in this function.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20211013094923.2473-3-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
New device support
* adrf6780 microwave upconverter.
- New driver for this interesting device including bindings.
Features
* lite-on ltr501
- Add dt-bindings including vendor ID and of_device_id table.
- Add regulator support.
* sensiron,scd4x
- Add reporting of channel scale.
Cleanups including fixes for things in this cycle
* Tree wide: Another set of dev_err_probe() introductions to reduce
noise in logs when deferred probing is needed and provide more debug
info. Devices included this time:
- amlogic,meson_saradc
- capella,cm3605
- fsl,imx7d
- maxim,max1118
- maxim,max1241
- nxp,lpc18xx
- qcom,pm8xxxx-xoadc
- rockchip,saradc
- sharp,gp2ap002
- sterricson,ab8500
- ti,ads7950
* core - iio:buffer
- Fix a path where a ret value is not intialized.
* channel-mux
- Add support to mux core subsystem for a settling delay and use
it in the iio-channel-mux driver.
- Fix a few dt binding warnings.
* nxp,lpc18xx
- Convert to devm_ functions for all of probe and drop remove()
* st,lsm6dsx
- Suppress a warning due to lack of handling of an enum *_MAX entry
that is just there to get the size.
* st,stm32-adc
- Add generic channel binding, deprecating the old approach.
- Add nvmem support to get calibration data for the vrefint channel and
use it to perform such calibration.
- Add a binding for sample-time to the generic channel description as it
can be per channel.
* ti,adc128s052
- Use devm_ managed functions and drop remove()
* vti,sca3000
- Use sign_extend32() rather than opencoding.
* xilinx,xadc
- Drop irq field from state structure as now just used in probe.
-----BEGIN PGP SIGNATURE-----
iQJFBAABCAAvFiEEbilms4eEBlKRJoGxVIU0mcT0FogFAmFxyHIRHGppYzIzQGtl
cm5lbC5vcmcACgkQVIU0mcT0FojRCBAAgIbn0CdCVo5cmYZNV1cIcc1ReGBbfgHq
HopVcs9XDO4aHfzTLSa8bRhAp+bWCLq+ld/3vQ4tWDAJCXM4wh6VW9GOOMhqtDhr
TWYPC9jlH+/z5PWzySozCJ6CsHjU5Z96q+SbQGSfoQZr1xelCO9J51gbT0hZS3Dr
LntwcWQWCCC3LW0WGj4ApKJnW4exqi30ty09Qwfujpa9X5nO2soawSBApfIlInR8
rUrE0WBaE8/rx8ORwngrj+Tfz5F3WNz77KooFR6oGkXOuMOxSLIWS77nUntEQbUc
SRfHUJTTUbL5uI+8ZWZe7IWZzL/OX6uyicsJwcrLxzhw0Z/+i714fIMVLxAEHWqD
D+JgcKiGYO/aPgl23XDOYb8I010TF9tf0bkbNcxzOBa4xdhixBLeg5PyWOMhwUKt
uaslEGKduoJ4S7olcebZJAt3wEHp8YXn71LSkHt6M+fC7rRtzpfSK/L35ZHTb7PI
JxzWGYaD7ZdIHd4y3f7KOU/B2/aEv+ez6NLC+yb8+Bs15nZ/B17zLDAmcd+THvxi
QOBpm/K12rDfqSGV663UCtIq+elScx0J7bIuZG1JwPIfZAiwzBNrOTLZG0o+b3bD
JIYIoZX+45tCR5i3Lukk27QhJ2hJ/7VVOcSQ3aPcgoMTl6QCTV8Fo2oofAZ1JIMo
yHjv28K4ZyA=
=XWvW
-----END PGP SIGNATURE-----
Merge tag 'iio-for-5.16b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next
Jonathan writes:
2nd set of IIO new driver, cleanups and features for the 5.16 cycle
New device support
* adrf6780 microwave upconverter.
- New driver for this interesting device including bindings.
Features
* lite-on ltr501
- Add dt-bindings including vendor ID and of_device_id table.
- Add regulator support.
* sensiron,scd4x
- Add reporting of channel scale.
Cleanups including fixes for things in this cycle
* Tree wide: Another set of dev_err_probe() introductions to reduce
noise in logs when deferred probing is needed and provide more debug
info. Devices included this time:
- amlogic,meson_saradc
- capella,cm3605
- fsl,imx7d
- maxim,max1118
- maxim,max1241
- nxp,lpc18xx
- qcom,pm8xxxx-xoadc
- rockchip,saradc
- sharp,gp2ap002
- sterricson,ab8500
- ti,ads7950
* core - iio:buffer
- Fix a path where a ret value is not intialized.
* channel-mux
- Add support to mux core subsystem for a settling delay and use
it in the iio-channel-mux driver.
- Fix a few dt binding warnings.
* nxp,lpc18xx
- Convert to devm_ functions for all of probe and drop remove()
* st,lsm6dsx
- Suppress a warning due to lack of handling of an enum *_MAX entry
that is just there to get the size.
* st,stm32-adc
- Add generic channel binding, deprecating the old approach.
- Add nvmem support to get calibration data for the vrefint channel and
use it to perform such calibration.
- Add a binding for sample-time to the generic channel description as it
can be per channel.
* ti,adc128s052
- Use devm_ managed functions and drop remove()
* vti,sca3000
- Use sign_extend32() rather than opencoding.
* xilinx,xadc
- Drop irq field from state structure as now just used in probe.
* tag 'iio-for-5.16b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (36 commits)
dt-bindings: iio: frequency: add adrf6780 doc
iio: frequency: adrf6780: add support for ADRF6780
iio: chemical: scd4x: Add a scale for the co2 concentration reading
dt-bindings: iio: io-channel-mux: allow duplicate channel, labels
dt-bindings: iio: io-channel-mux: add optional #io-channel-cells
iio: adc: adc128s052: Simplify adc128_probe()
iio: multiplexer: iio-mux: Support settle-time-us property
dt-bindings: iio: io-channel-mux: Add property for settle time
mux: add support for delay after muxing
iio: adc: stm32-adc: use generic binding for sample-time
iio: adc: stm32-adc: add vrefint calibration support
iio: adc: stm32-adc: add support of internal channels
iio: adc: stm32-adc: add support of generic channels binding
iio: adc: stm32-adc: split channel init into several routines
dt-bindings: iio: stm32-adc: add nvmem support for vrefint internal channel
dt-bindings: iio: stm32-adc: add generic channel binding
iio: accel: sca3000: Use sign_extend32() instead of opencoding sign extension.
iio: xilinx-xadc: Remove `irq` field from state struct
iio: imu: st_lsm6dsx: Avoid potential array overflow in st_lsm6dsx_set_odr()
iio: light: gp2ap002: Make use of the helper function dev_err_probe()
...
As these are very late in the 5.15 cycle and non are particularly urgent,
they can wait for the merge window.
Key element in this set is Yang Yingliang has identified a number of
issues in error paths introduced recently when we added multiple
buffer support.
Other fixes:
* adi,ad5662
- Fix handling of i2c_master_send() return value.
* adi,ad5766
- Fix a wrong dt-property name that indicated wrong units and
did not mach the bindings.
- Associated 'fix' of the bindings example to have a possible scale.
* st,pressure-spi
- Add some missing entries to the spi_device_id table to ensure
auto-loading works.
* ti,tsc2046
- Fix a backwards comparison leading to a false dev_warn
-----BEGIN PGP SIGNATURE-----
iQJFBAABCAAvFiEEbilms4eEBlKRJoGxVIU0mcT0FogFAmFxs7kRHGppYzIzQGtl
cm5lbC5vcmcACgkQVIU0mcT0FojEXhAAn8OoUwEaViRbrVuPJmWCLuhZR8/ke1HE
9WFXYjVvr6+FIyxgOxTVhoVd0LmcqzgeMg0si8CvnXvmx0mYqRyGxSgZ0oSWOfNR
/RhfbL3RKyWmbp5ey3JuJxGS9Py1LXSFycsC7igjrgySqGo05kLrMpGkMr2g3d6a
OKBOaoiBQPEvYmkNlFLOhtWGHNA4mICmi7UWwcfeN667SWKT3VFpBllSQwRpRXtz
h/h0XhJg72x7JdJJsiBAWX9IsbBm9bXjaeXWZldDNnrZRS3VKTXzAkMTI0Wu0Rrq
voEXvh74ys280aXoh5eHzN4OLdGBTJLVRjNaEAUaSMry4oWPpnkkda9pYY8dCcaR
b8kPxn68PnrjbBG5et3PBo+/XAh7C0Ny2ETEqI8qlNk9adqUEl0wixuUUEljEqVE
2rB35SEJYJzl0V0Up2uZMzYhPsfw+kbZoLUPyLfL9uNW3r1l9xgQURTM74UZcSdI
cV2kcGWZdIX6IKVrChhPpeXcsS9ZWljWzUGu4IFBw1h9X6jwhbWJvACj889Rf4EI
+ndjCylpE4aJfoZI7JSg5i41KvEGbwE3SkrKZTMNWe6aPajhcylzeG9+jxsAYaPn
+hnKbPTE99oaopu1Od/s2EUtmIontZQy74aDfbQM3HU8fHmauk8/+L9kDNlkV2b3
ZWbSw6Z2g4g=
=jYCH
-----END PGP SIGNATURE-----
Merge tag 'iio-fixes-for-5.16a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next
Jonathan writes:
First set of IIO fixes for the 5.16 cycle
As these are very late in the 5.15 cycle and non are particularly urgent,
they can wait for the merge window.
Key element in this set is Yang Yingliang has identified a number of
issues in error paths introduced recently when we added multiple
buffer support.
Other fixes:
* adi,ad5662
- Fix handling of i2c_master_send() return value.
* adi,ad5766
- Fix a wrong dt-property name that indicated wrong units and
did not mach the bindings.
- Associated 'fix' of the bindings example to have a possible scale.
* st,pressure-spi
- Add some missing entries to the spi_device_id table to ensure
auto-loading works.
* ti,tsc2046
- Fix a backwards comparison leading to a false dev_warn
* tag 'iio-fixes-for-5.16a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio:
iio: buffer: Fix memory leak in iio_buffers_alloc_sysfs_and_mask()
iio: adc: tsc2046: fix scan interval warning
iio: core: fix double free in iio_device_unregister_sysfs()
iio: core: check return value when calling dev_set_name()
iio: buffer: Fix memory leak in iio_buffer_register_legacy_sysfs_groups()
iio: buffer: Fix double-free in iio_buffers_alloc_sysfs_and_mask()
iio: buffer: Fix memory leak in __iio_buffer_alloc_sysfs_and_mask()
iio: buffer: check return value of kstrdup_const()
iio: dac: ad5446: Fix ad5622_write() return value
Documentation:devicetree:bindings:iio:dac: Fix val
drivers: iio: dac: ad5766: Fix dt property name
iio: st_pressure_spi: Add missing entries SPI to device ID table
When 'iio_dev_opaque->buffer_ioctl_handler' alloc fails in
iio_buffers_alloc_sysfs_and_mask(), the 'attrs' allocated in
iio_buffer_register_legacy_sysfs_groups() will be leaked:
unreferenced object 0xffff888108568d00 (size 128):
comm "88", pid 2014, jiffies 4294963294 (age 26.920s)
hex dump (first 32 bytes):
80 3e da 02 80 88 ff ff 00 3a da 02 80 88 ff ff .>.......:......
00 35 da 02 80 88 ff ff 00 38 da 02 80 88 ff ff .5.......8......
backtrace:
[<0000000095a9e51e>] __kmalloc+0x1a3/0x2f0
[<00000000faa3735e>] iio_buffers_alloc_sysfs_and_mask+0xfa3/0x1480 [industrialio]
[<00000000a46384dc>] __iio_device_register+0x52e/0x1b40 [industrialio]
[<00000000210af05e>] __devm_iio_device_register+0x22/0x80 [industrialio]
[<00000000730d7b41>] adjd_s311_probe+0x195/0x200 [adjd_s311]
[<00000000c0f70eb9>] i2c_device_probe+0xa07/0xbb0
The iio_buffer_register_legacy_sysfs_groups() is
called in __iio_buffer_alloc_sysfs_and_mask(),
so move the iio_buffer_unregister_legacy_sysfs_groups()
into __iio_buffer_free_sysfs_and_mask(), then the memory
will be freed.
Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: d9a625744e ("iio: core: merge buffer/ & scan_elements/ attributes")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20211018063718.1971240-1-yangyingliang@huawei.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
When !iio_buffer_space_available(rb) is true and signal_pending(current)
is false the end of the do-while loop is reached and the uninitialized
variable ret is zero checked. Fix this by initializing variable ret to
zero.
Addresses-Coverity: ("Uninitialized scalar variable")
Fixes: 9eeee3b0bf ("iio: Add output buffer support")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20211015153254.33783-1-colin.king@canonical.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Currently IIO only supports buffer mode for capture devices like ADCs. Add
support for buffered mode for output devices like DACs.
The output buffer implementation is analogous to the input buffer
implementation. Instead of using read() to get data from the buffer write()
is used to copy data into the buffer.
poll() with POLLOUT will wakeup if there is space available.
Drivers can remove data from a buffer using iio_pop_from_buffer(), the
function can e.g. called from a trigger handler to write the data to
hardware.
A buffer can only be either a output buffer or an input, but not both. So,
for a device that has an ADC and DAC path, this will mean 2 IIO buffers
(one for each direction).
The direction of the buffer is decided by the new direction field of the
iio_buffer struct and should be set after allocating and before registering
it.
Co-developed-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Co-developed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Mihail Chindris <mihail.chindris@analog.com>
Link: https://lore.kernel.org/r/20211007080035.2531-2-mihail.chindris@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Whilst it is almost always possible to arrange for scan data to be
read directly into a buffer that is suitable for passing to
iio_push_to_buffers_with_timestamp(), there are a few places where
leading data needs to be skipped over.
For these cases introduce a function that will allocate an appropriate
sized and aligned bounce buffer (if not already allocated) and copy
the unaligned data into that before calling
iio_push_to_buffers_with_timestamp() on the bounce buffer.
We tie the lifespace of this buffer to that of the iio_dev.dev
which should ensure no memory leaks occur.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20210613151039.569883-2-jic23@kernel.org
When __iio_buffer_alloc_sysfs_and_mask() failed, 'unwind_idx' should be
set to 'i - 1' to prevent double-free when cleanup resources.
BUG: KASAN: double-free or invalid-free in __iio_buffer_free_sysfs_and_mask+0x32/0xb0 [industrialio]
Call Trace:
kfree+0x117/0x4c0
__iio_buffer_free_sysfs_and_mask+0x32/0xb0 [industrialio]
iio_buffers_alloc_sysfs_and_mask+0x60d/0x1570 [industrialio]
__iio_device_register+0x483/0x1a30 [industrialio]
ina2xx_probe+0x625/0x980 [ina2xx_adc]
Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: ee708e6baa ("iio: buffer: introduce support for attaching more IIO buffers")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20211013094923.2473-2-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Check return value of kstrdup_const() in iio_buffer_wrap_attr(),
or it will cause null-ptr-deref in kernfs_name_hash() when calling
device_add() as follows:
BUG: kernel NULL pointer dereference, address: 0000000000000000
RIP: 0010:strlen+0x0/0x20
Call Trace:
kernfs_name_hash+0x22/0x110
kernfs_find_ns+0x11d/0x390
kernfs_remove_by_name_ns+0x3b/0xb0
remove_files.isra.1+0x7b/0x190
internal_create_group+0x7f1/0xbb0
internal_create_groups+0xa3/0x150
device_add+0x8f0/0x2020
cdev_device_add+0xc3/0x160
__iio_device_register+0x1427/0x1b40 [industrialio]
__devm_iio_device_register+0x22/0x80 [industrialio]
adjd_s311_probe+0x195/0x200 [adjd_s311]
i2c_device_probe+0xa07/0xbb0
Reported-by: Hulk Robot <hulkci@huawei.com>
Fixes: 15097c7a1a ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20211013040438.1689277-1-yangyingliang@huawei.com
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This is more standard to have sanity checks at the entry of a function,
instead of allocating some memory first and having to free it if a
condition is not met.
Shuffle code a bit to check 'masklength' before calling 'bitmap_alloc()'
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/98a351adda1908c306e981b9cc86d3dbc79eb5ec.1626261211.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Variable in_loc is being assigned a value from a calculation
however the assignment is never read, so this redundant assignment
can be removed.
Clean up the following clang-analyzer warning:
drivers/iio/industrialio-buffer.c:929:3: warning: Value stored to
'in_loc' is never read [clang-analyzer-deadcode.DeadStores].
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Link: https://lore.kernel.org/r/1621246317-62725-1-git-send-email-jiapeng.chong@linux.alibaba.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This lock is only of interest to the IIO core, so make it only
visible there.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Link: https://lore.kernel.org/r/20210426174911.397061-7-jic23@kernel.org
No reason for this cached value to be exposed to drivers so move it
to the opaque structure.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Link: https://lore.kernel.org/r/20210426174911.397061-6-jic23@kernel.org
When dynamically allocating sysfs attributes, it's a good idea to call
sysfs_attr_init() on them to initialize lock_class_keys.
This change does that.
The lock_class_keys are set when the CONFIG_DEBUG_LOCK_ALLOC symbol is
enabled. Which is [likely] one reason why I did not see this during
development.
I also am not able to see this even with CONFIG_DEBUG_LOCK_ALLOC enabled,
so this may [likely] be reproduce-able on some system configurations.
This was reported via:
https://lore.kernel.org/linux-iio/CA+U=DsrsvGgXEF30-vXuXS_k=-mjSjiBwEEzwKb1hJVn1P98OA@mail.gmail.com/T/#u
Fixes: 15097c7a1a ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210402174226.630346-1-aardelean@deviqon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
As Lars pointed out, we could either return the FD vs memcpy-ing it to the
userspace data object.
However, this comment exposed a bug. We should return 0 or negative from
these ioctl() handlers. Because an ioctl() handler can also return
IIO_IOCTL_UNHANDLED (which is positive 1), which means that the ioctl()
handler doesn't support this ioctl number. Positive 1 could also be a valid
FD number in some corner cases.
The reason we did this is to be able to differentiate between an error
code and an unsupported ioctl number; for unsupported ioctl numbers, the
main loop should keep going.
Maybe we should change this to a higher negative number, to avoid such
cases when/if we add more ioctl() handlers.
Cc: Lars-Peter Clausen <lars@metafoo.de>
Fixes: f73f7f4da5 ("iio: buffer: add ioctl() to support opening extra buffers for IIO device")
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210322084135.17536-1-aardelean@deviqon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
sysfs_emit() is preferred over raw s*printf() for sysfs attributes since it
knows about the sysfs buffer specifics and has some built-in sanity checks.
This patch converts the places in the iio core that follow the pattern of
return s*printf(...)
to
return sysfs_emit(...)
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Link: https://lore.kernel.org/r/20210320071405.9347-2-lars@metafoo.de
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Thanks to Lars for finding this.
The free of the 'attached_buffers' array should be done as late as
possible. This change moves it to iio_buffers_put(), which looks like
the best place for it, since it takes place right before the IIO device
data is free'd.
The free of this array will be handled by calling iio_device_free().
The iio_buffers_put() function is renamed to iio_device_detach_buffers()
since the role of this function changes a bit.
It looks like this issue was ocurring on the error path of
iio_buffers_alloc_sysfs_and_mask() and in
iio_buffers_free_sysfs_and_mask()
Added a comment in the doc-header of iio_device_attach_buffer() to
mention how this will be free'd in case anyone is reading the code
and becoming confused about it.
Fixes: ee708e6baa ("iio: buffer: introduce support for attaching more IIO buffers")
Reported-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <ardeleanalex@gmail.com>
Link: https://lore.kernel.org/r/20210307185444.32924-1-ardeleanalex@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
With this change, an ioctl() call is added to open a character device for a
buffer. The ioctl() number is 'i' 0x91, which follows the
IIO_GET_EVENT_FD_IOCTL ioctl.
The ioctl() will return an FD for the requested buffer index. The indexes
are the same from the /sys/iio/devices/iio:deviceX/bufferY (i.e. the Y
variable).
Since there doesn't seem to be a sane way to return the FD for buffer0 to
be the same FD for the /dev/iio:deviceX, this ioctl() will return another
FD for buffer0 (or the first buffer). This duplicate FD will be able to
access the same buffer object (for buffer0) as accessing directly the
/dev/iio:deviceX chardev.
Also, there is no IIO_BUFFER_GET_BUFFER_COUNT ioctl() implemented, as the
index for each buffer (and the count) can be deduced from the
'/sys/bus/iio/devices/iio:deviceX/bufferY' folders (i.e the number of
bufferY folders).
Used following C code to test this:
-------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h"
#include <errno.h>
#define IIO_BUFFER_GET_FD_IOCTL _IOWR('i', 0x91, int)
int main(int argc, char *argv[])
{
int fd;
int fd1;
int ret;
if ((fd = open("/dev/iio:device0", O_RDWR))<0) {
fprintf(stderr, "Error open() %d errno %d\n",fd, errno);
return -1;
}
fprintf(stderr, "Using FD %d\n", fd);
fd1 = atoi(argv[1]);
ret = ioctl(fd, IIO_BUFFER_GET_FD_IOCTL, &fd1);
if (ret < 0) {
fprintf(stderr, "Error for buffer %d ioctl() %d errno %d\n", fd1, ret, errno);
close(fd);
return -1;
}
fprintf(stderr, "Got FD %d\n", fd1);
close(fd1);
close(fd);
return 0;
}
-------------------------------------------------------------------
Results are:
-------------------------------------------------------------------
# ./test 0
Using FD 3
Got FD 4
# ./test 1
Using FD 3
Got FD 4
# ./test 2
Using FD 3
Got FD 4
# ./test 3
Using FD 3
Got FD 4
# ls /sys/bus/iio/devices/iio\:device0
buffer buffer0 buffer1 buffer2 buffer3 dev
in_voltage_sampling_frequency in_voltage_scale
in_voltage_scale_available
name of_node power scan_elements subsystem uevent
-------------------------------------------------------------------
iio:device0 has some fake kfifo buffers attached to an IIO device.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20210215104043.91251-21-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
With this change, calling iio_device_attach_buffer() will actually attach
more buffers.
Right now this doesn't do any validation of whether a buffer is attached
twice; maybe that can be added later (if needed). Attaching a buffer more
than once should yield noticeably bad results.
The first buffer is the legacy buffer, so a reference is kept to it.
At this point, accessing the data for the extra buffers (that are added
after the first one) isn't possible yet.
The iio_device_attach_buffer() is also changed to return an error code,
which for now is -ENOMEM if the array could not be realloc-ed for more
buffers.
To adapt to this new change iio_device_attach_buffer() is called last in
all place where it's called. The realloc failure is a bit difficult to
handle during un-managed calls when unwinding, so it's better to have this
as the last error in the setup_buffer calls.
At this point, no driver should call iio_device_attach_buffer() directly,
it should call one of the {devm_}iio_triggered_buffer_setup() or
devm_iio_kfifo_buffer_setup() or devm_iio_dmaengine_buffer_setup()
functions. This makes iio_device_attach_buffer() a bit easier to handle.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20210215104043.91251-20-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
The __iio_buffer_free_sysfs_and_mask() function will be used in
iio_buffer_alloc_sysfs_and_mask() when multiple buffers will be attached to
the IIO device.
This will need to be used to cleanup resources on each buffer, when the
buffers cleanup unwind will occur on the error path.
The move is done in this patch to make the patch that adds multiple buffers
per IIO device a bit cleaner.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20210215104043.91251-18-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
In order to keep backwards compatibility with the current chardev
mechanism, and in order to add support for multiple buffers per IIO device,
we need to pass both the IIO device & IIO buffer to the chardev.
This is particularly needed for the iio_buffer_read_outer() function, where
we need to pass another buffer object than 'indio_dev->buffer'.
Since we'll also open some chardevs via anon inodes, we can pass extra
buffers in that function by assigning another object to the
iio_dev_buffer_pair object.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20210215104043.91251-17-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>