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=1796382445; b=wvV/fBiivSfXdRNWl0QnuKrfAkQ0Br+mhEbzIanZeGDpSUztZgw8Be7iQx45RbZ2ZBMP JJuSRrH3AFpYmH874ietTQ1Hzui29vE8Ghv3QXfDzefkmq6PH+e/A2F0HAdteEibY1UWc bpZhDYsjZmu2lAQdF/njfn34qZaLhmLEug77TLHhyw5iTFjoTUMShdkwxL1YbHgMEegEN B7fXMQvKX8pgGEmUavUdst7FDnx9YhoWvb36lA+DXa9i1Jv5ft8pdElCK0D8yQuBNdKRa TU4j4VmScsdbc6KLllh0STJKvw/0FJMUv1R7rFdCJAQjvDN4/oAekxaQcMuP7xySZ6g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382445; 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=rNfkiHtblO+B9HPV3MjQx+OLSiz+M05I1YNiR+Wde1s=; b=5r2+NY4Rj1Po6G+FjA5j8qDycRUfpueKBukvUNazwUkDlmJd4QioNGSEoVPALrl3QnJF 0caexDdReaB4ivS+0ql35gWVQBbtpuM0UhVNBFA4mRumCL51tDRGUOsf6fTI0o5CE+EZA nf10eBVh8NLTrvv9QAEmpfzmU7TwoPp89hqCWvOLJVSBmJa6Q/qGM3+3CuCcNH1xNbavi Q/RwbtwdDeTr8vmEnxqcwFSTRV97W/OXIgpsMdnoZ+eVohtOTwssfMtOsriBDNX6gwSDo 8nyOoTuBO7966tofuTnJJTpYz9VkWvQKsADBojHxMvbzKcn+zkhoHfaa+U/8MiQhRPA== 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=109em0Gx; 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 04683606A336; Fri, 4 Dec 2026 11:07:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=109em0Gx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 745961F000C2; Fri, 4 Dec 2026 11:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382444; bh=rNfkiHtblO+B9HPV3MjQx+OLSiz+M05I1YNiR+Wde1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=109em0GxXk4haLZqUELkohk+MSKPGdMkgYUaR5c70zdpAEHOb2Y7eSZurnjeXMVMG lXeIZ5HSCYv4kXDyOp+f+5mnyv9+Eqjtypn/mwLYox+ylfvksy+iOM5SjoePLd+GGo s/GoNZwVsHslwKI8wFDONTwPgLIutGADp+rwy1h0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ziheng Wei , Guenter Roeck Subject: [PATCH 6.18 450/703] hwmon: (nct6775) Fix incorrect struct cast in beep callbacks Date: Fri, 4 Dec 2026 19:05:49 +0900 Message-ID: <20261204100639.763440712@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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;