From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8AE3136308F for ; Mon, 2 Mar 2026 12:03:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772452999; cv=none; b=L8nPBRrT7MQ2nXux37wDrc5M/P/tbViViNo1UymQ2MU6uNwBHRrktYnQiSSsq4oILvVNbk6Q9fa7eFP7iXb7mO2LqKrwdSHs9DT3CmzQnAiclM6q+POlaowh0a283P/lnYgeZoUFPH6W1We2fMqDsB4dmOBrlDCoB8RGLevbfU0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772452999; c=relaxed/simple; bh=a4wt8Vn9RF94EG9Mt5gAsLlW1nubpY1/4xbHb0qPvu4=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=TiaPBO2Faj/Q33xCyQZQ0TDyMlD/pJdStwVa6VClYZ7Lc4uDmtHzARyhNodyP4RGct7+ISGgFxg8VOg4kAKCEHRDjO/sWnEXtXozGu8QhT9aKjtcANJvsakGT6rDaiU1sATCnxN6ulphjZ1H14CpmOLacW5JjlfthzwygXuETvc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Kqccgrex; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Kqccgrex" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-48374014a77so52212485e9.3 for ; Mon, 02 Mar 2026 04:03:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772452997; x=1773057797; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=SX9nI5MblHYERbWwduXl8HQ63TKdaovR/2/q0+Kg+T0=; b=Kqccgrexz4hslJRgxjTh9kvXdww6wKyNmyy+4FDFwMA2vBRf7QYfbWqW995AoJ9kyG KZ03ahUhfxQhxs9lvu8gJcypQdap6xo7PDk7Vc6Lvqb5rhjCA9duK4ykSTc0aMnM+sHw qGGftCUoaFKvd3xMfKIKoJxK3KPUe6FVL3GfpHVs3Z4qyfOxuDI/Sf823SkNEMlzPJaP 5znlgN9Jjt/Nco2cbgoTohoqt/YatPKbMbHqTS264lEWXkEIP5fryKTttuHjWzLy4fbQ /hEU05IdmWNO5AYrwS9BAqSQLTw2sf61DIGRGUJMSQjfYsW2gCQgmXfNYP+7iwpFZOQf Gknw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772452997; x=1773057797; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SX9nI5MblHYERbWwduXl8HQ63TKdaovR/2/q0+Kg+T0=; b=SwYNFXXwRI8iWo1uImOMvvfpukTI5ubBPMbmY5to5FiCKcvbKOzAoEsLLhwhxZiK8R 3fgJ/Ye/AnOi4Ct9pr4pCOs31uK1ccNrxFHdJXxxFJM3yy+IXx+b9vqiKuEJ7KH0K+1W 4EVwrer8J3g+WXJMR1pR+WjBQQrR16pmEQrxKpKIFrT039/TQMQuYAtIfx9iFL6ZUmlS wooBsI8e84Bwxo+8GYvPJy0Z34aUugOpD4cLTsEEwLay8uPq1NjtX/OhFBcNdgSp37F6 J/SpACqitYqITwfeH2+tZe71OZwY8RgJwtC9F5CSxoGVWaPaO77a+4mSSjnAPq5T5Dzk +jUw== X-Forwarded-Encrypted: i=1; AJvYcCUfK3iF7oCpjT2O8JWAiFc/yxvzHKe37Z2I32xaMOwLP2Q/Kvr/LKL765No5bAjIcNI0WGmma3dJL8CFus=@vger.kernel.org X-Gm-Message-State: AOJu0YxOaC7HX39A3mdS3VCjp6CB9N/FO77IZdGVWxxHPHxZDGRzBEAJ 5AazB1Ka/JmzQC6zryAkAdEiHdiITL0LuXXOEZU1TQ47ta+rqKjuP/oN X-Gm-Gg: ATEYQzzk1mUw2CcSaxUhemK3/fkwWyU3YsPbFJY8NycXDn/3rKhjNSP6sxNEvT5M6lS vCFS/iD1AzeEP38yIU/Pakee24DGx1dK2nw3wWI/8DA3cJ6QEPFI820qCBW2ddGZTXDkNv6GKUq U4v0XuqY4jFnZ1UCo6YUzgTtwiCntct+oYOjPfC7bcjzT4bSWeLswhbMa6St7+GZYWLVHxZTy9K ajVoORVAG5QlCpvV1DU65P6V1Oq4z3JrlW8/NfpoTmRQ3ecfzezzt3zTd+YTOnAqk8eWMrOy8k8 crrNeZvXWaIwNS3IVKtkpwIj8l1MolBJ5WXqh/KYfWdKzPrsEsl1hHuzr9tna0fdvh8Io017SO1 hm/eqNq0bAdZRUzFtChj4wZR9wQCzxTEKcDKoHHn4UV/fFEX/OL6bLXcrrRsBdCPBjUJSOv0C6e IihHrYu5MSW/pmJJIO2OJRDZE3WkpfJj8= X-Received: by 2002:a05:600c:4e94:b0:483:6fc6:1e20 with SMTP id 5b1f17b1804b1-483c9bc0291mr196168025e9.9.1772452996801; Mon, 02 Mar 2026 04:03:16 -0800 (PST) Received: from [192.168.1.187] ([148.63.225.166]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483bfb77466sm170851635e9.5.2026.03.02.04.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 04:03:16 -0800 (PST) Message-ID: Subject: Re: [PATCH 4/4] iio: buffer: fix timestamp alignment when quaternion in scan From: Nuno =?ISO-8859-1?Q?S=E1?= To: David Lechner , Jiri Kosina , Jonathan Cameron , Srinivas Pandruvada , Nuno =?ISO-8859-1?Q?S=E1?= , Andy Shevchenko , Lars =?ISO-8859-1?Q?M=F6llendorf?= , Lars-Peter Clausen , Greg Kroah-Hartman Cc: Jonathan Cameron , Lixu Zhang , linux-input@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 02 Mar 2026 12:04:00 +0000 In-Reply-To: <20260301-iio-fix-timestamp-alignment-v1-4-1a54980bfb90@baylibre.com> References: <20260301-iio-fix-timestamp-alignment-v1-0-1a54980bfb90@baylibre.com> <20260301-iio-fix-timestamp-alignment-v1-4-1a54980bfb90@baylibre.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Sun, 2026-03-01 at 14:24 -0600, David Lechner wrote: > Fix timestamp alignment when a scan buffer contains an element larger > than sizeof(int64_t). Currently s32 quaternions are the only such > element, and the one driver that has this (hid-sensor-rotation) has a > workaround in place already so this change does not affect it. >=20 > Previously, we assumed that the timestamp would always be 8-byte aligned > relative to the end of the scan buffer, but in the case of a scan buffer > a 16-byte quaternion vector, scan_bytes =3D=3D 32, but the timestamp need= s > to be placed at offset 16, not 24. >=20 > Signed-off-by: David Lechner > --- >=20 > To test this, I used hid-sensor-rotation minus the first patch in the > series so that we can see that the timestamp actually moved to the > correct location. >=20 > Before this patch, the timestamp (8 bytes ending with "98 18") is in the > wrong location. >=20 > 00000000=C2=A0 6a 18 00 00 ac f3 ff ff=C2=A0 83 2d 00 00 02 d3 ff ff=C2= =A0 |j........-......| > 00000010=C2=A0 00 00 00 00 00 00 00 00=C2=A0 5a 17 a0 2a 73 cb 98 18=C2= =A0 |........Z..*s...| >=20 > 00000020=C2=A0 ad 17 00 00 6a f4 ff ff=C2=A0 35 2b 00 00 ca d0 ff ff=C2= =A0 |....j...5+......| > 00000030=C2=A0 00 00 00 00 00 00 00 00=C2=A0 2a a6 bb 30 73 cb 98 18=C2= =A0 |........*..0s...| >=20 > 00000040=C2=A0 92 1e 00 00 50 ec ff ff=C2=A0 ea c1 ff ff 78 f0 ff ff=C2= =A0 |....P.......x...| > 00000050=C2=A0 00 00 00 00 00 00 00 00=C2=A0 8f 3b a7 39 77 cb 98 18=C2= =A0 |.........;.9w...| >=20 > After this patch, timestamp is now in the correct location. >=20 > 00000000=C2=A0 55 0f 00 00 dd 1f 00 00=C2=A0 af 0b 00 00 ec 3e 00 00=C2= =A0 |U............>..| > 00000010=C2=A0 c7 17 68 42 6d d0 98 18=C2=A0 00 00 00 00 00 00 00 00=C2= =A0 |..hBm...........| >=20 > 00000020=C2=A0 57 0e 00 00 c8 1f 00 00=C2=A0 d1 0e 00 00 42 3e 00 00=C2= =A0 |W...........B>..| > 00000030=C2=A0 56 a2 87 48 6d d0 98 18=C2=A0 00 00 00 00 00 00 00 00=C2= =A0 |V..Hm...........| >=20 > 00000040=C2=A0 a3 e2 ff ff d3 1b 00 00=C2=A0 0b c9 ff ff cc 20 00 00=C2= =A0 |............. ..| > 00000050=C2=A0 27 59 4d b3 72 d0 98 18=C2=A0 00 00 00 00 00 00 00 00=C2= =A0 |'YM.r...........| >=20 > I also tested this with a different driver not affected by this bug to > make sure that the timestamp is still in the correct location for all > other drivers. > --- > =C2=A0include/linux/iio/buffer.h | 12 ++++++++++-- > =C2=A01 file changed, 10 insertions(+), 2 deletions(-) >=20 > diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h > index d37f82678f71..ac19b39bdbe4 100644 > --- a/include/linux/iio/buffer.h > +++ b/include/linux/iio/buffer.h > @@ -34,8 +34,16 @@ static inline int iio_push_to_buffers_with_timestamp(s= truct iio_dev *indio_dev, > =C2=A0 void *data, int64_t timestamp) > =C2=A0{ > =C2=A0 if (ACCESS_PRIVATE(indio_dev, scan_timestamp)) { > - size_t ts_offset =3D indio_dev->scan_bytes / sizeof(int64_t) - 1; > - ((int64_t *)data)[ts_offset] =3D timestamp; > + size_t ts_offset =3D indio_dev->scan_bytes - > + ACCESS_PRIVATE(indio_dev, largest_scan_element_size); Given that we're adding a new private member, maybe we could just directly = cache the ts_offset in iio_compute_scan_bytes()? Would make the code a bit easier to follow IMH= O - Nuno S=C3=A1 >=20