From mboxrd@z Thu Jan 1 00:00:00 1970 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,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 AEB59C48BDF for ; Sun, 13 Jun 2021 15:08:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D68861354 for ; Sun, 13 Jun 2021 15:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231879AbhFMPK6 (ORCPT ); Sun, 13 Jun 2021 11:10:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:59746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231841AbhFMPK5 (ORCPT ); Sun, 13 Jun 2021 11:10:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7D50361285; Sun, 13 Jun 2021 15:08:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623596936; bh=GftFmaYqSVIZg3oByRPY+E4bX0nmqwmIDpCm3TeFH6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lk9KY1cHW6XrfQ0X+1SLt5oqBg0WCfkHuXVwJTa0ArMbeE6cXYkh1ld948I4BrHjz f2AGoqKM+hrEpjrYYefQlXsFwHQZg3xcMBBwiQebq+zepDoh1aNOqr7nnGX3ZutSeL nZ/iDXHDoCT2TMakaXqToxhI7CudhX9gRwZp0hOa+VeyvUcxRLJ2Vjg0oYmLTy7CP0 803UhjjZu8yr6jDAw8sYxPpxxCXpN2VsSt+WJSy1fgiY3uj9ICV8l52esVIA/vRdqX uiW86C+19Zz3lVUjtl/PKT48Bc+1CzezcCrInOTYTdIyT8Z2FDn2M4zSX5workeR/B iRWbcsK3zUvKw== From: Jonathan Cameron To: linux-iio@vger.kernel.org, Andy Shevchenko , Nuno Sa Cc: Linus Walleij , Jan Kiszka , Jonathan Cameron , =?UTF-8?q?Nuno=20S=C3=A1?= Subject: [PATCH v2 4/4] iio: imu: adis16400: Fix buffer alignment requirements. Date: Sun, 13 Jun 2021 16:10:39 +0100 Message-Id: <20210613151039.569883-5-jic23@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210613151039.569883-1-jic23@kernel.org> References: <20210613151039.569883-1-jic23@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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_unaligned() 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 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 cb8d3ffab6fc..66a83ebd3109 100644 --- a/drivers/iio/imu/adis16400.c +++ b/drivers/iio/imu/adis16400.c @@ -648,13 +648,23 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p) if (ret) dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret); - 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_unaligned(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); -- 2.32.0