Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "^[$Bhq^[(B ^[$By~W3^[(B" <Spector.Tsai@outlook.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [RFC PATCH] hwmon: (nct6775) Ignore 0xffff TSI temperature readings
Date: Mon, 24 Aug 2026 18:57:48 +0000	[thread overview]
Message-ID: <20260824185749.627B81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260824184443.81887-1-Spector.Tsai@outlook.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the `tsi_temp` array is incorrectly declared as `s16` (signed) instead of `u16`. As a result, when an active TSI channel returns `0xffff` dynamically at runtime, the value is stored as a negative number (`-1`). When passed to `show_tsi_temp()` and then to `tsi_temp_from_reg(unsigned int reg)`, it is sign-extended to a 32-bit integer (`0xffffffff`). The function then performs a logical right shift (`reg >> 5`), corrupting the value and yielding a bogus reading of 3892313987 millidegrees Celsius. While the patch hides `0xffff` at probe time, it leaves the root cause (the `s16` array type) unfixed, allowing the bug to trigger during runtime updates.
--

--- Patch [1]: [RFC PATCH] hwmon: (nct6775) Ignore 0xffff TSI temperature readings ---
commit 4af5e21bfe7d5aa83ca756cf26ad0f2043522f36
Author: Spector Tsai <Spector.Tsai@outlook.com>

hwmon: (nct6775) Ignore 0xffff TSI temperature readings

This patch updates the probe path to treat 0xffff as an inactive TSI channel.
It aims to prevent unused TSI channels from being exposed and reporting bogus
temperature readings of 3892313987 millidegrees Celsius.

> diff --git a/drivers/hwmon/nct6775-core.c b/drivers/hwmon/nct6775-core.c
> index 759ea3d1286e3..34e6a01aa4e49 100644
> --- a/drivers/hwmon/nct6775-core.c
> +++ b/drivers/hwmon/nct6775-core.c
> @@ -4339,7 +4339,7 @@ int nct6775_probe(struct device *dev, struct nct6775_data *data,
>  		err = nct6775_read_value(data, data->REG_TSI_TEMP[i], &tmp);
>  		if (err)
>  			return err;
> -		if (tmp)
> +		if (tmp && tmp != 0xffff)

[Severity: High]
This isn't a bug introduced by this patch, but does this fully resolve the
bogus reading issue if an active channel returns 0xffff dynamically at
runtime?

Looking at drivers/hwmon/nct6775.h, the tsi_temp array is declared as s16:

struct nct6775_data {
    ...
    s16 tsi_temp[NUM_TSI_TEMP];
    ...
}

In nct6775_update_device(), when reading a TSI channel that temporarily
returns 0xffff, this 16-bit value is stored into the s16 array as -1.

When the temperature is exported to sysfs:

drivers/hwmon/nct6775-core.c:show_tsi_temp() {
    ...
    return sysfs_emit(buf, "%u\n",
                      tsi_temp_from_reg(data->tsi_temp[sattr->index]));
}

The s16 value is passed to tsi_temp_from_reg() which takes an unsigned int:

drivers/hwmon/nct6775-core.c:tsi_temp_from_reg() {
    return (reg >> 5) * 125;
}

The -1 is implicitly cast to an unsigned int (0xffffffff), and the logical
right shift yields the 3892313987 millidegrees Celsius bogus reading. If
userspace thermal managers observe this massive value during runtime updates,
could it trigger an unwarranted emergency system shutdown?

Would changing the tsi_temp array type to u16 prevent this sign-extension
issue entirely?

>  			data->have_tsi_temp |= BIT(i);
>  	}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824184443.81887-1-Spector.Tsai@outlook.com?part=1

  reply	other threads:[~2026-08-24 18:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 18:44 [RFC PATCH] hwmon: (nct6775) Ignore 0xffff TSI temperature readings 蔡 紱彝
2026-08-24 18:57 ` sashiko-bot [this message]
2026-08-28 15:50 ` 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=20260824185749.627B81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Spector.Tsai@outlook.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox