From patchwork Sun May 17 17:29:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Cameron X-Patchwork-Id: 11554217 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA8E7913 for ; Sun, 17 May 2020 17:32:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCE7E207E8 for ; Sun, 17 May 2020 17:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589736727; bh=Z7VxFsNB9LM9hUPq/XJa4cJQiQ2taNpfFzDMic5EeQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=wEOvz64L/h2lNlUdhQI9AOFBoIQ9Wnl9Qu6OkySZkEImgQib366BKjN5u3J2+l6JR FK5BC09NVhWGhO/Il8vQq1iOOwDpbbykI1/cytHFNs5YYbtPaf/UGMo5qZyjGTCzm7 JJJXXhATDcEJM7duRzisplUep0QByBE4YEpOhYDY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726290AbgEQRcH (ORCPT ); Sun, 17 May 2020 13:32:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:51242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726248AbgEQRcG (ORCPT ); Sun, 17 May 2020 13:32:06 -0400 Received: from localhost.localdomain (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BC7FA207DA; Sun, 17 May 2020 17:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589736726; bh=Z7VxFsNB9LM9hUPq/XJa4cJQiQ2taNpfFzDMic5EeQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fBQ5Sdw9H6KXbXCqM2yfV5Ot3ggOlqfrZTSaHaoDcXmdSJb7ou2DwhSUUHdy5epEn Qe6eplQpG45HectaVlUdTW904p3btjWdGpwzn5MlC3QvoauRS1P1Eyb3awr9ugafs1 khXw5miZR7w6hcYbl+/3BjEqn38zWbDSaE8Juh3A= From: jic23@kernel.org To: linux-iio@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH 01/11] iio: accel: kxsd9: Fix alignment of local buffer. Date: Sun, 17 May 2020 18:29:50 +0100 Message-Id: <20200517173000.220819-2-jic23@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200517173000.220819-1-jic23@kernel.org> References: <20200517173000.220819-1-jic23@kernel.org> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Jonathan Cameron iio_push_to_buffers_with_timestamp assumes 8 byte alignment which is not guaranteed by an array of smaller elements. Reported-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/iio/accel/kxsd9.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c index 0b876b2dc5bd..f989e6ffda88 100644 --- a/drivers/iio/accel/kxsd9.c +++ b/drivers/iio/accel/kxsd9.c @@ -209,14 +209,20 @@ static irqreturn_t kxsd9_trigger_handler(int irq, void *p) const struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct kxsd9_state *st = iio_priv(indio_dev); + /* + * Ensure correct positioning and alignment of timestamp. + * No need to zero initialize as all elements written. + */ + struct { + __be16 chan[4]; + s64 ts; + } hw_values; int ret; - /* 4 * 16bit values AND timestamp */ - __be16 hw_values[8]; ret = regmap_bulk_read(st->map, KXSD9_REG_X, - &hw_values, - 8); + hw_values.chan, + sizeof(hw_values.chan)); if (ret) { dev_err(st->dev, "error reading data\n"); @@ -224,7 +230,7 @@ static irqreturn_t kxsd9_trigger_handler(int irq, void *p) } iio_push_to_buffers_with_timestamp(indio_dev, - hw_values, + &hw_values, iio_get_time_ns(indio_dev)); iio_trigger_notify_done(indio_dev->trig);