From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.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 EE245202997 for ; Sat, 2 May 2026 02:08:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777687738; cv=none; b=HQR9Ly4/fHbrsUuKRAWaLCUau9h/4wq5iekdn8BIaQBH5HVc7RMaVrzaDVH2dNgHmV25S+jTr0lkX5c9Cpvz0k1GQ5SoJnRbh4SZSHEkUOsLuXqCIQKM9/JaXrMNjkrBRg4d97FNHD/PHA+dOuQ62zgtHYPliqjkbqO79/VhQ94= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777687738; c=relaxed/simple; bh=Vj0a9qduxlNCPp1ydSPehmSf382ohEVT4KqXWYvxNPk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CfEILsFoiYlsujwTT6WOYL9UhHnB5D6ROpimAkKU+W4fwzX9PAC+GyPEfu9i4FkEWn4kuCjGOpaEEQP8hU2MpkAHzBqpP6cTAEQfJMzrYCRn79zOpYiDrdfOufOSZSPh5b3WMouhx34Pwo7BgGPBc9XB8O0XLT3wdIHFXXmINTQ= 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=jvtyKGH2; arc=none smtp.client-ip=209.85.216.53 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="jvtyKGH2" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-35dac556bb2so1937984a91.1 for ; Fri, 01 May 2026 19:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777687736; x=1778292536; 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=lvktrsPRQjbid/M7vQVO3VIEYHof7fHHQw2CFy4zVhM=; b=jvtyKGH2gKoU0npHz5JbaMwFXIRxb6894Oa1avO0QFl8y7SMZbl6pCsZHLWPzNUEoz F6evvb7s+UE4lRWKoDxoQbbQhSGc9143vcEDjCPftT/muwS/EMKXtrPqJDKXQibbSUOU IHP/+GGPxRFqQ1gyXZ6FUTO74YBtpmyrWQ4aV+ZbzEc9B3DsoUzGWoWjfe45h/bmT291 tus/kLfpJAE1LIoWbe+4Q7tjdVcrhbLx1iWg4P7nUld8L5GBnPghL26v60Msq3mGhU6l o5q60xQ+L5RfZC6eu1zfw39w545Yhek8v86pW08ho8TEnd8maaFP7IZY1aimYO7zJhHG yOZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777687736; x=1778292536; 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=lvktrsPRQjbid/M7vQVO3VIEYHof7fHHQw2CFy4zVhM=; b=X5vaUl2S3VvzFIFcjNrytabZtdVjZiSZzAMbg0DKzpB+s8kOeZnkVQDtIaYBYuSJBh zaSJakrL7hJL4Zd532+fNhFtxSQ+Se1a0UoGSI4hhR7vKWtHsdueIH6R5k4RGkY7nGux 4zdW9Qi6mRI7HaQcOX+oQnVd5r7ZNMMDyXM50Zmb5kS0TThPrWvvYf3XvvfJTQrVcTYK H2yxIe4XCNtXlHD8VYYepPJ80ylsfJA5S6ZwEh+NjMoP3QTh8nhtWka6XTOGrq5TPNzR OPwCdHGSxN+nbIwvCv7XkiNLfKTcOkKZ1owHpGGo5VQPqGq9U5DFoalnwl63sAI5Ud4j /ABg== X-Forwarded-Encrypted: i=1; AFNElJ8nu9N2VwLaJXoI7rLD4XodxYeHdFz6WBL5/2WCUSSWZxduVgTm5Dk13EPNj6+tvKJJ7hePSmuYccx3w0w=@vger.kernel.org X-Gm-Message-State: AOJu0YyIvZ6zEukRjwHACyCp0uwewwM7/rHHDh9UyogurtgL21f1/eyH b8sUrFenJJrmgSUXNy2YVoxTlx0vb0/Gw5eHSqQlk3LJ9hNJYc34YZZg X-Gm-Gg: AeBDievHZJgwt0n5O6dsLUC0jRDCEMXUCXIvMhJRtTyfN0PSsonUUpb/Eigt9ijssbU P+jNu8r7rdwrV9SFgQsNYqr2NzGfvXoVIrtE/kv567xUdHa/FwtO/UwY16AJ1oZAF8LWmWNzN31 SSS/twtI/UG7YS8JmfdOHClH38XaRebiQ9NclQFVx6KbqQhnCHYNYnUyBNuFlf9lSxwRNAQamTn bg5cZU8v8RXaMx4f1EjHAM9U/jJ/qTKfPMD0xOna1E4zaFyMDKY7lknT65hPcDOntuQ5VEK42mn 24CtVaIK0T7Ijvlg3o3ie4aJKM8V6v8PCrM0PF2hilNyDmRMN8A3StcjpKNoFuQBpfLSq1nAOiA MhoY7G/JB/dI6JlbhmUVI7rJ3Qx4mmtZk5SUYGsNSN3lby8aDRBgRfXY5eDPTTjETQCsTBCkQPJ DpVvj106Q4kT4n+HiWql+ow0F5GAtdlOyBOGUZ3CULU9sTLJaiPyqo/BMCbobEUtROMIFoLfW0P Y7wjg== X-Received: by 2002:a17:902:9889:b0:2b4:5309:2c14 with SMTP id d9443c01a7336-2b9f260b785mr10116985ad.31.1777687736219; Fri, 01 May 2026 19:08:56 -0700 (PDT) Received: from tabrez-VivoBook-ASUSLaptop-X513UA-KM513UA.. ([116.72.73.183]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b9cae39e91sm34519135ad.56.2026.05.01.19.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 May 2026 19:08:55 -0700 (PDT) From: Tabrez Ahmed To: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux@roeck-us.net, david.laight.linux@gmail.com, me@brighamcampbell.com, shuah@kernel.org, Tabrez Ahmed , Sashiko Subject: [PATCH v6 1/3] hwmon: (ads7871) Fix endianness bug in 16-bit register reads Date: Sat, 2 May 2026 07:38:42 +0530 Message-ID: <20260502020844.110038-2-tabreztalks@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260502020844.110038-1-tabreztalks@gmail.com> References: <20260502020844.110038-1-tabreztalks@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The ads7871_read_reg16() function relies on spi_w8r16() to read the 16-bit sensor output. The ADS7871 device transmits the Least Significant Byte (LSB) first. On Little-Endian architectures, spi_w8r16() correctly reconstructs the 16-bit value. However, on Big-Endian architectures, the byte swapping causes the first received byte (LSB) to be placed in the most significant byte of the u16, resulting in corrupted voltage readings. To fix this, cast the integer result of spi_w8r16() to a restricted __le16 type and convert it to the host CPU's native byte order using le16_to_cpu(). Negative error codes returned by the SPI core are caught and returned prior to the conversion to avoid mangling the error status. Reported-by: Sashiko Closes: https://sashiko.dev/#/patchset/20260418034601.90226-1-tabreztalks@gmail.com Suggested-by: David Laight Signed-off-by: Tabrez Ahmed --- drivers/hwmon/ads7871.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ads7871.c b/drivers/hwmon/ads7871.c index 9bfdf9e6bcd77..52584bb77ffb7 100644 --- a/drivers/hwmon/ads7871.c +++ b/drivers/hwmon/ads7871.c @@ -61,7 +61,6 @@ #include #define DEVICE_NAME "ads7871" - struct ads7871_data { struct spi_device *spi; }; @@ -77,9 +76,13 @@ static int ads7871_read_reg8(struct spi_device *spi, int reg) static int ads7871_read_reg16(struct spi_device *spi, int reg) { int ret; + reg = reg | INST_READ_BM | INST_16BIT_BM; ret = spi_w8r16(spi, reg); - return ret; + if (ret < 0) + return ret; + + return le16_to_cpu((__force __le16)ret); } static int ads7871_write_reg8(struct spi_device *spi, int reg, u8 val) -- 2.43.0