lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <685ce5ff-127a-4f8b-b058-d36d3adb1c0d@roeck-us.net>
Date: Sun, 26 Jan 2025 05:18:11 -0800
From: Guenter Roeck <linux@...ck-us.net>
To: Vincent Mailhol <mailhol.vincent@...adoo.fr>,
 Ming Yu <a0282524688@...il.com>
Cc: tmyu0@...oton.com, lee@...nel.org, linus.walleij@...aro.org,
 brgl@...ev.pl, andi.shyti@...nel.org, mkl@...gutronix.de,
 andrew+netdev@...n.ch, davem@...emloft.net, edumazet@...gle.com,
 kuba@...nel.org, pabeni@...hat.com, wim@...ux-watchdog.org,
 jdelvare@...e.com, alexandre.belloni@...tlin.com,
 linux-kernel@...r.kernel.org, linux-gpio@...r.kernel.org,
 linux-i2c@...r.kernel.org, linux-can@...r.kernel.org,
 netdev@...r.kernel.org, linux-watchdog@...r.kernel.org,
 linux-hwmon@...r.kernel.org, linux-rtc@...r.kernel.org,
 linux-usb@...r.kernel.org
Subject: Re: [PATCH v6 6/7] hwmon: Add Nuvoton NCT6694 HWMON support

On 1/25/25 23:42, Vincent Mailhol wrote:
> On 23/01/2025 at 18:11, Ming Yu wrote:
>> This driver supports Hardware monitor functionality for NCT6694 MFD
>> device based on USB interface.
>>
>> Signed-off-by: Ming Yu <a0282524688@...il.com>
>> ---
> 
> (...)
> 
>> +static int nct6694_temp_write(struct device *dev, u32 attr, int channel,
>> +			      long val)
>> +{
>> +	struct nct6694_hwmon_data *data = dev_get_drvdata(dev);
>> +	struct nct6694_cmd_header cmd_hd;
>> +	unsigned char temp_hyst;
>> +	signed char temp_max;
>> +	int ret;
>> +
>> +	guard(mutex)(&data->lock);
>> +
>> +	switch (attr) {
>> +	case hwmon_temp_enable:
>> +		if (val == 0)
>> +			data->hwmon_en.tin_en[channel / 8] &= ~BIT(channel % 8);
>> +		else if (val == 1)
>> +			data->hwmon_en.tin_en[channel / 8] |= BIT(channel % 8);
>> +		else
>> +			return -EINVAL;
>> +
>> +		cmd_hd = (struct nct6694_cmd_header) {
>> +			.mod = NCT6694_HWMON_MOD,
>> +			.cmd = NCT6694_HWMON_CONTROL,
>> +			.sel = NCT6694_HWMON_CONTROL_SEL,
>> +			.len = cpu_to_le16(sizeof(data->hwmon_en))
>> +		};
>> +
>> +		return nct6694_write_msg(data->nct6694, &cmd_hd,
>> +					 &data->hwmon_en);
>> +	case hwmon_temp_max:
>> +		cmd_hd = (struct nct6694_cmd_header) {
>> +			.mod = NCT6694_HWMON_MOD,
>> +			.cmd = NCT6694_HWMON_ALARM,
>> +			.sel = NCT6694_HWMON_ALARM_SEL,
>> +			.len = cpu_to_le16(sizeof(data->msg->hwmon_alarm))
>> +		};
>> +		ret = nct6694_read_msg(data->nct6694, &cmd_hd,
>> +				       &data->msg->hwmon_alarm);
>> +		if (ret)
>> +			return ret;
>> +
>> +		val = clamp_val(val, -127000, 127000);
>> +		data->msg->hwmon_alarm.tin_cfg[channel].hl = temp_to_reg(val);
>> +
>> +		return nct6694_write_msg(data->nct6694, &cmd_hd,
>> +					 &data->msg->hwmon_alarm);
>> +	case hwmon_temp_max_hyst:
>> +		cmd_hd = (struct nct6694_cmd_header) {
>> +			.mod = NCT6694_HWMON_MOD,
>> +			.cmd = NCT6694_HWMON_ALARM,
>> +			.sel = NCT6694_HWMON_ALARM_SEL,
>> +			.len = cpu_to_le16(sizeof(data->msg->hwmon_alarm))
>> +		};
>> +		ret = nct6694_read_msg(data->nct6694, &cmd_hd,
>> +				       &data->msg->hwmon_alarm);
>> +
>> +		val = clamp_val(val, -127000, 127000);
>> +		temp_max = data->msg->hwmon_alarm.tin_cfg[channel].hl;
>> +		temp_hyst = temp_max - temp_to_reg(val);
>> +		temp_hyst = clamp_val(temp_hyst, 0, 7);
> 
> temp_hyst is unsigned. It can not be smaller than zero. No need for
> clamp(), using min here is sufficient.
> 

Wrong conclusion. It needs to be declared as signed variable because
"temp_max - temp_to_reg(val)" could be negative.

Guenter


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ