From patchwork Sat May 1 17:25:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12234937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BA02C433ED for ; Sat, 1 May 2021 17:26:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D91FF6157E for ; Sat, 1 May 2021 17:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231517AbhEAR1b (ORCPT ); Sat, 1 May 2021 13:27:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:33160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbhEAR1a (ORCPT ); Sat, 1 May 2021 13:27:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 502A861352; Sat, 1 May 2021 17:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619890000; bh=FUch7K2YPak34gEMoFnxZ2XFRa3bDN6RsgpW16M1uz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e6FjrSVBep2SyD6fLbVX9IZo048J7b6K1POpaQnU6nKiVjPY/ADDdG5eteWZjod4F ujZhRE0Erx8ewtyVBDObQyqaQc5lEQKJc6irDRGg0sjVneodMic3m1+xUM0Brgc4Lo 1AXzx1bcUDegAgZzuIFJOU18KBZ4iIXomApxdCqk9t35SSFmepc2pkgnIpvq9503u3 8vAeNHQPtxtJf0kDrQL/3Z3ZFS4Je618NJalP1VZ9Yg8P/qoQhFBppzSsJQscfiXnw t99lj8g6/3bTmo3TEagPiFMaAr6odOXRreZfT09zbXLoDxb39Klc/nLHk1Dy8X0+AQ zYPsKnzs6siLQ== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Jonathan Cameron Subject: [RFC PATCH 1/4] iio: core: Introduce iio_push_to_buffers_with_ts_na() for non aligned case. Date: Sat, 1 May 2021 18:25:12 +0100 Message-Id: <20210501172515.513486-2-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210501172515.513486-1-jic23@kernel.org> References: <20210501172515.513486-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron 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 --- drivers/iio/industrialio-buffer.c | 36 +++++++++++++++++++++++++++++++ include/linux/iio/buffer.h | 4 ++++ include/linux/iio/iio-opaque.h | 4 ++++ 3 files changed, 44 insertions(+) diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 9a8e16c7e9af..818dfaa73665 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -1727,6 +1727,42 @@ int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data) } EXPORT_SYMBOL_GPL(iio_push_to_buffers); +/** + * iio_push_to_buffers_with_ts_na() - push to registered buffer, + * no alignment or space requirements. + * @indio_dev: iio_dev structure for device. + * @data: channel data excluding the timestamp. + * @data_sz: size of data. + * @timestamp: timestamp for the sample data. + * + * This special variant of iio_push_to_buffers_with_timetamp() does + * not require space for the timestamp, or 8 byte alignment of data. + * It does however require an allocation on first call and additional + * coppies on all calls, so should be avoided if possible + */ +int iio_push_to_buffers_with_ts_na(struct iio_dev *indio_dev, + const void *data, + size_t data_sz, + int64_t timestamp) +{ + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); + + data_sz = min_t(size_t, indio_dev->scan_bytes, data_sz); + if (iio_dev_opaque->bounce_buffer_size != indio_dev->scan_bytes) { + iio_dev_opaque->bounce_buffer = + devm_krealloc(&indio_dev->dev, + iio_dev_opaque->bounce_buffer, + indio_dev->scan_bytes, GFP_KERNEL); + if (!iio_dev_opaque) + return -ENOMEM; + } + memcpy(iio_dev_opaque->bounce_buffer, data, data_sz); + return iio_push_to_buffers_with_timestamp(indio_dev, + iio_dev_opaque->bounce_buffer, + timestamp); +} +EXPORT_SYMBOL_GPL(iio_push_to_buffers_with_ts_na); + /** * iio_buffer_release() - Free a buffer's resources * @ref: Pointer to the kref embedded in the iio_buffer struct diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h index b6928ac5c63d..4ea9027ad2bf 100644 --- a/include/linux/iio/buffer.h +++ b/include/linux/iio/buffer.h @@ -38,6 +38,10 @@ static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev, return iio_push_to_buffers(indio_dev, data); } +int iio_push_to_buffers_with_ts_na(struct iio_dev *indio_dev, + const void *data, size_t data_sz, + int64_t timestamp); + bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, const unsigned long *mask); diff --git a/include/linux/iio/iio-opaque.h b/include/linux/iio/iio-opaque.h index 32addd5e790e..70ca58e66c0a 100644 --- a/include/linux/iio/iio-opaque.h +++ b/include/linux/iio/iio-opaque.h @@ -19,6 +19,8 @@ * @groupcounter: index of next attribute group * @legacy_scan_el_group: attribute group for legacy scan elements attribute group * @legacy_buffer_group: attribute group for legacy buffer attributes group + * @bounce_buffer: for devices that call iio_push_to_buffers_with_timestamp_na + * @bounce_buffer_size: size of currently allocate bounce buffer * @debugfs_dentry: device specific debugfs dentry * @cached_reg_addr: cached register address for debugfs reads * @read_buf: read buffer to be used for the initial reg read @@ -38,6 +40,8 @@ struct iio_dev_opaque { int groupcounter; struct attribute_group legacy_scan_el_group; struct attribute_group legacy_buffer_group; + void *bounce_buffer; + size_t bounce_buffer_size; #if defined(CONFIG_DEBUG_FS) struct dentry *debugfs_dentry; unsigned cached_reg_addr; From patchwork Sat May 1 17:25:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12234939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2806EC433B4 for ; Sat, 1 May 2021 17:26:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F3FEA613B0 for ; Sat, 1 May 2021 17:26:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231758AbhEAR1c (ORCPT ); Sat, 1 May 2021 13:27:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:33176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231724AbhEAR1c (ORCPT ); Sat, 1 May 2021 13:27:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 10A9661353; Sat, 1 May 2021 17:26:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619890002; bh=JMdkmCwdMa062ZW88E1zPmLbJ7CiSfvIbLzrI1I4gPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U/mTFHIEkpvUpRHxmkJGt5cgJC3Kmrl2Ikglw99yBnS7SwXtx8Jj/cEQEpP9Eyd4k 9/0XpyF2hAfRAlcuAPBMDAzpYDzUQQvV/kj9gDUuRJWhfHb04tK9Q9+NAPz2OVJ5CA 93zfo6WWVuGEwwBzy+kFhxw75D32cnZIuuuzVIeNFT61ku5fnkhN7OCdMcBjc0a1dC jNxaeyMJy+4XN+Yp1A+waJgXxOitKHgV110uZj2OUOV59sLdzc9I8OlLiCDs/zdXbM t0fN25N78yx4KC3gO13hvBe3Wy8NTkkDeiSS8z9KcohbpXoR0d5tp5VRs1OD6IUfgy PkoF0hbWOaJnA== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Jonathan Cameron , Jan Kiszka Subject: [RFC PATCH 2/4] iio: adc: ti-adc108s102: Fix alignment of buffer pushed to iio buffers. Date: Sat, 1 May 2021 18:25:13 +0100 Message-Id: <20210501172515.513486-3-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210501172515.513486-1-jic23@kernel.org> References: <20210501172515.513486-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Use the newly introduce iio_push_to_buffers_with_ts_na() function to ensure a bounce buffer is used to provide the required alignment and space padding needed by the IIO core which requires the timestamp is naturally aligned. There will be a performance cost to this change but it will ensure the driver works on platforms that do not support unaligned 8 byte assignements, and with consumer drivers that may assume natural alignment of the timestamp. Issue found as part of an audit of all calls to iio_push_to_buffers_with_timestamp() Fixes: 7e87d11c9bda ("iio: adc: Add support for TI ADC108S102 and ADC128S102") Signed-off-by: Jonathan Cameron Cc: Jan Kiszka --- drivers/iio/adc/ti-adc108s102.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/iio/adc/ti-adc108s102.c b/drivers/iio/adc/ti-adc108s102.c index 183b2245e89b..7aeed3503829 100644 --- a/drivers/iio/adc/ti-adc108s102.c +++ b/drivers/iio/adc/ti-adc108s102.c @@ -75,9 +75,9 @@ struct adc108s102_state { * rx_buf: |XX|R0|R1|R2|R3|R4|R5|R6|R7|tt|tt|tt|tt| * * tx_buf: 8 channel read commands, plus 1 dummy command - * rx_buf: 1 dummy response, 8 channel responses, plus 64-bit timestamp + * rx_buf: 1 dummy response, 8 channel responses */ - __be16 rx_buf[13] ____cacheline_aligned; + __be16 rx_buf[9] ____cacheline_aligned; __be16 tx_buf[9] ____cacheline_aligned; }; @@ -149,9 +149,10 @@ static irqreturn_t adc108s102_trigger_handler(int irq, void *p) goto out_notify; /* Skip the dummy response in the first slot */ - iio_push_to_buffers_with_timestamp(indio_dev, - (u8 *)&st->rx_buf[1], - iio_get_time_ns(indio_dev)); + iio_push_to_buffers_with_ts_na(indio_dev, + &st->rx_buf[1], + st->ring_xfer.len - sizeof(st->rx_buf[1]), + iio_get_time_ns(indio_dev)); out_notify: iio_trigger_notify_done(indio_dev->trig); From patchwork Sat May 1 17:25:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12234941 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1678BC433B4 for ; Sat, 1 May 2021 17:26:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E523761352 for ; Sat, 1 May 2021 17:26:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231774AbhEAR1e (ORCPT ); Sat, 1 May 2021 13:27:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:33194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231724AbhEAR1d (ORCPT ); Sat, 1 May 2021 13:27:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B18A26157E; Sat, 1 May 2021 17:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619890003; bh=JoCp7na093tHRDNFCpVgawLhstlanRFN7EVE+Cga+pE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sA7tZEWL8WY1zutbQAI4E6H6SzQTiNw5paHUZnzXNUtzzabdI64KiR/SJkdudSyJV DJGufWsEb/7y9LPHU2yq8RRkvhbNBTFH98MZgtWxHjLTo6MBNhraUe0r5nuVTpUTIz iK+4Zre2qQsMvCIlIcGp/jMizn79n3lw5F7meuwn2HItDucfjA0N1KTZ+AuA/1+L1b 99d1o7FDdbH7N57U2um245xuthiqKN/xTC1508kTDrfplsIhMycTZ0M9rEE6xzByvs WqS7v1dzvUdX3OdiLCqScjjncAcwTiqBDe05xgOEV05Oai42JrYw8XlLTv73eVgJTc D3niLPguI/7tg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Jonathan Cameron , Linus Walleij Subject: [RFC PATCH 3/4] iio: gyro: mpu3050: Fix alignment and size issues with buffers. Date: Sat, 1 May 2021 18:25:14 +0100 Message-Id: <20210501172515.513486-4-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210501172515.513486-1-jic23@kernel.org> References: <20210501172515.513486-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron Fix a set of closely related issues. 1. When using fifo_values() there was not enough space for the timestamp to be inserted by iio_push_to_buffers_with_timestamp() 2. fifo_values() did not meet the alignment requirement of iio_push_to_buffers_with_timestamp() 3. hw_values did not meet the alignment requirement either. 1 and 2 fixed by using new iio_push_to_buffers_with_ts_na() which has no alignment or space padding requirements. 3 fixed by introducing a structure that makes the space and alignment requirements explicit. Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope") Signed-off-by: Jonathan Cameron Cc: Linus Walleij Reviewed-by: Linus Walleij --- drivers/iio/gyro/mpu3050-core.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c index ac90be03332a..a7fdfe811258 100644 --- a/drivers/iio/gyro/mpu3050-core.c +++ b/drivers/iio/gyro/mpu3050-core.c @@ -462,13 +462,10 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p) struct iio_dev *indio_dev = pf->indio_dev; struct mpu3050 *mpu3050 = iio_priv(indio_dev); int ret; - /* - * Temperature 1*16 bits - * Three axes 3*16 bits - * Timestamp 64 bits (4*16 bits) - * Sum total 8*16 bits - */ - __be16 hw_values[8]; + struct { + __be16 chans[4]; + s64 timestamp __aligned(8); + } scan; s64 timestamp; unsigned int datums_from_fifo = 0; @@ -563,9 +560,10 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p) fifo_values[4]); /* Index past the footer (fifo_values[0]) and push */ - iio_push_to_buffers_with_timestamp(indio_dev, - &fifo_values[1], - timestamp); + iio_push_to_buffers_with_ts_na(indio_dev, + &fifo_values[1], + sizeof(__be16) * 4, + timestamp); fifocnt -= toread; datums_from_fifo++; @@ -623,15 +621,15 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p) goto out_trigger_unlock; } - ret = regmap_bulk_read(mpu3050->map, MPU3050_TEMP_H, &hw_values, - sizeof(hw_values)); + ret = regmap_bulk_read(mpu3050->map, MPU3050_TEMP_H, scan.chans, + sizeof(scan.chans)); if (ret) { dev_err(mpu3050->dev, "error reading axis data\n"); goto out_trigger_unlock; } - iio_push_to_buffers_with_timestamp(indio_dev, hw_values, timestamp); + iio_push_to_buffers_with_timestamp(indio_dev, &scan, timestamp); out_trigger_unlock: mutex_unlock(&mpu3050->lock); From patchwork Sat May 1 17:25:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 12234943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 553F3C43460 for ; Sat, 1 May 2021 17:26:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 215CD610EA for ; Sat, 1 May 2021 17:26:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231846AbhEAR1f (ORCPT ); Sat, 1 May 2021 13:27:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:33238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231784AbhEAR1f (ORCPT ); Sat, 1 May 2021 13:27:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3B785613B0; Sat, 1 May 2021 17:26:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1619890005; bh=WhMpe9jY5QFi6XU8b1GuG7GpGTvF623i/0hC2OJnUhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QmV/rqLUItgjWS4dDWmXqEnpT4MCv7fZZ6j2vzmz59X4S8fr9fuYlnWS+3SPgzhRk NcEy4cSxB7Sw2+/F5SnaiK2zSku6u33tyYy/vhPWiE1MDK01uKXvQ+w9NZHeqyh8MS R8ZzrRqLleu0z5e5M+RqasUvnyTn0PgzW+CXhw0wmRsZb1QisaPgpOw2t9TStFLkW8 gDtIFjJZ9ikXqz6Qucde8Uwwcm1aS8yt6pFqS3e0lCkksbjE/IELrAq1J9ct8v59Zz n3lXLbE++LdWeqMAWwLv1j5Okdg22IMWHGPV5h61xRtwToNLlmpKtPPP8kUVUcCoxy +g25n/awwkzzg== From: Jonathan Cameron To: linux-iio@vger.kernel.org Cc: Jonathan Cameron , Nuno Sa Subject: [RFC PATCH 4/4] iio: imu: adis16400: Fix buffer alignment requirements. Date: Sat, 1 May 2021 18:25:15 +0100 Message-Id: <20210501172515.513486-5-jic23@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210501172515.513486-1-jic23@kernel.org> References: <20210501172515.513486-1-jic23@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron iio_push_to_buffers_with_timestamp() requires that the buffer is 8 byte alignment to ensure an inserted timestamp is naturally aligned. This requirement was not met here when burst mode is in use beause of a leading u16. Use the new iio_push_to_buffers_with_ts_na() function that has more relaxed requirements. It is somewhat complex to access that actual data length, but a safe bound can be found by using scan_bytes - sizeof(timestamp) so that is used in this path. More efficient approaches exist, but this ensure correctness at the cost of using a bounce buffer. Fixes: 5075e0720d93 ("iio: imu: adis: generalize burst mode support") Signed-off-by: Jonathan Cameron Cc: Nuno Sa Reviewed-by: Nuno Sá --- drivers/iio/imu/adis16400.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/iio/imu/adis16400.c b/drivers/iio/imu/adis16400.c index 768aa493a1a6..c6d03a37373b 100644 --- a/drivers/iio/imu/adis16400.c +++ b/drivers/iio/imu/adis16400.c @@ -663,13 +663,23 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p) spi_setup(st->adis.spi); } - if (st->variant->flags & ADIS16400_BURST_DIAG_STAT) + if (st->variant->flags & ADIS16400_BURST_DIAG_STAT) { buffer = adis->buffer + sizeof(u16); - else - buffer = adis->buffer; + /* + * The size here is always larger than, or equal to the true + * size of the channel data. This may result in a larger copy + * than necessary, but as the target buffer will be + * buffer->scan_bytes this will be safe. + */ + iio_push_to_buffers_with_ts_na(indio_dev, buffer, + indio_dev->scan_bytes - sizeof(pf->timestamp), + pf->timestamp); + } else { + iio_push_to_buffers_with_timestamp(indio_dev, + adis->buffer, + pf->timestamp); + } - iio_push_to_buffers_with_timestamp(indio_dev, buffer, - pf->timestamp); iio_trigger_notify_done(indio_dev->trig);