Re: [PATCH 1/3] hwmon: (nct6775) Fix incorrect struct cast in beep callbacks

From: Guenter Roeck

Date: Sun Nov 15 2026 - 08:35:24 EST


On Sun, Nov 15, 2026 at 04:02:01PM +0800, Ziheng Wei wrote:
> 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@xxxxxxxxxxxxxxx
> Signed-off-by: Ziheng Wei <zihengw03@xxxxxxx>

Applied.

Thanks,
Guenter