From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 BBA773921C0 for ; Wed, 25 Feb 2026 10:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772013980; cv=none; b=HlfBS+wHnRBv9CEZZcFY+dzTrvkds19W68vGnSMT21CH0r6Eagom3rwllpyoeQ4jdACe+6YzGjFE9wqxjQIDd1vni87LdqH5muB/O7kYMdlBb66jR8jAY+v0P/JwCXsfKJfW1ne3ziniUEpkMh46tHfO0jkQyILd5ft6D50l3YA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772013980; c=relaxed/simple; bh=8vSSfk/mqV/Diy8xqYAvuYstYG9PfyLi4Xga/dffatA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uT+glF1hzNhVfzurfgMCeRQ2MBOl1/ywPg6WdJ+gLMDWAFJ1Vs0Fiuxk6qy/Y5b8qpUbfenVqMHf2wmwgCeurvbetMgojYaJO+R2ODypXSctjYTErSGD3+HQJH13iVkfCetbXwwG/wpdH2Z+xcei7m6eCJf5Q2cBzApmjwlW1HE= 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=eiZ2Qc+H; arc=none smtp.client-ip=209.85.221.53 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="eiZ2Qc+H" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-43992e3f9b8so164034f8f.3 for ; Wed, 25 Feb 2026 02:06:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1772013977; x=1772618777; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oGDK1Bq0ybXWleKDcajfmOxR9UUUs8qs+hjFsjzRODo=; b=eiZ2Qc+Hq95mH64aIJgQaTtNK62ExSc60dOSc9UoxJ8BxZeg+5FErU31yIAQS0ix4c hnZCQ+cziE7xdF+VmhhnZ1wAntL/X2GJ35X8XBvGnsiDficA/6vHl5EEvLu1Wl8dVS/U yyV838N9UmyjWTxeBpOSTXcR7UUcANO0aMNd0EAlmOJYpmqiJPjMxr6RePw5x+TsknPi NGDm0vGg2AjNx36Jlwe1VinxS+7uWzFkMoH6DSTxJgR0rhCtMempr8fXmsE+i6N3det5 e5NdU7EdLZtPb4T6SrkZPPFyIp3xaUlCallrdZmHdyQEjO8HattlMQ9YBQWANyECzLyx Fheg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772013977; x=1772618777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oGDK1Bq0ybXWleKDcajfmOxR9UUUs8qs+hjFsjzRODo=; b=ZuPT1D/0cIO5WMwWlHaeNU4xPMsQgST9+Zzh1qLRPbp29lNUmmBat1Ve901b/ih9sP h4LiCnFG0rRZsyBC6HDZYTKmFy7Aqc4JTGJ9QaBtQW6XajEfVvbcSEn6TrMXW+yU6YZu mRGm7af4s+FyYuj1CNK7BGORDTB+LXvn6Sdv39h9J3iwcV86UT4UwZC/LlXphPDFh41k kxmnWxvKxuil8OYLPyc7eDq7+bvr6mpYHRjwMpGM+G4A9A4O7Acjj7HqCLIQjwpNdGz2 fR4Lldruu3DlplL5VdYgPoxMTnuF6NXpuasDqFbf8fAC6kPdQ3ZHQC2SKpgVq8Gbzeys CnTA== X-Gm-Message-State: AOJu0YwmkxHsN2Ow9K8aPie2+nLjnKolFtjmo8OSXPxzzlkYdwUaXGyX FQhpWx1JObD8cgFoXEG9LCg2ITVL9g2orV7rUEWpR5+kVDUC9I9vcayaGz4VS5hlQrlDCJbu7Jt ar64tKPQ= X-Gm-Gg: ATEYQzwBoN06PdS3/AryRzf5dGee4o6RxJf2Pm6f3JhoLYquY1QA52ZbzXSNwcH8R+f p3L9J3bUuD8vCjphUzxOpoJUPCY1eUHo2d/RyZegWF9OR5+7RsKGIBbNYIHAvPdlFThqhS8KTLe abnHHjhd0xoVddI4H4nhysIkfo67tu2WYgGMENFK8u0q7PNKphce4bl0pmmcdk1aR540BlB7nww KmR77ZJBMpn+bgIbYsBxqY/4CCazad5ZthRTVTXfeOOgTYANhNm8Sl9aWS+uFPCy7L7almpk+QB NptGqL7f6Sw7SDVXi9BMHSIkQkBy8RbeuBwGBJW7p7wXIqDNVzvxj96ND/IXGRXH+L6sWFhvJtu uMt6xq+HlpBNqyclHCQ9wU+x2URyc0+KhPIHinXV8dM2qIeiOBYmPV1LS3ZvFna1yVRK1PA== X-Received: by 2002:a05:6000:22c5:b0:439:8c42:8ab3 with SMTP id ffacd0b85a97d-4398fae1289mr2781711f8f.34.1772013976952; Wed, 25 Feb 2026 02:06:16 -0800 (PST) Received: from localhost ([151.35.220.155]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4398d568772sm6373189f8f.0.2026.02.25.02.06.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Feb 2026 02:06:16 -0800 (PST) From: Francesco Lavra To: Cc: linux-kernel@vger.kernel.org Subject: [PATCH v6 3/7] iio: imu: st_lsm6dsx: Fix check for invalid samples from FIFO Date: Wed, 25 Feb 2026 11:06:02 +0100 Message-Id: <20260225100608.2367061-3-flavra@baylibre.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260225100608.2367061-1-flavra@baylibre.com> References: <20260225100421.2366864-1-flavra@baylibre.com> <20260225100608.2367061-1-flavra@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3692; i=flavra@baylibre.com; h=from:subject; bh=8vSSfk/mqV/Diy8xqYAvuYstYG9PfyLi4Xga/dffatA=; b=owEB7QES/pANAwAKAe3xO3POlDZfAcsmYgBpnsmMfn5oXpJpDx0hpSTDM4Sw5hhySnctawLYJ Rj4y1hM/+aJAbMEAAEKAB0WIQSGV4VPlTvcox7DFObt8TtzzpQ2XwUCaZ7JjAAKCRDt8TtzzpQ2 X4YBC/oDRppR0bhWZ6092hE105YwExZsV6Kcew7p9NeMqnTqRXvIgNoqfP6Nt6V+BmUebRRWmzW n2QQ4jUiyDVzJC1ovr+gfj90w0n55clZ5AbO3V+5GkfsmOTe0BLq35h3FtKC4lbYIM1S0Z2OH4G ZT9hqDmcNFp0q7XoUFs/yyYUA77+KfuE3zDXZ2LqoHT90QAEgiKzHk5bS4NxzNsphpEwOB4rtFJ WyTLmFAkkV5mqugpXPBBdkrt97p15bAc2xhVlDfWeT/C5q1x2CRYUOM/F3O7PCGBu4pS05BOeYB RQFFKWMxxJdJqjqO+kMe6zFbYFR+rGI5lsq9g8UQinl8+bZC8a0icR/eZC2gWU4fS6sqZ4CPaKY CpMZS9vThHrnUHkpIv/+DStfKFwl6x2WpGtUf8xQc492SVuUFYX7dyjnFb8EDcov6+nscoa9qvA McW8PhtXkO0FLL0kwC1ULtvnsCewij+tlyx/qQneLGmYbgWJNwnIS2CnQsFZcpWhoP9aM= X-Developer-Key: i=flavra@baylibre.com; a=openpgp; fpr=8657854F953BDCA31EC314E6EDF13B73CE94365F Content-Transfer-Encoding: 8bit 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. To avoid casting to __le16 * when checking sample values, clean up the type representation for data read from the FIFO. Fixes: 960506ed2c69 ("iio: imu: st_lsm6dsx: enable drdy-mask if available") Signed-off-by: Francesco Lavra --- .../iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c index 5b28a3ffcc3d..a6ee2da5a06c 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -365,8 +365,6 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr, return 0; } -#define ST_LSM6DSX_IIO_BUFF_SIZE (ALIGN(ST_LSM6DSX_SAMPLE_SIZE, \ - sizeof(s64)) + sizeof(s64)) /** * st_lsm6dsx_read_fifo() - hw FIFO read routine * @hw: Pointer to instance of struct st_lsm6dsx_hw. @@ -539,14 +537,14 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) #define ST_LSM6DSX_INVALID_SAMPLE 0x7ffd static int st_lsm6dsx_push_tagged_data(struct st_lsm6dsx_hw *hw, u8 tag, - u8 *data, s64 ts) + __le16 *data, s64 ts) { - s16 val = le16_to_cpu(*(__le16 *)data); struct st_lsm6dsx_sensor *sensor; struct iio_dev *iio_dev; /* invalid sample during bootstrap phase */ - if (val >= ST_LSM6DSX_INVALID_SAMPLE) + if ((tag == ST_LSM6DSX_GYRO_TAG || tag == ST_LSM6DSX_ACC_TAG) && + (s16)le16_to_cpup(data) >= ST_LSM6DSX_INVALID_SAMPLE) return -EINVAL; /* @@ -609,7 +607,13 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) * must be passed a buffer that is aligned to 8 bytes so * as to allow insertion of a naturally aligned timestamp. */ - u8 iio_buff[ST_LSM6DSX_IIO_BUFF_SIZE] __aligned(8); + struct { + union { + __le16 data[3]; + __le32 fifo_ts; + }; + aligned_s64 timestamp; + } iio_buff = { }; u8 tag; bool reset_ts = false; int i, err, read_len; @@ -648,7 +652,7 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) for (i = 0; i < pattern_len; i += ST_LSM6DSX_TAGGED_SAMPLE_SIZE) { - memcpy(iio_buff, &hw->buff[i + ST_LSM6DSX_TAG_SIZE], + memcpy(&iio_buff, &hw->buff[i + ST_LSM6DSX_TAG_SIZE], ST_LSM6DSX_SAMPLE_SIZE); tag = hw->buff[i] >> 3; @@ -659,7 +663,7 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) * B0 = ts[7:0], B1 = ts[15:8], B2 = ts[23:16], * B3 = ts[31:24] */ - ts = le32_to_cpu(*((__le32 *)iio_buff)); + ts = le32_to_cpu(iio_buff.fifo_ts); /* * check if hw timestamp engine is going to * reset (the sensor generates an interrupt @@ -670,7 +674,8 @@ int st_lsm6dsx_read_tagged_fifo(struct st_lsm6dsx_hw *hw) reset_ts = true; ts *= hw->ts_gain; } else { - st_lsm6dsx_push_tagged_data(hw, tag, iio_buff, + st_lsm6dsx_push_tagged_data(hw, tag, + iio_buff.data, ts); } } -- 2.39.5