From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.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 2037C45BD4A for ; Wed, 21 Jan 2026 14:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769004361; cv=none; b=ikjK2D7iR4BrTrD5uHTV4/u+sf/5+ZDj+EHFr2JDdNjSIG9b7vdNJDXd9fjmDLKsd4ZuObSTRTA46wjqZjvzORC3sy45n0WfUqLOlG+bqmvRy5N6aRFVxh4cp4eAi2A6DpJn7D25s1kuSCZ4F7bLJl0/iReQo22VvY4w5+V47t8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769004361; c=relaxed/simple; bh=U6AfKx4a56pbE/bWX0xpp6yHrDtNa+tDYA8lqH/H8go=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=TNFtXqQ95lH87429jtUhkcWM3WxFgWDdtjv4dt4T8gEr7/gw/vaOUna2CFoufb9Ux6MurqZh232meCYB0sjyGBmgZQwtSXp60O6Mt9iAyswDY6c6/7qmbggh9xPvT0N3RghPOz+Jb41YQxEbyREtvb5jjizd+0NPEpIdZWzQX00= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=IkzwRbCC; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="IkzwRbCC" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-42fb0fc5aa9so3811666f8f.1 for ; Wed, 21 Jan 2026 06:05:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1769004357; x=1769609157; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:organization :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to; bh=U6AfKx4a56pbE/bWX0xpp6yHrDtNa+tDYA8lqH/H8go=; b=IkzwRbCCRFweekzIyaX7xeVfGBnALgRtAYW9wSQfRtOz81X/57uZmEYVfQTK55nohP KnEWvUIgbAPdwpHcrWemcDNmEu3cn/Gdb/2lQY3m+Jk9pWdajZlP1w00lfox2hWJZu6R TDoCBii/BPdSasfjBdFLGgtPjv/+D/5UQPABt/mXILQfo6USyfJQEHx7WO0hUTKNLlHb P6Mxym0hvDg6pfpQEBXIS+e9caIIVbh9Z4TOYRB88lr/g1gNTeW+21+gJiGQlomSWIxB odmm7pzeijPO7F0IXGTr6T05N6BAcfnQTrVxJX4eBgN2oaDnIvVKJTt7SJRiQk+7Cjoi XqmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769004357; x=1769609157; h=mime-version:user-agent:content-transfer-encoding:organization :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=U6AfKx4a56pbE/bWX0xpp6yHrDtNa+tDYA8lqH/H8go=; b=w6hOgJCr25n57X2Kb3MJPdpQ0e1wF9yBVOc0LQOXtrHY7jiOdqpi3w50pC2fwgJepD nT6ZRBv7Z8LwLCTfQ69J5dvyrKYZ/W2QGzwAix4fDV7rdsZQFetuDztKcYZDZjiRfWn9 AgRTgFQ5dZ1cIU+GkWMqXfv67AYUOR2ieA80Y2Xfqq6Wv6iHhXwchHY5ZE3H4BmgyPWp Or4xLn5/c0bkKATNAyhLbiQFx8G3FRGLDqcRETUSpxhH6kYrBwn1XqzOIpoQaRkmzhkG WPsLbRm4S15VsJT0+IwZES8nnEVajGhqmX3p/sb85lRjAX9nLPpvOpcJb6KcwZaCffrQ byFQ== X-Forwarded-Encrypted: i=1; AJvYcCVvcZguqywXt0qvoLKc80mrK2F5YbHPZXyOEkvDTND10VIm+cu7hnL6aKooIvR2JEKKSjakBj4nWtOJYjo=@vger.kernel.org X-Gm-Message-State: AOJu0YzcKXBeKdkKmuSxyTDfKoEk0qSm2RKmo9IDXfch38bGmia13Lav tXRKYpOg8n/FDG1DqC2Y+1TCwd4wXPjabA9zQ/Q+2+B4HoIYRMj9VhIM/Rfhw7UXHHU= X-Gm-Gg: AZuq6aLq1It8nSMbcZJdxr2jLhqUZTn2hdsxRD7BIkqxOmZy9OsSjjr1hfuJMVgllT6 OuSYRdJpOG6xofKHL7qDobdo+B6glxAJ/t6bheH5NBZoOBgmXxuIt11+UfbJeebJkUrrs8NYv6R haCvynGjoReq3OqL5d2aPhfUFGFNVJSiMpLnfg/l+v08+WI2gKn1ESfjOZdbZK85nfpO0dYZ9+n rYlQmRhr5TAg6hR6Ne+sMQeI22ePdTlIdcCn1hYKXTv65cwLiHfkmaMPGF3x0wNpliA7NzewOIr FaworNoJ4BLkMlYt9erMuTufeQMXz7/mYFb3IAg/XhWya2+nuyrqnm2KIiVJp92N9MExMEt1hlh 8PhjXrkObQn0+pLYwnqlaqlc/Kihlkk96em80KP08dFVuYv8JQpOkReVMiV6Yajwmhkg= X-Received: by 2002:a05:6000:2089:b0:435:9ef7:5c3c with SMTP id ffacd0b85a97d-4359ef76526mr3574067f8f.25.1769004357420; Wed, 21 Jan 2026 06:05:57 -0800 (PST) Received: from [10.203.83.9] ([151.35.203.18]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4358f12ee69sm13731631f8f.11.2026.01.21.06.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jan 2026 06:05:57 -0800 (PST) Message-ID: <0168c543e320aeacbbdcdd7f4f3bb0edb81b79f4.camel@baylibre.com> Subject: Re: [PATCH] iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO From: Francesco Lavra To: Andy Shevchenko Cc: Lorenzo Bianconi , Jonathan Cameron , David Lechner , Nuno =?ISO-8859-1?Q?S=E1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 21 Jan 2026 15:05:54 +0100 In-Reply-To: References: <20260121112758.1831077-1-flavra@baylibre.com> <20260121112758.1831077-4-flavra@baylibre.com> Organization: BayLibre Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Wed, 2026-01-21 at 14:47 +0200, Andy Shevchenko wrote: > On Wed, Jan 21, 2026 at 12:27:57PM +0100, Francesco Lavra wrote: > > The DRDY_MASK feature implemented in sensor chips marks gyroscope and > > accelerometer invalid samples (i.e. samples that have been acquired > > during > > the settling time of sensor filters) with the special values 0x7FFFh, > > 0x7FFE, and 0x7FFD. > > The driver checks FIFO samples against these special values in order to > > discard invalid samples; however, it does the check regardless of the > > type > > of samples being processed, whereas this feature is specific to > > gyroscope > > and accelerometer data. This could cause valid samples to be discarded. > > Fix the above check so that it takes into account the type of samples > > being > > processed. >=20 > ... >=20 > > =C2=A0st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag, > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 u8 *data, s64 ts) > > =C2=A0{ > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0s16 val =3D le16_to_cpu(*(__= le16 *)data); > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct st_lsm6dsx_senso= r *sensor; > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0struct iio_dev *iio_dev= ; > > =C2=A0 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0/* invalid sample durin= g bootstrap phase */ > > -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if (val >=3D ST_LSM6DSX_INVA= LID_SAMPLE) > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0if ((tag =3D=3D ST_LSM6DSX_G= YRO_TAG || tag =3D=3D ST_LSM6DSX_ACC_TAG) > > && > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (s16)le16= _to_cpup((__le16 *)data) >=3D > > ST_LSM6DSX_INVALID_SAMPLE) >=20 > Since data is u8 *, it might appear on unaligned addresses and the proper > conversion here is to use get_unaligned_le16() without any of those ugly > castings. data here corresponds to iio_buff in st_lsm6dsx_read_tagged_fifo(), which is declared as __aligned(8), so it cannot appear on unaligned addresses. > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0return -EINVAL; >=20