From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796383848; b=4GTmXl6SZP5zBzZ6d52XzInrCWn9E31ZvgCDLULLaaGOMCIocCd8sHnHOQ7PNJui0Jc5 EzWB406J3btDJlXtHQzQIHFC8t28dFFSGCpfiSql6fE1bay3TAGYoALTpsU4p1AVu665L oaNgRfxA/SVdNhOdbyw2jUicswWxRToRHz73iVOVFQRDCnfbEeSZj/2KMEPkCv3u/9Pca Eu22tZJRH+gJaSEPeorX6NYww51VY702aWCEtLrOQE022RxhQNH07aMPwwA2/WSnVxjmc QP7sG7Wk/I90AMcbzH38iKhHux03ITZRvlTDt8whhvTVwqgmhhg53rf5mOp/09QPFGA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383848; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=sOlZn1glLWPmwo45UCf7hOOuccr/gqfeCUaZaJwimL4=; b=2PIE67PrjXM8YBFPsNkxg49ZjVg7rxY/tELLVNYU+oNLQWQv1q2WDMmqO0g7ShBQxo3W DI+cS2U2W3HWEQCs+n3jQ7fJJFWMm7dWww1DmbYD4kP9c4f8HxcRpTeL2+yX0WfImNycF +J3jAWOj7s3QnwOm2LGx339qfHakv8ADTjnQmb5H0K0bQRzTHjZwqRlv81Zobn7n3IiWa Mf9iuQTXstT6FewCKRtyeE24cqjFmoRyGH4zza155bRYYpkVURWOazN6pUiKPXcDrYiAh WaT4lWfZbtf5/2GHQyCRZo0lWB+O3M6D6hOkZGc3qwAm/4mYAKLooKAMwbChraEtsgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fb7JVkBX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06C74606A322; Fri, 4 Dec 2026 11:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fb7JVkBX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F6C61F000C2; Fri, 4 Dec 2026 11:30:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383847; bh=sOlZn1glLWPmwo45UCf7hOOuccr/gqfeCUaZaJwimL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fb7JVkBXkysf+5B8a+suUzMn1x/P9T9hJeBAnaMyG6cOjFSKxiQNcZhMbfoxZA4Om HNHT5yRAwXwy5TMbrB4RaA0cOG+UOT79Z9Pc1zSUwv5RMC/6UTrpVFLk4MZpiH7BdY OVGGHha4FsMhEqXxK4smBM/faMCMMXnD3sC62FYY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ziheng Wei , Guenter Roeck Subject: [PATCH 6.12 393/555] hwmon: (nct6775) Fix incorrect struct cast in beep callbacks Date: Fri, 4 Dec 2026 19:07:16 +0900 Message-ID: <20261204100624.658388189@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ziheng Wei commit 07571b42cf41d0e42fb890713340a8f0a3c03d56 upstream. On big-endian architectures, writing the in[1-*]_beep, fan[1-*]_beep and temp[1-*]_beep sysfs attributes in the nct6775 hardware monitoring driver always changes channel 0 due to an incorrect struct downcast in the beep store callbacks. The driver defines these sysfs attributes using SENSOR_TEMPLATE(), which initializes them as struct sensor_device_attribute (where the index is a 32-bit int). However, the sysfs store callbacks nct6775_store_beep() and store_temp_beep() incorrectly downcast the attribute to a struct sensor_device_attribute_2 (where the index is an 8-bit u8). Because both structs start with struct device_attribute, container_of() resolves to the same base address. On big-endian architectures, reading the 8-bit index field from the memory layout of a 32-bit int fetches the most significant byte (which is 0), rather than the intended channel number. This type mismatch causes all beep writes to change the beep setting of channel 0, regardless of which channel the user targeted. Fix the type casts in the two store callbacks. Not runtime-tested: the only big-endian machine available to me (s390x under QEMU) cannot build the platform driver (no HAS_IOPORT). Fixes: 30846993047b ("hwmon: (nct6775) Add support for beep attributes") Cc: stable@vger.kernel.org Signed-off-by: Ziheng Wei Link: https://patch.msgid.link/20261115080203.910033-2-zihengw03@163.com Signed-off-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman --- drivers/hwmon/nct6775-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/hwmon/nct6775-core.c +++ b/drivers/hwmon/nct6775-core.c @@ -1819,7 +1819,7 @@ EXPORT_SYMBOL_GPL(nct6775_show_beep); ssize_t nct6775_store_beep(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); struct nct6775_data *data = dev_get_drvdata(dev); int nr = data->BEEP_BITS[sattr->index]; int regindex = nr >> 3; @@ -1873,7 +1873,7 @@ static ssize_t store_temp_beep(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); struct nct6775_data *data = dev_get_drvdata(dev); int nr, bit, regindex; unsigned long val;