All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 06/11] hwmon: (nct6683) Fix incorrect struct cast in show_pwm() and store_pwm()
Date: Fri, 30 Oct 2026 11:52:51 -0700	[thread overview]
Message-ID: <20261030185256.976255-7-linux@roeck-us.net> (raw)
In-Reply-To: <20261030185256.976255-1-linux@roeck-us.net>

On big-endian architectures, reading or writing the pwm[1-8] sysfs
attributes in the nct6683 hardware monitoring driver always redirects to
channel 0 due to an incorrect struct downcast in show_pwm() and
store_pwm().
The driver defines the PWM sysfs attributes using SENSOR_TEMPLATE(),
which initializes them as struct sensor_device_attribute (where the index
is a 32-bit int). However, the sysfs callbacks show_pwm() and store_pwm()
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 PWM reads to return data for channel 0, and
any writes intended to configure other channels will silently overwrite the
duty cycle of PWM channel 0 instead.

Fix the type casts in show_pwm() and store_pwm() to solve the problem.

Fixes: 41082d66bfd6 ("hwmon: Driver for NCT6683D")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/nct6683.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
index e1c36c95affb..f34cb62305be 100644
--- a/drivers/hwmon/nct6683.c
+++ b/drivers/hwmon/nct6683.c
@@ -920,7 +920,7 @@ static ssize_t
 show_pwm(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct nct6683_data *data = nct6683_update_device(dev);
-	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
+	struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
 	int index = sattr->index;
 
 	return sprintf(buf, "%d\n", data->pwm[index]);
@@ -930,7 +930,7 @@ static ssize_t
 store_pwm(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 nct6683_data *data = dev_get_drvdata(dev);
 	int index = sattr->index;
 	unsigned long val;
-- 
2.45.2


  parent reply	other threads:[~2026-10-30 18:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 18:52 [PATCH 0/11] hwmon: Various fixes Guenter Roeck
2026-10-30 18:52 ` [PATCH 01/11] hwmon: (aquacomputer_d5next) Check maxcollection when probing AQUAERO devices Guenter Roeck
2026-10-30 18:52 ` [PATCH 02/11] hwmon: (asus_wmi_sensors) Avoid global struct mutation Guenter Roeck
2026-10-30 18:52 ` [PATCH 03/11] hwmon: (hp-wmi-sensors) " Guenter Roeck
2026-10-30 18:52 ` [PATCH 04/11] hwmon: (hp-wmi-sensors) Fix unbounded loops in scale_numeric_sensor() Guenter Roeck
2026-10-30 18:52 ` [PATCH 05/11] hwmon: (lm87) Fix drvdata type confusion in vrm_show() and vrm_store() Guenter Roeck
2026-10-30 18:52 ` Guenter Roeck [this message]
2026-10-30 18:52 ` [PATCH 07/11] hwmon: (peci/dimmtemp) Fix devres leak and UAF on concurrent unbind Guenter Roeck
2026-10-30 18:52 ` [PATCH 08/11] hwmon: (pmbus/q54sj108a2) Add missing NULL pointer check Guenter Roeck
2026-10-30 18:52 ` [PATCH 09/11] hwmon: (pmbus) Check return value from pmbus_thermal_add_sensor() Guenter Roeck
2026-10-30 18:52 ` [PATCH 10/11] hwmon: (pmbus) Release devres allocated memory after devm_thermal_of_zone_register error Guenter Roeck
2026-10-30 18:52 ` [PATCH 11/11] hwmon: (pmbus) Fix return value check from thermal zone registration Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261030185256.976255-7-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=linux-hwmon@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.