From patchwork Mon Jul 12 06:10:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 472865 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2648146jao; Sun, 11 Jul 2021 23:30:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKTTJxFxsDWBAPMw+uwr+16doo+y1ko76G2vlsPsdngx8IbOKByouMJt3i549EnmqSSRud X-Received: by 2002:a17:906:b301:: with SMTP id n1mr6521318ejz.271.1626071420221; Sun, 11 Jul 2021 23:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626071420; cv=none; d=google.com; s=arc-20160816; b=QAplqaMTHndjleKVn2p6RlPd6MW1uNN9ZgB4BH9zJPE79bbto0RGnniEY2k2RCcfcR eg/GNSDdgEj2sSVzu1/gF4f8p9a4IBh/oTfLDeR8Nx1r9L5N1eR7sHf6Kwf46qqgkDGm /BdVFivJ2KQBDru02y9CF1tzkxOwEV85ZAD+FuIRG8tdUuJNJiKkJKYSh/jp9xnCqv77 bZQPsLwfLOSU/gjHB3eqSjIsVjykmDaU5eyAA0GP4KTwjU9I6bNiJABQ+/H/AApk0fyy fCCgAXH4VUE753OsQPdVux1xSdq96bJ3VXT6qIdHJjZNXJ8XfBD+/Ve69ZGHPO0meqTj IHkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PGQd9pm3eUBj04fDW9cvcSTxCZawmoP+wbXJbc6u8BA=; b=Pr1/TulGUNB5tPc9HGmvoJqRQB1ffzkgx11Wl+B38mKTYZCzNBA2mYq67fy2QGZX08 Z4AveSwNXRiWrVuleFQhSy7cqlg9hNubwjCIpaI2ixumvGe3qYuy9BkOjx7u2F41uI+8 sTiJ4HeKEGViZh3q3UL9bY3HsMXmMvn9ffmvFUkCdPkn8qYDKII2s9tGxS0LIIu/9Qlr kMwGULEsLC0QJxp/DfJLoWFnc6lXsvD8i77mkbp8WAm67g1HH3q34UPjjTJJahgGVmBb RvS3SJEyO/Nn1mt4bK/jrteXvWqOoJm7jkff82vXJJM0cMErrXiJ7cU8OvaBOoNI83Ji Wuuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dNL4PxHL; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz6si16420285ejc.610.2021.07.11.23.30.19; Sun, 11 Jul 2021 23:30:20 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dNL4PxHL; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235879AbhGLGc4 (ORCPT + 12 others); Mon, 12 Jul 2021 02:32:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:47908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235904AbhGLG3i (ORCPT ); Mon, 12 Jul 2021 02:29:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BB327610A6; Mon, 12 Jul 2021 06:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071170; bh=HDGL2HFCogh5/3MH5xyseAs7SOq5POpo+SlbD3jZ77E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dNL4PxHLWPAlZYdEV3QuccVSYc0P7+uYl6MmFk7uPSzK9glQWbUJKmIhcobbIHri0 OEzM8kVvtUt45SE9hgO68jG5ktXEImWscEQ5YBin3PX4BDcB1hKlZ0W2ziSGJUcf7G eAA6L9SpKk2P9EqCqYEy02tn2b72u7jequMMYDdY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathan Cameron , Srinivas Pandruvada , Andy Shevchenko , Sasha Levin Subject: [PATCH 5.4 262/348] iio: accel: hid: Fix buffer alignment in iio_push_to_buffers_with_timestamp() Date: Mon, 12 Jul 2021 08:10:46 +0200 Message-Id: <20210712060738.147386458@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jonathan Cameron [ Upstream commit c6559bf796ccdb3a0c79db846af96c8f7046880b ] To make code more readable, use a structure to express the channel layout and ensure the timestamp is 8 byte aligned. Note this matches what was done in all the other hid sensor drivers. This one was missed previously due to an extra level of indirection. Found during an audit of all calls of this function. Fixes: a96cd0f901ee ("iio: accel: hid-sensor-accel-3d: Add timestamp") Signed-off-by: Jonathan Cameron Cc: Srinivas Pandruvada Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/20210501170121.512209-4-jic23@kernel.org Signed-off-by: Sasha Levin --- drivers/iio/accel/hid-sensor-accel-3d.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) -- 2.30.2 diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index 0d9e2def2b25..f908476fa095 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c @@ -29,8 +29,11 @@ struct accel_3d_state { struct hid_sensor_hub_callbacks callbacks; struct hid_sensor_common common_attributes; struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX]; - /* Reserve for 3 channels + padding + timestamp */ - u32 accel_val[ACCEL_3D_CHANNEL_MAX + 3]; + /* Ensure timestamp is naturally aligned */ + struct { + u32 accel_val[3]; + s64 timestamp __aligned(8); + } scan; int scale_pre_decml; int scale_post_decml; int scale_precision; @@ -241,8 +244,8 @@ static int accel_3d_proc_event(struct hid_sensor_hub_device *hsdev, accel_state->timestamp = iio_get_time_ns(indio_dev); hid_sensor_push_data(indio_dev, - accel_state->accel_val, - sizeof(accel_state->accel_val), + &accel_state->scan, + sizeof(accel_state->scan), accel_state->timestamp); accel_state->timestamp = 0; @@ -267,7 +270,7 @@ static int accel_3d_capture_sample(struct hid_sensor_hub_device *hsdev, case HID_USAGE_SENSOR_ACCEL_Y_AXIS: case HID_USAGE_SENSOR_ACCEL_Z_AXIS: offset = usage_id - HID_USAGE_SENSOR_ACCEL_X_AXIS; - accel_state->accel_val[CHANNEL_SCAN_INDEX_X + offset] = + accel_state->scan.accel_val[CHANNEL_SCAN_INDEX_X + offset] = *(u32 *)raw_data; ret = 0; break;