From patchwork Mon Jul 19 14:50:12 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: 479907 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp4226318jao; Mon, 19 Jul 2021 08:22:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy2CF6b6ZQafWt0Kl7NcTsCPZmD1G99pYem2peeQgulwANWjzKCk4t1uH+tbp9uVSB1CHy X-Received: by 2002:a50:ed89:: with SMTP id h9mr34848616edr.106.1626708143092; Mon, 19 Jul 2021 08:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708143; cv=none; d=google.com; s=arc-20160816; b=vQfNUcQub3IoV4+vd6vN9O1GCRNptzRYsz4JFuw5GJrUKLucpyGU4FvPeTgOBqWk3S NeKJlF7DUSle9An5zrEjVTeo8B2AF5ME1mgYL9YMdAHwLn7pd8s2kZ84T85RAluOYjYi uyBs/YPMot1TrXWYrPzyoyOLpHdZgwjIXM1V7kdJHnriMdN4Dza5BNYltDuS6LtcWGL9 nQT7MMYA8Az7X3XyXuRFZQZnrPemtBQPHaZjldkkKIQR9BXlvJMQgRTyxORtflsMUODi u6dCZpLPYRKBnkVLhHjxHQAFqpgFnbn74J1t5JxDHkoMO9jjpRgtCpxjvsV9WrXaiOJD vzYA== 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=8tHcZ0yqpE2k7qYFeGpnwXlLA24EmBhARjPGSPlhYuo=; b=EvETC833YMEFIh0wnEeEpSgHfBkLW7bqiSs52mrUezxYok6qKmqh/AlJEEeqGBV6Mo Ws1MFdOv7H4C4TgLXebnWrIJ8+ASaqunGWZOSeRFIfDsHQ3NeSNdu0RrPEqLkKyPiy8i Stl6WIJTuJN9zvuXZJCWnhLcxE41e9dzTd+24AQ6fUfgnpdkqqXpjPX9b79+SkoGjBp+ 7hPzf9udPehphRPafI0GqZpUfU4ne47TMYmIMlpysX2hlxvvaINpoguUTmm3MUDZKXx9 HPQ1FVbK77lyPKIOFFFEzRI3D1OHD/PzcSD34SVdRfi1GEN+OG5GCZ7tV8wtNLqy+Kpo lAhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oWG19Uo8; 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 l3si24719878ejo.634.2021.07.19.08.22.22; Mon, 19 Jul 2021 08:22:23 -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=oWG19Uo8; 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 S244891AbhGSOlg (ORCPT + 12 others); Mon, 19 Jul 2021 10:41:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:54628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343598AbhGSOjf (ORCPT ); Mon, 19 Jul 2021 10:39:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 58C0D6120E; Mon, 19 Jul 2021 15:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707953; bh=jZMdGmbOHjjGOtpYHIVxX4PkF25zCODcqZ43E09E8R0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oWG19Uo8sQPFFQTEA8BO8zyAO4Jgi/wbq+gRAcgUWhrD2UWFUkssKF80vWUMeFbVU ipIjMmhJ4ERDDtXhAcwkxHtQfEFJL1jtq3E74vgvISgw4zrkAoc8lyq7/PVzWp2YA8 kCnRASQpKyVJXdHiOgJQbBWrUVJCeaXCmpUZ05zM= 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 4.14 123/315] iio: accel: hid: Fix buffer alignment in iio_push_to_buffers_with_timestamp() Date: Mon, 19 Jul 2021 16:50:12 +0200 Message-Id: <20210719144946.918607875@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.861561397@linuxfoundation.org> References: <20210719144942.861561397@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 f573d9c61fc3..fc210d88bba9 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c @@ -42,8 +42,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; @@ -255,8 +258,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; @@ -281,7 +284,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;