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] [thread-next>] [day] [month] [year] [list]
Date: Tue, 28 May 2024 09:09:28 +0200
From: Thomas Weißschuh <linux@...ssschuh.net>
To: Tzung-Bi Shih <tzungbi@...nel.org>
Cc: Jean Delvare <jdelvare@...e.com>, Guenter Roeck <linux@...ck-us.net>, 
	Benson Leung <bleung@...omium.org>, Lee Jones <lee@...nel.org>, Guenter Roeck <groeck@...omium.org>, 
	linux-kernel@...r.kernel.org, linux-hwmon@...r.kernel.org, chrome-platform@...ts.linux.dev, 
	Dustin Howett <dustin@...ett.net>, Mario Limonciello <mario.limonciello@....com>, 
	Moritz Fischer <mdf@...nel.org>, Stephen Horvath <s.horvath@...look.com.au>, 
	Rajas Paranjpe <paranjperajas@...il.com>
Subject: Re: [PATCH v3 2/3] hwmon: add ChromeOS EC driver

On 2024-05-28 06:39:25+0000, Tzung-Bi Shih wrote:
> On Mon, May 27, 2024 at 10:58:32PM +0200, Thomas Weißschuh wrote:
> > diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
> [...]
> > + *  ChromesOS EC driver for hwmon
> 
> s/ChromesOS/ChromeOS/.

Ack. Copy-and-paste...

> > +struct cros_ec_hwmon_priv {
> > +	struct cros_ec_device *cros_ec;
> > +	const char *temp_sensor_names[EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES];
> > +	u8 usable_fans;
> > +};
> > +
> > +static int cros_ec_hwmon_read_fan_speed(struct cros_ec_device *cros_ec, u8 index, u16 *speed)
> > +{
> > +	u16 data;
> > +	int ret;
> > +
> > +	ret = cros_ec_cmd_readmem(cros_ec, EC_MEMMAP_FAN + index * 2, 2, &data);
> > +	if (ret < 0)
> > +		return ret;
> > +
> > +	data = le16_to_cpu(data);
> > +	*speed = data;
> > +
> > +	if (data == EC_FAN_SPEED_NOT_PRESENT || data == EC_FAN_SPEED_STALLED)
> > +		return -EIO;
> 
> `data` could be eliminated; use `*speed` instead.

Then the le16 value would need to be written directly to the out
parameter. The current usage relies on *speed (sometimes) being set even
if ret != 0.

(See next response block)

> 
> > +static int cros_ec_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
> > +			      u32 attr, int channel, long *val)
> > +{
> [...]
> > +	u16 speed = 0;
> > +	u8 temp = 0;
> 
> They don't need to initialize.

They need to.

The logic

if (ret == -EIO && speed == EC_FAN_SPEED_STALLED)
	ret = 0;

relies on -EIO and a write to speed from cros_ec_hwmon_read_fan_speed().

But if cros_ec_cmd_readmem() already returns -EIO, then speed would be
uninitialized.

I'll see if I can make this clearer somehow.

> 
> > +	if (type == hwmon_fan && attr == hwmon_fan_input) {
> > +		ret = cros_ec_hwmon_read_fan_speed(priv->cros_ec, channel, &speed);
> > +		if (ret == 0)
> > +			*val = speed;
> > +	} else if (type == hwmon_fan && attr == hwmon_fan_fault) {
> > +		ret = cros_ec_hwmon_read_fan_speed(priv->cros_ec, channel, &speed);
> > +		if (ret == -EIO && speed == EC_FAN_SPEED_STALLED)
> > +			ret = 0;
> > +		if (ret == 0)
> > +			*val = speed == EC_FAN_SPEED_STALLED;
> > +	} else if (type == hwmon_temp && attr == hwmon_temp_input) {
> > +		ret = cros_ec_hwmon_read_temp(priv->cros_ec, channel, &temp);
> > +		if (ret == 0)
> > +			*val = kelvin_to_millicelsius((((long)temp) + EC_TEMP_SENSOR_OFFSET));
> > +	} else if (type == hwmon_temp && attr == hwmon_temp_fault) {
> > +		ret = cros_ec_hwmon_read_temp(priv->cros_ec, channel, &temp);
> > +		if (ret == -EIO && speed == EC_TEMP_SENSOR_ERROR)
> > +			ret = 0;
> > +		if (ret == 0)
> > +			*val = temp == EC_TEMP_SENSOR_ERROR;
> > +	}
> 
> Refactoring them by switch .. case .. may improve the readability.

It would introduce another level of indentation, which I tried to avoid.
But some vertical whitespace would be useful indeed.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ