Skip to contentSkip to conversation

Support ADIS16475 and similar IMUs

PATCH In review Nuno Sá 6 participants 24 messages Apr 13, 2020 – May 18, 2020

Subsystems (5)
lore
Share & tools
lore

Nuno Sá

author maintainer
#0 lore raw

v5 cover Support ADIS16475 and similar IMUs

This series adds support for the adis16475 and similar IMUs. This driver will be the first user of some changes on the adis library. Hence, the first three patches are related to the library:
* Add anaged device functions for registering triggers with the library;
* Updates the way irq_mask is passed to request_irq();
* It adds an update_bits() like API.

A new patch was introduced (iio: adis: Add burst_max_len variable) in order to make burst32 configuration at runtime.

Nuno Sá (6):
iio: imu: adis: Add Managed device functions
iio: imu: adis: Add irq mask variable
iio: adis: Add adis_update_bits() APIs
iio: adis: Support different burst sizes
iio: imu: Add support for adis16475
dt-bindings: iio: Add adis16475 documentation

 .../bindings/iio/imu/adi,adis16475.yaml       |  137 ++
 MAINTAINERS                                   |    8 +
 drivers/iio/imu/Kconfig                       |   13 +
 drivers/iio/imu/Makefile                      |    1 +
 drivers/iio/imu/adis.c                        |   25 +
 drivers/iio/imu/adis16400.c                   |    2 +-
 drivers/iio/imu/adis16475.c                   | 1336 +++++++++++++++++
 drivers/iio/imu/adis_buffer.c                 |   58 +-
 drivers/iio/imu/adis_trigger.c                |   72 +-
 include/linux/iio/imu/adis.h                  |   87 +-
 10 files changed, 1728 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
 create mode 100644 drivers/iio/imu/adis16475.c
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH v5 1/6 iio: imu: adis: Add Managed device functions

This patch adds support for a managed device version of adis_setup_buffer_and_trigger. It works exactly as the original one but it calls all the devm_iio_* functions to setup an iio buffer and trigger. Hence we do not need to care about cleaning those and we do not need to support a remove() callback for every driver using the adis library.

---
Changes in v2:
* Added blank lines for readability.

Changes in V3:
* Removed unnecessary inline;
* Free buffer resources.

Changes in v4:
* Make use of irq_handler_t.

Changes in v5:
* Nothing changed.

 drivers/iio/imu/adis_buffer.c  | 45 ++++++++++++++++++++++++++++++++++
 drivers/iio/imu/adis_trigger.c | 41 ++++++++++++++++++++++++++++---
 include/linux/iio/imu/adis.h   | 17 +++++++++++++
 3 files changed, 100 insertions(+), 3 deletions(-)
drivers/iio/imu/adis_buffer.c +45 -0
index 04e5e2a0fd6b..8fdc4dca10c0 100644
@@ -156,6 +156,14 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
+static void adis_buffer_cleanup(void *arg)
+{
+	struct adis *adis = arg;
+
+	kfree(adis->buffer);
+	kfree(adis->xfer);
+}
+
 /**
  * adis_setup_buffer_and_trigger() - Sets up buffer and trigger for the adis device
  * @adis: The adis device.
@@ -198,6 +206,43 @@ int adis_setup_buffer_and_trigger(struct adis *adis, struct iio_dev *indio_dev,
 }
 EXPORT_SYMBOL_GPL(adis_setup_buffer_and_trigger);
 
+/**
+ * devm_adis_setup_buffer_and_trigger() - Sets up buffer and trigger for
+ *					  the managed adis device
+ * @adis: The adis device
+ * @indio_dev: The IIO device
+ * @trigger_handler: Optional trigger handler, may be NULL.
+ *
+ * Returns 0 on success, a negative error code otherwise.
+ *
+ * This function perfoms exactly the same as adis_setup_buffer_and_trigger()
+ */
+int
+devm_adis_setup_buffer_and_trigger(struct adis *adis, struct iio_dev *indio_dev,
+				   irq_handler_t trigger_handler)
+{
+	int ret;
+
+	if (!trigger_handler)
+		trigger_handler = adis_trigger_handler;
+
+	ret = devm_iio_triggered_buffer_setup(&adis->spi->dev, indio_dev,
+					      &iio_pollfunc_store_time,
+					      trigger_handler, NULL);
+	if (ret)
+		return ret;
+
+	if (adis->spi->irq) {
+		ret = devm_adis_probe_trigger(adis, indio_dev);
+		if (ret)
+			return ret;
+	}
+
+	return devm_add_action_or_reset(&adis->spi->dev, adis_buffer_cleanup,
+					adis);
+}
+EXPORT_SYMBOL_GPL(devm_adis_setup_buffer_and_trigger);
+
 /**
  * adis_cleanup_buffer_and_trigger() - Free buffer and trigger resources
  * @adis: The adis device.
drivers/iio/imu/adis_trigger.c +38 -3

59 lines not on this page · raw message

include/linux/iio/imu/adis.h +17 -0
index dd8219138c2e..e70814d96e1c 100644
@@ -448,11 +448,15 @@ struct adis_burst {
 	unsigned int	extra_len;
 };
 
+int
+devm_adis_setup_buffer_and_trigger(struct adis *adis, struct iio_dev *indio_dev,
+				   irq_handler_t trigger_handler);
 int adis_setup_buffer_and_trigger(struct adis *adis,
 	struct iio_dev *indio_dev, irqreturn_t (*trigger_handler)(int, void *));
 void adis_cleanup_buffer_and_trigger(struct adis *adis,
 	struct iio_dev *indio_dev);
 
+int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev);
 int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev);
 void adis_remove_trigger(struct adis *adis);
 
@@ -461,6 +465,13 @@ int adis_update_scan_mode(struct iio_dev *indio_dev,
 
 #else /* CONFIG_IIO_BUFFER */
 
+static inline int
+devm_adis_setup_buffer_and_trigger(struct adis *adis, struct iio_dev *indio_dev,
+				   irq_handler_t trigger_handler)
+{
+	return 0;
+}
+
 static inline int adis_setup_buffer_and_trigger(struct adis *adis,
 	struct iio_dev *indio_dev, irqreturn_t (*trigger_handler)(int, void *))
 {
@@ -472,6 +483,12 @@ static inline void adis_cleanup_buffer_and_trigger(struct adis *adis,
 {
 }
 
+static inline int devm_adis_probe_trigger(struct adis *adis,
+					  struct iio_dev *indio_dev)
+{
+	return 0;
+}
+
 static inline int adis_probe_trigger(struct adis *adis,
 	struct iio_dev *indio_dev)
 {
Signature · 1 line
2.17.1
author maintainer
#2 lore raw

PATCH v5 2/6 iio: imu: adis: Add irq flag variable

In reply to Nuno Sá

There are some ADIS devices that can configure the data ready pin polarity. Hence, we cannot hardcode our IRQ mask as IRQF_TRIGGER_RISING since we might want to have it as IRQF_TRIGGER_FALLING.

---
Changes in v2:
* Add kernel doc-string for irq-mask.

Changes in v3:
* Removed unnecessary inline;
* Renamed __adis_validate_irq_mask to adis_validate_irq_mask to keep lib consistency;
* Cosmetics in logs.

Changes in v4:
* Use flag suffix instead of mask;
* Add comments to adis_validate_irq_flag.

Changes in v5:
* Change commit subject to irq flag instead of mask.

 drivers/iio/imu/adis_trigger.c | 33 +++++++++++++++++++++++++++++++--
 include/linux/iio/imu/adis.h   |  2 ++
 2 files changed, 33 insertions(+), 2 deletions(-)
drivers/iio/imu/adis_trigger.c +31 -2
index a36810e0b1ab..8afe71947c00 100644
@@ -34,6 +34,27 @@ static void adis_trigger_setup(struct adis *adis)
 	iio_trigger_set_drvdata(adis->trig, adis);
 }
 
+static int adis_validate_irq_flag(struct adis *adis)
+{
+	/*
+	 * Typically this devices have data ready either on the rising edge or
+	 * on the falling edge of the data ready pin. This checks enforces that
+	 * one of those is set in the drivers... It defaults to
+	 * IRQF_TRIGGER_RISING for backward compatibility wiht devices that
+	 * don't support changing the pin polarity.
+	 */
+	if (!adis->irq_flag) {
+		adis->irq_flag = IRQF_TRIGGER_RISING;
+		return 0;
+	} else if (adis->irq_flag != IRQF_TRIGGER_RISING &&
+		   adis->irq_flag != IRQF_TRIGGER_FALLING) {
+		dev_err(&adis->spi->dev, "Invalid IRQ mask: %08lx\n",
+			adis->irq_flag);
+		return -EINVAL;
+	}
+
+	return 0;
+}
 /**
  * adis_probe_trigger() - Sets up trigger for a adis device
  * @adis: The adis device
@@ -54,9 +75,13 @@ int adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
 
 	adis_trigger_setup(adis);
 
+	ret = adis_validate_irq_flag(adis);
+	if (ret)
+		return ret;
+
 	ret = request_irq(adis->spi->irq,
 			  &iio_trigger_generic_data_rdy_poll,
-			  IRQF_TRIGGER_RISING,
+			  adis->irq_flag,
 			  indio_dev->name,
 			  adis->trig);
 	if (ret)
@@ -96,9 +121,13 @@ int devm_adis_probe_trigger(struct adis *adis, struct iio_dev *indio_dev)
 
 	adis_trigger_setup(adis);
 
+	ret = adis_validate_irq_flag(adis);
+	if (ret)
+		return ret;
+
 	ret = devm_request_irq(&adis->spi->dev, adis->spi->irq,
 			       &iio_trigger_generic_data_rdy_poll,
-			       IRQF_TRIGGER_RISING,
+			       adis->irq_flag,
 			       indio_dev->name,
 			       adis->trig);
 	if (ret)
include/linux/iio/imu/adis.h +2 -0
index e70814d96e1c..70e4d1d262f5 100644
@@ -87,6 +87,7 @@ struct adis_data {
  * @msg: SPI message object
  * @xfer: SPI transfer objects to be used for a @msg
  * @current_page: Some ADIS devices have registers, this selects current page
+ * @irq_flag: IRQ handling flags as passed to request_irq()
  * @buffer: Data buffer for information read from the device
  * @tx: DMA safe TX buffer for SPI transfers
  * @rx: DMA safe RX buffer for SPI transfers
@@ -113,6 +114,7 @@ struct adis {
 	struct spi_message	msg;
 	struct spi_transfer	*xfer;
 	unsigned int		current_page;
+	unsigned long		irq_flag;
 	void			*buffer;
 
 	uint8_t			tx[10] ____cacheline_aligned;
Signature · 1 line
2.17.1
author maintainer
#3 lore raw

PATCH v5 3/6 iio: adis: Add adis_update_bits() APIs

In reply to Nuno Sá

This patch adds a regmap_update_bits() like API to the ADIS library. It provides locked and unlocked variant.

---
Changes in v2:
* Add BUILD_BUG_ON() to avoid invalid types.

Changes in V3:
* Nothing changed.

Changes in v4:
* Use one liner for updating the bits.

Changes in v5:
* Nothing changed.

 drivers/iio/imu/adis.c       | 25 +++++++++++++++
 include/linux/iio/imu/adis.h | 59 ++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
drivers/iio/imu/adis.c +25 -0
index 2e7d0d337f8f..c539dfa3b8d3 100644
@@ -223,6 +223,31 @@ int __adis_read_reg(struct adis *adis, unsigned int reg,
 	return ret;
 }
 EXPORT_SYMBOL_GPL(__adis_read_reg);
+/**
+ * __adis_update_bits_base() - ADIS Update bits function - Unlocked version
+ * @adis: The adis device
+ * @reg: The address of the lower of the two registers
+ * @mask: Bitmask to change
+ * @val: Value to be written
+ * @size: Size of the register to update
+ *
+ * Updates the desired bits of @reg in accordance with @mask and @val.
+ */
+int __adis_update_bits_base(struct adis *adis, unsigned int reg, const u32 mask,
+			    const u32 val, u8 size)
+{
+	int ret;
+	u32 __val;
+
+	ret = __adis_read_reg(adis, reg, &__val, size);
+	if (ret)
+		return ret;
+
+	__val = (__val & ~mask) | (val & mask);
+
+	return __adis_write_reg(adis, reg, __val, size);
+}
+EXPORT_SYMBOL_GPL(__adis_update_bits_base);
 
 #ifdef CONFIG_DEBUG_FS
 
include/linux/iio/imu/adis.h +59 -0

65 lines not on this page · raw message

Signature · 1 line
2.17.1
author maintainer
#4 lore raw

PATCH v5 4/6 iio: adis: Support different burst sizes

In reply to Nuno Sá

Add burst_max_len to adis_burst. This is useful for devices which support different burst modes with different sizes. The buffer to be used in the spi transfer is allocated with this variable making sure that has space for all burst modes. The spi transfer length should hold the "real" burst length depending on the current burst mode configured in the device.

Moreover, extra_len in adis_burst is made const and it should contain the smallest extra length necessary for a burst transfer. In struct adis was added a new burst_extra_len that should hold the extra bytes needed depending on the device instance being used.

---
Changes in v2:
* Nothing changed.

Changes in v3:
* Reworked commit message;
* Made extra_len const;
* Added burst_extra_len to struct adis;
* Changed adis16400 accordingly.

Changes in v4:
* Nothing changed.

Changes in v5:
* Nothing changed.

 drivers/iio/imu/adis16400.c   |  2 +-
 drivers/iio/imu/adis_buffer.c | 13 +++++++++----
 include/linux/iio/imu/adis.h  |  9 +++++++--
 3 files changed, 17 insertions(+), 7 deletions(-)
drivers/iio/imu/adis16400.c +1 -1
index 4445c242709c..439feb755d82 100644
@@ -1195,7 +1195,7 @@ static int adis16400_probe(struct spi_device *spi)
 		indio_dev->available_scan_masks = st->avail_scan_mask;
 		st->adis.burst = &adis16400_burst;
 		if (st->variant->flags & ADIS16400_BURST_DIAG_STAT)
-			st->adis.burst->extra_len = sizeof(u16);
+			st->adis.burst_extra_len = sizeof(u16);
 	}
 
 	adis16400_data = &st->variant->adis_data;
drivers/iio/imu/adis_buffer.c +9 -4
index 8fdc4dca10c0..5b4225ee09b9 100644
@@ -23,25 +23,30 @@ static int adis_update_scan_mode_burst(struct iio_dev *indio_dev,
 	const unsigned long *scan_mask)
 {
 	struct adis *adis = iio_device_get_drvdata(indio_dev);
-	unsigned int burst_length;
+	unsigned int burst_length, burst_max_length;
 	u8 *tx;
 
 	/* All but the timestamp channel */
 	burst_length = (indio_dev->num_channels - 1) * sizeof(u16);
-	burst_length += adis->burst->extra_len;
+	burst_length += adis->burst->extra_len + adis->burst_extra_len;
+
+	if (adis->burst->burst_max_len)
+		burst_max_length = adis->burst->burst_max_len;
+	else
+		burst_max_length = burst_length;
 
 	adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);
 	if (!adis->xfer)
 		return -ENOMEM;
 
-	adis->buffer = kzalloc(burst_length + sizeof(u16), GFP_KERNEL);
+	adis->buffer = kzalloc(burst_max_length + sizeof(u16), GFP_KERNEL);
 	if (!adis->buffer) {
 		kfree(adis->xfer);
 		adis->xfer = NULL;
 		return -ENOMEM;
 	}
 
-	tx = adis->buffer + burst_length;
+	tx = adis->buffer + burst_max_length;
 	tx[0] = ADIS_READ_REG(adis->burst->reg_cmd);
 	tx[1] = 0;
 
include/linux/iio/imu/adis.h +7 -2
index 247fc4c7185c..2df67448f0d1 100644
@@ -83,6 +83,8 @@ struct adis_data {
  * @trig: IIO trigger object data
  * @data: ADIS chip variant specific data
  * @burst: ADIS burst transfer information
+ * @burst_extra_len: Burst extra length. Should only be used by devices that can
+ *		     dynamically change their burst mode length.
  * @state_lock: Lock used by the device to protect state
  * @msg: SPI message object
  * @xfer: SPI transfer objects to be used for a @msg
@@ -98,7 +100,7 @@ struct adis {
 
 	const struct adis_data	*data;
 	struct adis_burst	*burst;
-
+	unsigned int		burst_extra_len;
 	/**
 	 * The state_lock is meant to be used during operations that require
 	 * a sequence of SPI R/W in order to protect the SPI transfer
@@ -502,11 +504,14 @@ int adis_single_conversion(struct iio_dev *indio_dev,
  * @en			burst mode enabled
  * @reg_cmd		register command that triggers burst
  * @extra_len		extra length to account in the SPI RX buffer
+ * @burst_max_len	holds the maximum burst size when the device supports
+ *			more than one burst mode with different sizes
  */
 struct adis_burst {
 	bool		en;
 	unsigned int	reg_cmd;
-	unsigned int	extra_len;
+	const u32	extra_len;
+	const u32	burst_max_len;
 };
 
 int
Signature · 1 line
2.17.1
author maintainer
#5 lore raw

PATCH v5 5/6 iio: imu: Add support for adis16475

In reply to Nuno Sá

Support ADIS16475 and similar IMU devices. These devices are a precision, miniature MEMS inertial measurement unit (IMU) that includes a triaxial gyroscope and a triaxial accelerometer. Each inertial sensor combines with signal conditioning that optimizes dynamic performance.

The driver adds support for the following devices:
* adis16470, adis16475, adis16477, adis16465, adis16467, adis16500, adis16505, adis16507.

---
Changes in v2:
* Remove burst mode config (enabled by default);
* Fix timestamp channel index;
* Do return code checks inline in adis16475_read_raw;
* Increase buffer size to fit aligned timestamp;
* Remove spi_device_id table;
* Rename adis16475_clks to adis16475_sync;
* Rename adis16475_config_ext_clk adis16475_config_sync_mode;
* Fix output-sync mode. There's no need to call clk_get in this mode as
it acts as an output pin;
* Fix scaled-mode configuration. Up scale was not being written on the right register;
* Handle burst32 configuration at runtime. When the decimation or the FIR filter is enabled
the LSB bits are meangninfull. Hence, use burst32 in that case (if the part supports it);
* When there's no burst32 mode and the LSB data is meangninfull, read it manually...
* Do not push data to buffers if crc is invalid.

Changes in V3:
* Fix multiple instance devices for different burst sizes;
* Only return error if freq is 0 on `adis16475_set_freq``;
* Fixed typo in comment;
* Do not allow 7 to be set in adis16475_set_filter;
* Change adis16475_validate_crc return type to bool;
* Return 1 if crc is valid instead of 0.

Changes in v4:
* Remove unused file from MAINTAINERS;
* Remove <asm/unaligned.h>;
* Use irq_flag - Changed in 2 patch;
* Use DEFINE_DEBUGFS_ATTRIBUTE + debugfs_create_file_unsafe;
* No need to return in adis16475_debugfs_init;
* Drop parentheses in (crc == 0);
* Remove unnecessary casts;
* Directly pass data to iio_push_to_buffers_with_timestamp;
* Remove all get_unaligned calls;
* Better indent macros with inside macros;
* Use assign_bit();
* Drop ret < 0 checks;
* Use device_get_match_data();
* Replace linux/of_device.h by <linux/mod_devicetable.h>and <linux/property.h>;
* Remove invalid index in adis16475_3db_freqs;
* Make the loop in adis16475_set_filter more readable.

Changes in v5:
* Added braces in while expression;
* Removed extra blank line;
* Add missing blank lines;
* Removed redundant parentheses;
* Use the correct irq type defines after irqd_get_trigger_type;
* Explictly assign irq_flags even when IRQ_TYPE_EDGE_RISING;
* Check return value of device_property_read_u32 when checking adi,scaled-output-hz.

 MAINTAINERS                 |    7 +
 drivers/iio/imu/Kconfig     |   13 +
 drivers/iio/imu/Makefile    |    1 +
 drivers/iio/imu/adis16475.c | 1339 +++++++++++++++++++++++++++++++++++
 4 files changed, 1360 insertions(+)
 create mode 100644 drivers/iio/imu/adis16475.c
MAINTAINERS +7 -0
index 8687cc5397c8..a2ff8322c184 100644
@@ -1009,6 +1009,13 @@ W:	http://ez.analog.com/community/linux-device-drivers
 F:	drivers/iio/imu/adis16460.c
 F:	Documentation/devicetree/bindings/iio/imu/adi,adis16460.yaml
 
+ANALOG DEVICES INC ADIS16475 DRIVER
+M:	Nuno Sa <[email protected]>
+L:	[email protected]
+W:	http://ez.analog.com/community/linux-device-drivers
+S:	Supported
+F:	drivers/iio/imu/adis16475.c
+
 ANALOG DEVICES INC ADM1177 DRIVER
 M:	Beniamin Bia <[email protected]>
 M:	Michael Hennerich <[email protected]>
drivers/iio/imu/Kconfig +13 -0
index 60bb1029e759..fc4123d518bc 100644
@@ -29,6 +29,19 @@ config ADIS16460
 	  To compile this driver as a module, choose M here: the module will be
 	  called adis16460.
 
+config ADIS16475
+	tristate "Analog Devices ADIS16475 and similar IMU driver"
+	depends on SPI
+	select IIO_ADIS_LIB
+	select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
+	help
+	  Say yes here to build support for Analog Devices ADIS16470, ADIS16475,
+	  ADIS16477, ADIS16465, ADIS16467, ADIS16500, ADIS16505, ADIS16507 inertial
+	  sensors.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called adis16475.
+
 config ADIS16480
 	tristate "Analog Devices ADIS16480 and similar IMU driver"
 	depends on SPI
drivers/iio/imu/Makefile +1 -0
index 5237fd4bc384..88b2c4555230 100644
@@ -6,6 +6,7 @@
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_ADIS16400) += adis16400.o
 obj-$(CONFIG_ADIS16460) += adis16460.o
+obj-$(CONFIG_ADIS16475) += adis16475.o
 obj-$(CONFIG_ADIS16480) += adis16480.o
 
 adis_lib-y += adis.o
drivers/iio/imu/adis16475.c new file +1339 -0

1,339 lines not on this page · raw message

Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

drivers/iio/imu/adis16475.c line 1061

Quoted 8 lines · Nuno Sá

[...]

drivers/iio/imu/adis16475.c new file +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);

If the timestamp is enabled the IIO core might insert padding between the data channels and the timestamp. If that happens this will disclose kernel stack memory to userspace.

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data into the state struct and kzalloc it.

- Lars

maintainer
#7 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 14 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:

drivers/iio/imu/adis16475.c line 1061

Quoted 8 lines · Nuno Sá

[...]

drivers/iio/imu/adis16475.c new file +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);  

If the timestamp is enabled the IIO core might insert padding between the data channels and the timestamp. If that happens this will disclose kernel stack memory to userspace.

Quoted 2 lines

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data into the state struct and kzalloc it.

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

Thanks,

Jonathan

Quoted 3 lines

- Lars

#8 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 16 lines · Jonathan Cameron
Quoted 13 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:

drivers/iio/imu/adis16475.c line 1061

Quoted 8 lines · Nuno Sá

[...]

drivers/iio/imu/adis16475.c new file +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf->timestamp);

If the timestamp is enabled the IIO core might insert padding between the data channels and the timestamp. If that happens this will disclose kernel stack memory to userspace.

Quoted 6 lines
Quoted 2 lines

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data into the state struct and kzalloc it.

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily aligned to 64 bit, which causes issues if we try to put the 64-bit timestamp in it. I think data should really be in the state struct.

#9 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 23 lines · Lars-Peter Clausen
Quoted 22 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 9 lines · Nuno Sá

[...]

drivers/iio/imu/adis16475.c new file +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf-
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding between
the data channels and the timestamp. If that happens this will disclose
kernel stack memory to userspace.

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data
into the state struct and kzalloc it.

Quoted 7 lines
Quoted 5 lines

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit
memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily aligned to 64 bit, which causes issues if we try to put the 64-bit

Oh, this is actually more problematic. Yes, since we have an array of u16, that is not guaranteed to be 64bit aligned. Doing a quick search of iio_push_to_buffers_with_timestamp() users and I could quickly find 4/5 drivers with the same problem. I guess the API should clearly state that data needs to be __at least__ 64 bits aligned (maybe a future patch). Or we could even check the address and guarantee that it is properly aligned before continuing (though Im guessing this will break a lot of users...)

Quoted 1 line

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use __aligned(8) on the stack variable?

- Nuno Sá

maintainer
#10 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 40 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 23 lines · Lars-Peter Clausen
Quoted 22 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 9 lines · Nuno Sá

[...]

drivers/iio/imu/adis16475.c new file +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf-  
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding between
the data channels and the timestamp. If that happens this will disclose
kernel stack memory to userspace.

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data
into the state struct and kzalloc it.

Quoted 7 lines
Quoted 5 lines

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit
memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily aligned to 64 bit, which causes issues if we try to put the 64-bit

Oh, this is actually more problematic. Yes, since we have an array of u16, that is not guaranteed to be 64bit aligned. Doing a quick search of iio_push_to_buffers_with_timestamp() users and I could quickly find 4/5 drivers with the same problem. I guess the API should clearly state that data needs to be __at least__ 64 bits aligned (maybe a future patch). Or we could even check the address and guarantee that it is properly aligned before continuing (though Im guessing this will break a lot of users...)

Quoted 4 lines
Quoted 1 line

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use __aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

The moment Lars mentioned this I groaned. As you've noted a few other drivers have the same problem + the ABI doesn't clearly state or check this.

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

Jonathan

Quoted 4 lines

- Nuno Sá

#11 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 52 lines · Jonathan Cameron
Quoted 39 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 23 lines · Lars-Peter Clausen
Quoted 22 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 9 lines · Nuno Sá

[...]

drivers/iio/imu/adis16475.c new file +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf-
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding between
the data channels and the timestamp. If that happens this will disclose
kernel stack memory to userspace.

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data
into the state struct and kzalloc it.

Quoted 7 lines
Quoted 5 lines

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit
memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily aligned to 64 bit, which causes issues if we try to put the 64-bit

Oh, this is actually more problematic. Yes, since we have an array of u16, that is not guaranteed to be 64bit aligned. Doing a quick search of iio_push_to_buffers_with_timestamp() users and I could quickly find 4/5 drivers with the same problem. I guess the API should clearly state that data needs to be __at least__ 64 bits aligned (maybe a future patch). Or we could even check the address and guarantee that it is properly aligned before continuing (though Im guessing this will break a lot of users...)

Quoted 3 lines
Quoted 1 line

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use __aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

Quoted 6 lines

The moment Lars mentioned this I groaned. As you've noted a few other drivers have the same problem + the ABI doesn't clearly state or check this.

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should switch to put_unaligned(). We probably got lucky in most cases and the buffer is naturally aligned to 64 bit.

But the reason I noticed this is because I ran into the issue in the wild where the timestamp ended up at the wrong offset in the buffer, so it does happen.

The following semantic patch finds affected drivers.

@@
type T;
identifier buf;
expression N;
expression ts;
expression indio_dev;
@@
*T buf[N];
...
*iio_push_to_buffers_with_timestamp(indio_dev, buf, ts)

Matched files:

--- drivers/iio/health/afe4403.c
--- drivers/iio/health/afe4404.c
--- drivers/iio/gyro/mpu3050-core.c
--- drivers/iio/gyro/itg3200_buffer.c
--- drivers/iio/chemical/ccs811.c
--- drivers/iio/chemical/sps30.c
--- drivers/iio/chemical/pms7003.c
--- drivers/iio/proximity/isl29501.c
--- drivers/iio/proximity/mb1232.c
--- drivers/iio/accel/kxsd9.c
--- drivers/iio/accel/mma8452.c
--- drivers/iio/accel/bmc150-accel-core.c --- drivers/iio/accel/mma7455_core.c
--- drivers/iio/adc/ti-adc081c.c
--- drivers/iio/adc/ti-adc084s021.c
--- drivers/iio/adc/ti-ads1015.c
--- drivers/iio/adc/ti-ads124s08.c
--- drivers/iio/adc/ina2xx-adc.c
--- drivers/iio/adc/ti-ads8688.c
--- drivers/iio/adc/ti-adc0832.c
--- drivers/iio/adc/ti-adc12138.c
--- drivers/iio/adc/max1118.c
--- drivers/iio/adc/ad_sigma_delta.c
--- drivers/iio/light/si1145.c
--- drivers/iio/light/vcnl4035.c
--- drivers/iio/light/max44000.c
--- drivers/iio/light/rpr0521.c
--- drivers/iio/light/st_uvis25_core.c
--- drivers/iio/light/ltr501.c
--- drivers/iio/magnetometer/ak8974.c
--- drivers/iio/magnetometer/mag3110.c
--- drivers/iio/magnetometer/ak8975.c
--- drivers/iio/humidity/hdc100x.c
--- drivers/iio/humidity/hts221_buffer.c --- drivers/iio/imu/bmi160/bmi160_core.c --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c --- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c --- drivers/iio/pressure/ms5611_core.c
--- drivers/iio/pressure/mpl3115.c

#12 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 109 lines · Lars-Peter Clausen
Quoted 51 lines · Jonathan Cameron
Quoted 38 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 22 lines · Lars-Peter Clausen
Quoted 21 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 9 lines · Nuno Sá

[...]

(quoted diff) +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+    __be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+    iio_push_to_buffers_with_timestamp(indio_dev, data, pf-
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding between
the data channels and the timestamp. If that happens this will disclose
kernel stack memory to userspace.

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data
into the state struct and kzalloc it.

Quoted 7 lines
Quoted 5 lines

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit
memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily aligned to 64 bit, which causes issues if we try to put the 64-bit

Oh, this is actually more problematic. Yes, since we have an array of u16, that is not guaranteed to be 64bit aligned. Doing a quick search of iio_push_to_buffers_with_timestamp() users and I could quickly find 4/5 drivers with the same problem. I guess the API should clearly state that data needs to be __at least__ 64 bits aligned (maybe a future patch). Or we could even check the address and guarantee that it is properly aligned before continuing (though Im guessing this will break a lot of users...)

Quoted 3 lines
Quoted 1 line

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use __aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

Quoted 6 lines

The moment Lars mentioned this I groaned. As you've noted a few other drivers have the same problem + the ABI doesn't clearly state or check this.

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should switch to put_unaligned(). We probably got lucky in most cases and the buffer is naturally aligned to 64 bit.

But the reason I noticed this is because I ran into the issue in the wild where the timestamp ended up at the wrong offset in the buffer, so it does happen.

The following semantic patch finds affected drivers.

@@
type T;
identifier buf;
expression N;
expression ts;
expression indio_dev;
@@
*T buf[N];
...
*iio_push_to_buffers_with_timestamp(indio_dev, buf, ts)

Matched files:

--- drivers/iio/health/afe4403.c
--- drivers/iio/health/afe4404.c
--- drivers/iio/gyro/mpu3050-core.c
--- drivers/iio/gyro/itg3200_buffer.c
--- drivers/iio/chemical/ccs811.c
--- drivers/iio/chemical/sps30.c
--- drivers/iio/chemical/pms7003.c
--- drivers/iio/proximity/isl29501.c
--- drivers/iio/proximity/mb1232.c
--- drivers/iio/accel/kxsd9.c
--- drivers/iio/accel/mma8452.c
--- drivers/iio/accel/bmc150-accel-core.c
--- drivers/iio/accel/mma7455_core.c
--- drivers/iio/adc/ti-adc081c.c
--- drivers/iio/adc/ti-adc084s021.c
--- drivers/iio/adc/ti-ads1015.c
--- drivers/iio/adc/ti-ads124s08.c
--- drivers/iio/adc/ina2xx-adc.c
--- drivers/iio/adc/ti-ads8688.c
--- drivers/iio/adc/ti-adc0832.c
--- drivers/iio/adc/ti-adc12138.c
--- drivers/iio/adc/max1118.c
--- drivers/iio/adc/ad_sigma_delta.c
--- drivers/iio/light/si1145.c
--- drivers/iio/light/vcnl4035.c
--- drivers/iio/light/max44000.c
--- drivers/iio/light/rpr0521.c
--- drivers/iio/light/st_uvis25_core.c
--- drivers/iio/light/ltr501.c
--- drivers/iio/magnetometer/ak8974.c
--- drivers/iio/magnetometer/mag3110.c

Quoted 9 lines

--- drivers/iio/magnetometer/ak8975.c
--- drivers/iio/humidity/hdc100x.c
--- drivers/iio/humidity/hts221_buffer.c --- drivers/iio/imu/bmi160/bmi160_core.c --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c --- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c --- drivers/iio/pressure/ms5611_core.c
--- drivers/iio/pressure/mpl3115.c

Most of these drivers also seem to have the issue that they leak stack memory. Only 11 of them clear the buffer.

maintainer
#13 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 57 lines · On Sun, 3 May 2020 11:12:34 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 56 lines · Lars-Peter Clausen
Quoted 55 lines · Jonathan Cameron
Quoted 38 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 22 lines · Lars-Peter Clausen
Quoted 21 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 9 lines · Nuno Sá

[...]

(quoted diff) +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+    __be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+    iio_push_to_buffers_with_timestamp(indio_dev, data, pf-  
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding between
the data channels and the timestamp. If that happens this will disclose
kernel stack memory to userspace.

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data
into the state struct and kzalloc it.

Quoted 7 lines
Quoted 5 lines

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit
memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily aligned to 64 bit, which causes issues if we try to put the 64-bit

Oh, this is actually more problematic. Yes, since we have an array of u16, that is not guaranteed to be 64bit aligned. Doing a quick search of iio_push_to_buffers_with_timestamp() users and I could quickly find 4/5 drivers with the same problem. I guess the API should clearly state that data needs to be __at least__ 64 bits aligned (maybe a future patch). Or we could even check the address and guarantee that it is properly aligned before continuing (though Im guessing this will break a lot of users...)

Quoted 3 lines
Quoted 1 line

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use __aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

The moment Lars mentioned this I groaned. As you've noted a few other drivers have the same problem + the ABI doesn't clearly state or check this.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should switch to put_unaligned(). We probably got lucky in most cases and the buffer is naturally aligned to 64 bit.

Just a quick update on this. I've been taking a deeper look and there are some 'interesting' cases in here so the put_unaligned is attractive unfortunately I don't think we can go that way because it would be reasonable for consumers of the buffer to expect it to be appropriately
aligned. We need to rework many of these anyway to fix the related
data leak.

I've done some of below and will post shortly - a few will take more effort and probably need testing rather than just relying on review.

So far the 'interesting ones' are mpu3050 and isl29501.

J

Quoted 63 lines
Quoted 51 lines

But the reason I noticed this is because I ran into the issue in the wild where the timestamp ended up at the wrong offset in the buffer, so it does happen.

The following semantic patch finds affected drivers.

@@
type T;
identifier buf;
expression N;
expression ts;
expression indio_dev;
@@
*T buf[N];
...
*iio_push_to_buffers_with_timestamp(indio_dev, buf, ts)

Matched files:

--- drivers/iio/health/afe4403.c
--- drivers/iio/health/afe4404.c
--- drivers/iio/gyro/mpu3050-core.c
--- drivers/iio/gyro/itg3200_buffer.c
--- drivers/iio/chemical/ccs811.c
--- drivers/iio/chemical/sps30.c
--- drivers/iio/chemical/pms7003.c
--- drivers/iio/proximity/isl29501.c
--- drivers/iio/proximity/mb1232.c
--- drivers/iio/accel/kxsd9.c
--- drivers/iio/accel/mma8452.c
--- drivers/iio/accel/bmc150-accel-core.c
--- drivers/iio/accel/mma7455_core.c
--- drivers/iio/adc/ti-adc081c.c
--- drivers/iio/adc/ti-adc084s021.c
--- drivers/iio/adc/ti-ads1015.c
--- drivers/iio/adc/ti-ads124s08.c
--- drivers/iio/adc/ina2xx-adc.c
--- drivers/iio/adc/ti-ads8688.c
--- drivers/iio/adc/ti-adc0832.c
--- drivers/iio/adc/ti-adc12138.c
--- drivers/iio/adc/max1118.c
--- drivers/iio/adc/ad_sigma_delta.c
--- drivers/iio/light/si1145.c
--- drivers/iio/light/vcnl4035.c
--- drivers/iio/light/max44000.c
--- drivers/iio/light/rpr0521.c
--- drivers/iio/light/st_uvis25_core.c
--- drivers/iio/light/ltr501.c
--- drivers/iio/magnetometer/ak8974.c
--- drivers/iio/magnetometer/mag3110.c

Quoted 9 lines

--- drivers/iio/magnetometer/ak8975.c
--- drivers/iio/humidity/hdc100x.c
--- drivers/iio/humidity/hts221_buffer.c --- drivers/iio/imu/bmi160/bmi160_core.c --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c --- drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c --- drivers/iio/pressure/ms5611_core.c
--- drivers/iio/pressure/mpl3115.c

Most of these drivers also seem to have the issue that they leak stack memory. Only 11 of them clear the buffer.

#14 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 72 lines · Jonathan Cameron
Quoted 57 lines · On Sun, 3 May 2020 11:12:34 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 56 lines · Lars-Peter Clausen
Quoted 55 lines · Jonathan Cameron
Quoted 38 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 22 lines · Lars-Peter Clausen
Quoted 21 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 9 lines · Nuno Sá

[...]

(quoted diff) +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+    __be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+    iio_push_to_buffers_with_timestamp(indio_dev, data, pf-
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding between
the data channels and the timestamp. If that happens this will disclose
kernel stack memory to userspace.

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data
into the state struct and kzalloc it.

Quoted 7 lines
Quoted 5 lines

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit
memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily aligned to 64 bit, which causes issues if we try to put the 64-bit

Oh, this is actually more problematic. Yes, since we have an array of u16, that is not guaranteed to be 64bit aligned. Doing a quick search of iio_push_to_buffers_with_timestamp() users and I could quickly find 4/5 drivers with the same problem. I guess the API should clearly state that data needs to be __at least__ 64 bits aligned (maybe a future patch). Or we could even check the address and guarantee that it is properly aligned before continuing (though Im guessing this will break a lot of users...)

Quoted 3 lines
Quoted 1 line

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use __aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

The moment Lars mentioned this I groaned. As you've noted a few other drivers have the same problem + the ABI doesn't clearly state or check this.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should switch to put_unaligned(). We probably got lucky in most cases and the buffer is naturally aligned to 64 bit.

Just a quick update on this. I've been taking a deeper look and there are some 'interesting' cases in here so the put_unaligned is attractive unfortunately I don't think we can go that way because it would be reasonable for consumers of the buffer to expect it to be appropriately
aligned. We need to rework many of these anyway to fix the related
data leak.

Quoted 4 lines

I've done some of below and will post shortly - a few will take more effort and probably need testing rather than just relying on review.

So far the 'interesting ones' are mpu3050 and isl29501.

isl29501 looks OK to me. mpu3050 is clearly broken, buffer is both unaligned and too small!

#15 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 73 lines · On Sun, 17 May 2020 21:07:45 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 72 lines · Jonathan Cameron
Quoted 57 lines · On Sun, 3 May 2020 11:12:34 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 56 lines · Lars-Peter Clausen
Quoted 55 lines · Jonathan Cameron
Quoted 38 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 22 lines · Lars-Peter Clausen
Quoted 21 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 9 lines · Nuno Sá

[...]

(quoted diff) +5 -0
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)
+{
[...]
+    __be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+    iio_push_to_buffers_with_timestamp(indio_dev, data, pf-  
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding between
the data channels and the timestamp. If that happens this will disclose
kernel stack memory to userspace.

This needs either a memset(data, 0x00, sizeof(data)) or maybe put data
into the state struct and kzalloc it.

Quoted 7 lines
Quoted 5 lines

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than explicit
memset, but some form of zeroization is needed.

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily aligned to 64 bit, which causes issues if we try to put the 64-bit

Oh, this is actually more problematic. Yes, since we have an array of u16, that is not guaranteed to be 64bit aligned. Doing a quick search of iio_push_to_buffers_with_timestamp() users and I could quickly find 4/5 drivers with the same problem. I guess the API should clearly state that data needs to be __at least__ 64 bits aligned (maybe a future patch). Or we could even check the address and guarantee that it is properly aligned before continuing (though Im guessing this will break a lot of users...)

Quoted 3 lines
Quoted 1 line

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use __aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

The moment Lars mentioned this I groaned. As you've noted a few other drivers have the same problem + the ABI doesn't clearly state or check this.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should switch to put_unaligned(). We probably got lucky in most cases and the buffer is naturally aligned to 64 bit.

Just a quick update on this. I've been taking a deeper look and there are some 'interesting' cases in here so the put_unaligned is attractive unfortunately I don't think we can go that way because it would be reasonable for consumers of the buffer to expect it to be appropriately
aligned. We need to rework many of these anyway to fix the related
data leak.

Quoted 7 lines
Quoted 4 lines

I've done some of below and will post shortly - a few will take more effort and probably need testing rather than just relying on review.

So far the 'interesting ones' are mpu3050 and isl29501.

isl29501 looks OK to me. mpu3050 is clearly broken, buffer is both unaligned and too small!

isl29501 reads a pair of 8 bit registers, then writes them to a 32 bit value for no particular reason and puts that in the first 32 bits of the buffer having declared the channel to have a storage size of 16 bits.

So going to have some fun on one or other of the endian types...

J

Quoted 1 line
#16 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

In reply to Lars-Peter Clausen
Quoted 75 lines · Lars-Peter Clausen
Quoted 74 lines · Jonathan Cameron
Quoted 53 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 32 lines · Lars-Peter Clausen
Quoted 31 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 10 lines · Nuno Sá

[...]
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)

(quoted diff) +4 -0
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf-
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding
between
the data channels and the timestamp. If that happens this will
disclose
kernel stack memory to userspace.

Quoted 4 lines

This needs either a memset(data, 0x00, sizeof(data)) or maybe put
data
into the state struct and kzalloc it.

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than
explicit
memset, but some form of zeroization is needed.

Quoted 5 lines
Quoted 1 line

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily
aligned to 64 bit, which causes issues if we try to put the 64- bit

Oh, this is actually more problematic. Yes, since we have an array of
u16, that is not guaranteed to be 64bit aligned. Doing a quick search
of iio_push_to_buffers_with_timestamp() users and I could quickly
find 4/5 drivers with the same problem. I guess the API should clearly
state that data needs to be __at least__ 64 bits aligned (maybe a
future patch). Or we could even check the address and guarantee that it
is properly aligned before continuing (though Im guessing this will
break a lot of users...)

Quoted 5 lines
Quoted 2 lines

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use
__aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why
we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

The moment Lars mentioned this I groaned. As you've noted a few other
drivers have the same problem + the ABI doesn't clearly state or check this.

Quoted 5 lines
Quoted 2 lines

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should switch

Yeps, not surprised...

Quoted 2 lines

to put_unaligned(). We probably got lucky in most cases and the buffer

This would keep us from having to fix all the users (just need to fix the memory leakage you mention on the next email) to use a properly aligned buffer. And later on, if we want, we can always add an aligned variant of iio_push_to_buffers_with_timestamp() were we check for alignment...

- Nuno Sá

maintainer
#17 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 84 lines · On Sun, 03 May 2020 13:07:01 +0200 Nuno Sá <[email protected]> wrote:
Quoted 75 lines · Lars-Peter Clausen
Quoted 74 lines · Jonathan Cameron
Quoted 53 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 32 lines · Lars-Peter Clausen
Quoted 31 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 10 lines · Nuno Sá

[...]
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)

(quoted diff) +4 -0
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf-  
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding
between
the data channels and the timestamp. If that happens this will
disclose
kernel stack memory to userspace.

Quoted 4 lines

This needs either a memset(data, 0x00, sizeof(data)) or maybe put
data
into the state struct and kzalloc it.

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than
explicit
memset, but some form of zeroization is needed.

Quoted 5 lines
Quoted 1 line

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily
aligned to 64 bit, which causes issues if we try to put the 64- bit

Oh, this is actually more problematic. Yes, since we have an array of
u16, that is not guaranteed to be 64bit aligned. Doing a quick search
of iio_push_to_buffers_with_timestamp() users and I could quickly
find 4/5 drivers with the same problem. I guess the API should clearly
state that data needs to be __at least__ 64 bits aligned (maybe a
future patch). Or we could even check the address and guarantee that it
is properly aligned before continuing (though Im guessing this will
break a lot of users...)

Quoted 5 lines
Quoted 2 lines

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use
__aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why
we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

The moment Lars mentioned this I groaned. As you've noted a few other
drivers have the same problem + the ABI doesn't clearly state or check this.

Quoted 5 lines
Quoted 2 lines

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should switch

Yeps, not surprised...

Quoted 8 lines
Quoted 2 lines

to put_unaligned(). We probably got lucky in most cases and the buffer

This would keep us from having to fix all the users (just need to fix the memory leakage you mention on the next email) to use a properly aligned buffer. And later on, if we want, we can always add an aligned variant of iio_push_to_buffers_with_timestamp() were we check for alignment...

I'd rather scrub the existing set to fix this. The reason being to make the point they were broken. Fixing up with an unaligned write in the core is not 'obvious' to people looking at whether to pick up patches for individual drivers.

Unlikely to be too much extra over making sure we don't leak kernel
data. If we move them to the iio_priv structure we will avoid that
anyway due to that being kzalloc ed in the first place. We may leak previous timestamps or read values, but we don't care about that.

It's been there a while, so no 'super hurry' to fix these up but we should do it over next few months.

Jonathan

Quoted 3 lines

- Nuno Sá

maintainer
#18 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 101 lines · On Sun, 3 May 2020 12:29:26 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 84 lines · On Sun, 03 May 2020 13:07:01 +0200 Nuno Sá <[email protected]> wrote:
Quoted 75 lines · Lars-Peter Clausen
Quoted 74 lines · Jonathan Cameron
Quoted 53 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 32 lines · Lars-Peter Clausen
Quoted 31 lines · Jonathan Cameron
Quoted 19 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 10 lines · Nuno Sá

[...]
+static irqreturn_t adis16475_trigger_handler(int irq, void *p)

(quoted diff) +4 -0
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev, data, pf-    
Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding
between
the data channels and the timestamp. If that happens this will
disclose
kernel stack memory to userspace.

Quoted 4 lines

This needs either a memset(data, 0x00, sizeof(data)) or maybe put
data
into the state struct and kzalloc it.

Good spot. Could simply do __be16 data[ADI..] = {0}; rather than
explicit
memset, but some form of zeroization is needed.

Quoted 5 lines
Quoted 1 line

I've fixed up the applied patch with the above approach.

There is actually another issue. The stack data is not necessarily
aligned to 64 bit, which causes issues if we try to put the 64- bit

Oh, this is actually more problematic. Yes, since we have an array of
u16, that is not guaranteed to be 64bit aligned. Doing a quick search
of iio_push_to_buffers_with_timestamp() users and I could quickly
find 4/5 drivers with the same problem. I guess the API should clearly
state that data needs to be __at least__ 64 bits aligned (maybe a
future patch). Or we could even check the address and guarantee that it
is properly aligned before continuing (though Im guessing this will
break a lot of users...)

Quoted 5 lines
Quoted 2 lines

timestamp in it. I think data should really be in the state struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just use
__aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is why
we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly be in the testing branch.

The moment Lars mentioned this I groaned. As you've noted a few other
drivers have the same problem + the ABI doesn't clearly state or check this.

Quoted 5 lines
Quoted 2 lines

We should certainly fix all the drivers that suffer this problem first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should switch

Yeps, not surprised...

Quoted 8 lines
Quoted 2 lines

to put_unaligned(). We probably got lucky in most cases and the buffer

This would keep us from having to fix all the users (just need to fix the memory leakage you mention on the next email) to use a properly aligned buffer. And later on, if we want, we can always add an aligned variant of iio_push_to_buffers_with_timestamp() were we check for alignment...

I'd rather scrub the existing set to fix this. The reason being to make the point they were broken. Fixing up with an unaligned write in the core is not 'obvious' to people looking at whether to pick up patches for individual drivers.

Quoted 7 lines

Unlikely to be too much extra over making sure we don't leak kernel
data. If we move them to the iio_priv structure we will avoid that
anyway due to that being kzalloc ed in the first place. We may leak previous timestamps or read values, but we don't care about that.

It's been there a while, so no 'super hurry' to fix these up but we should do it over next few months.

It's also worth noticing that there is some care needed. Some devices don't need to zero because there is no padding. Some devices are using the core demux, so the timestamp is always in the same place, hence can be nicely refactored to an explicit structure, either on the stack or heap.

Anyhow, from the first few I looked at I suspect they are all going to have slightly different optimal solutions.

Take a look at the kxsd9 patch I'll send in a minute. For that one I think the cleanest thing is to leave the variable on the stack but use an explicit structure to ensure the alignment is correct.

I'll look to do a few of these at a time over the next few weeks as each one needs fairly careful review.

Jonathan

Quoted 7 lines

Jonathan

Quoted 3 lines

- Nuno Sá

#19 lore raw

Re: [PATCH v5 5/6] iio: imu: Add support for adis16475

Quoted 144 lines · Jonathan Cameron
Quoted 132 lines · On Sun, 3 May 2020 12:29:26 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 108 lines · On Sun, 03 May 2020 13:07:01 +0200 Nuno Sá <[email protected]> wrote:
Quoted 94 lines · Lars-Peter Clausen
Quoted 93 lines · Jonathan Cameron
Quoted 67 lines · On Sat, 02 May 2020 21:52:18 +0200 Nuno Sá <[email protected]> wrote:
Quoted 37 lines · Lars-Peter Clausen
Quoted 36 lines · Jonathan Cameron
Quoted 22 lines · On Mon, 27 Apr 2020 20:06:07 +0200 Lars-Peter Clausen <[email protected]> wrote:
Quoted 10 lines · Nuno Sá

[...]
+static irqreturn_t adis16475_trigger_handler(int
irq,
void *p)

(quoted diff) +4 -0
+{
[...]
+	__be16 data[ADIS16475_MAX_SCAN_DATA], *buffer;
[...]
+
+	iio_push_to_buffers_with_timestamp(indio_dev,
Quoted 2 lines

data, pf-

Quoted 1 line

timestamp);

If the timestamp is enabled the IIO core might insert padding
between
the data channels and the timestamp. If that happens this
will
disclose
kernel stack memory to userspace.

Quoted 5 lines

This needs either a memset(data, 0x00, sizeof(data)) or
maybe put
data
into the state struct and kzalloc it.

Good spot. Could simply do __be16 data[ADI..] = {0}; rather
than
explicit
memset, but some form of zeroization is needed.

Quoted 7 lines
Quoted 2 lines

I've fixed up the applied patch with the above
approach.

There is actually another issue. The stack data is not necessarily
aligned to 64 bit, which causes issues if we try to put the 64-
bit

Oh, this is actually more problematic. Yes, since we have an
array of
u16, that is not guaranteed to be 64bit aligned. Doing a quick
search
of iio_push_to_buffers_with_timestamp() users and I could quickly
find 4/5 drivers with the same problem. I guess the API should
clearly
state that data needs to be __at least__ 64 bits aligned (maybe
a
future patch). Or we could even check the address and guarantee
that it
is properly aligned before continuing (though Im guessing this
will
break a lot of users...)

Quoted 7 lines
Quoted 3 lines

timestamp in it. I think data should really be in the state
struct.

Yes, with a proper __aligned(8) attribute... Or couldn't we just
use
__aligned(8) on the stack variable?

Forcing alignment on the stack isn't terribly reliable, which is
why
we never do that for dma safe buffers.

Probably better to just move it to the state structure. I'll fix it up to do that. Please sanity check what will shortly
be in the testing branch.

The moment Lars mentioned this I groaned. As you've noted a few
other
drivers have the same problem + the ABI doesn't clearly state or check this.

Quoted 7 lines
Quoted 3 lines

We should certainly fix all the drivers that suffer this problem
first then we can think about adding a runtime check.

It looks like it is actually quite a few drivers, maybe we should
switch

Yeps, not surprised...

Quoted 2 lines

to put_unaligned(). We probably got lucky in most cases and the buffer

Quoted 8 lines

This would keep us from having to fix all the users (just need to fix
the memory leakage you mention on the next email) to use a properly
aligned buffer. And later on, if we want, we can always add an aligned variant of iio_push_to_buffers_with_timestamp() were we
check for alignment...

I'd rather scrub the existing set to fix this. The reason being to make the point they were broken. Fixing up with an unaligned write in the core is not 'obvious' to people looking at whether to pick up patches for individual drivers.

Unlikely to be too much extra over making sure we don't leak kernel
data. If we move them to the iio_priv structure we will avoid
that
anyway due to that being kzalloc ed in the first place. We may leak previous timestamps or read values, but we don't care about that.

Quoted 2 lines

It's been there a while, so no 'super hurry' to fix these up but we should do it over next few months.

It's also worth noticing that there is some care needed. Some devices don't need to zero because there is no padding. Some devices are using the core demux, so the timestamp is always in the same place, hence can be nicely refactored to an explicit structure, either on the stack or heap.

Quoted 6 lines

Anyhow, from the first few I looked at I suspect they are all going to have slightly different optimal solutions.

Take a look at the kxsd9 patch I'll send in a minute. For that one I think the cleanest thing is to leave the variable on the stack but use an explicit structure to ensure the alignment is correct.

Agreed. In those cases where there is no padding for the timestamp we
can leave the variable on the stack (we can even think about adding an helper macro to declare this kind of construct :D). For the other's we can make use of iio_priv being kzalloc at probe so that we don't leak kernel data...

- Nuno Sá

Quoted 8 lines

Jonathan

Quoted 4 lines

Jonathan

Quoted 2 lines

- Nuno Sá

author maintainer
#20 lore raw

PATCH v5 6/6 dt-bindings: iio: Add adis16475 documentation

In reply to Nuno Sá

Document the ADIS16475 device devicetree bindings

---
Changes in v2:
* Remove burst32 property;
* Rename clk-mode to adi,sync-mode;
* Remove clock-names;
* Add conditionals to state that clocks is only needed depending on adi,sync-mode property.

Changes in v3:
* Make use of 'allOf' in conditionals.

Changes in v4:
* Nothing changed.

Changes in v5:
* Nothing changed.

 .../bindings/iio/imu/adi,adis16475.yaml       | 137 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 138 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml new file +137 -0
new file mode 100644
index 000000000000..98baecb4b98a
@@ -0,0 +1,137 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/imu/adi,adis16475.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADIS16475 and similar IMUs
+
+maintainers:
+  - Nuno Sá <[email protected]>
+
+description: |
+  Analog Devices ADIS16475 and similar IMUs
+  https://www.analog.com/media/en/technical-documentation/data-sheets/ADIS16475.pdf
+
+properties:
+  compatible:
+    enum:
+      - adi,adis16475-1
+      - adi,adis16475-2
+      - adi,adis16475-3
+      - adi,adis16477-1
+      - adi,adis16477-2
+      - adi,adis16477-3
+      - adi,adis16470
+      - adi,adis16465-1
+      - adi,adis16465-2
+      - adi,adis16465-3
+      - adi,adis16467-1
+      - adi,adis16467-2
+      - adi,adis16467-3
+      - adi,adis16500
+      - adi,adis16505-1
+      - adi,adis16505-2
+      - adi,adis16505-3
+      - adi,adis16507-1
+      - adi,adis16507-2
+      - adi,adis16507-3
+
+  reg:
+    maxItems: 1
+
+  spi-cpha: true
+
+  spi-cpol: true
+
+  spi-max-frequency:
+    maximum: 2000000
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  reset-gpios:
+    description:
+      Must be the device tree identifier of the RESET pin. If specified,
+      it will be asserted during driver probe. As the line is active low,
+      it should be marked GPIO_ACTIVE_LOW.
+    maxItems: 1
+
+  adi,sync-mode:
+    description:
+      Configures the device SYNC pin. The following modes are supported
+      0 - output_sync
+      1 - direct_sync
+      2 - scaled_sync
+      3 - pulse_sync
+    allOf:
+      - $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0
+    maximum: 3
+
+  adi,scaled-output-hz:
+    description:
+      This property must be present if the clock mode is scaled-sync through
+      clock-names property. In this mode, the input clock can have a range
+      of 1Hz to 128HZ which must be scaled to originate an allowable sample
+      rate. This property specifies that rate.
+    minimum: 1900
+    maximum: 2100
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - spi-cpha
+  - spi-cpol
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - adi,adis16500
+              - adi,adis16505-1
+              - adi,adis16505-2
+              - adi,adis16505-3
+              - adi,adis16507-1
+              - adi,adis16507-2
+              - adi,adis16507-3
+
+    then:
+      properties:
+        adi,sync-mode:
+          minimum: 0
+          maximum: 2
+
+  - if:
+      properties:
+        adi,sync-mode:
+          enum: [1, 2, 3]
+
+    then:
+      dependencies:
+        adi,sync-mode: [ clocks ]
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    spi {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            adis16475: adis16475-3@0 {
+                    compatible = "adi,adis16475-3";
+                    reg = <0>;
+                    spi-cpha;
+                    spi-cpol;
+                    spi-max-frequency = <2000000>;
+                    interrupts = <4 IRQ_TYPE_EDGE_RISING>;
+                    interrupt-parent = <&gpio>;
+            };
+    };
+...
MAINTAINERS +1 -0
index a2ff8322c184..0828302accd8 100644
@@ -1015,6 +1015,7 @@ L:	[email protected]
 W:	http://ez.analog.com/community/linux-device-drivers
 S:	Supported
 F:	drivers/iio/imu/adis16475.c
+F:	Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
 
 ANALOG DEVICES INC ADM1177 DRIVER
 M:	Beniamin Bia <[email protected]>
Signature · 1 line
2.17.1
maintainer Reviewed-by on v5 6/6
#21 lore raw

Re: [PATCH v5 6/6] dt-bindings: iio: Add adis16475 documentation

Quoted 16 lines · On Mon, 13 Apr 2020 10:24:45 +0200, =?UTF-8?q?Nuno=20S=C3=A1?= wrote:

Document the ADIS16475 device devicetree bindings

---
Changes in v2:
* Remove burst32 property;
* Rename clk-mode to adi,sync-mode;
* Remove clock-names;
* Add conditionals to state that clocks is only needed depending on adi,sync-mode property.

Changes in v3:
* Make use of 'allOf' in conditionals.

Changes in v4:
* Nothing changed.

Quoted 8 lines

Changes in v5:
* Nothing changed.

 .../bindings/iio/imu/adi,adis16475.yaml       | 137 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 138 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
maintainer
#22 lore raw
In reply to Nuno Sá
Quoted 9 lines · On Mon, 13 Apr 2020 10:24:39 +0200 Nuno Sá <[email protected]> wrote:

This series adds support for the adis16475 and similar IMUs. This driver will be the first user of some changes on the adis library. Hence, the first three patches are related to the library:
* Add anaged device functions for registering triggers with the library;
* Updates the way irq_mask is passed to request_irq();
* It adds an update_bits() like API.

A new patch was introduced (iio: adis: Add burst_max_len variable) in order to make burst32 configuration at runtime.

Series looks good to me, but I'd like to allow a bit of time for DT review + anyone else who wants to take another look.

Thanks,

Jonathan

Quoted 23 lines

Nuno Sá (6):
iio: imu: adis: Add Managed device functions
iio: imu: adis: Add irq mask variable
iio: adis: Add adis_update_bits() APIs
iio: adis: Support different burst sizes
iio: imu: Add support for adis16475
dt-bindings: iio: Add adis16475 documentation

 .../bindings/iio/imu/adi,adis16475.yaml       |  137 ++
 MAINTAINERS                                   |    8 +
 drivers/iio/imu/Kconfig                       |   13 +
 drivers/iio/imu/Makefile                      |    1 +
 drivers/iio/imu/adis.c                        |   25 +
 drivers/iio/imu/adis16400.c                   |    2 +-
 drivers/iio/imu/adis16475.c                   | 1336 +++++++++++++++++
 drivers/iio/imu/adis_buffer.c                 |   58 +-
 drivers/iio/imu/adis_trigger.c                |   72 +-
 include/linux/iio/imu/adis.h                  |   87 +-
 10 files changed, 1728 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
 create mode 100644 drivers/iio/imu/adis16475.c
maintainer
#23 lore raw
Quoted 10 lines · On Mon, 13 Apr 2020 17:27:22 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 7 lines · On Mon, 13 Apr 2020 10:24:39 +0200 Nuno Sá <[email protected]> wrote:

This series adds support for the adis16475 and similar IMUs. This driver will be the first user of some changes on the adis library. Hence, the first three patches are related to the library:
* Add anaged device functions for registering triggers with the library;
* Updates the way irq_mask is passed to request_irq();
* It adds an update_bits() like API.

Quoted 5 lines
Quoted 2 lines

A new patch was introduced (iio: adis: Add burst_max_len variable) in order to make burst32 configuration at runtime.

Series looks good to me, but I'd like to allow a bit of time for DT review + anyone else who wants to take another look.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 29 lines

Thanks,

Jonathan

Quoted 23 lines

Nuno Sá (6):
iio: imu: adis: Add Managed device functions
iio: imu: adis: Add irq mask variable
iio: adis: Add adis_update_bits() APIs
iio: adis: Support different burst sizes
iio: imu: Add support for adis16475
dt-bindings: iio: Add adis16475 documentation

 .../bindings/iio/imu/adi,adis16475.yaml       |  137 ++
 MAINTAINERS                                   |    8 +
 drivers/iio/imu/Kconfig                       |   13 +
 drivers/iio/imu/Makefile                      |    1 +
 drivers/iio/imu/adis.c                        |   25 +
 drivers/iio/imu/adis16400.c                   |    2 +-
 drivers/iio/imu/adis16475.c                   | 1336 +++++++++++++++++
 drivers/iio/imu/adis_buffer.c                 |   58 +-
 drivers/iio/imu/adis_trigger.c                |   72 +-
 include/linux/iio/imu/adis.h                  |   87 +-
 10 files changed, 1728 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/imu/adi,adis16475.yaml
 create mode 100644 drivers/iio/imu/adis16475.c