mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Tzung-Bi Shih <tzungbi@kernel.org>
Cc: Jean Delvare <jdelvare@suse.com>,
	Guenter Roeck <linux@roeck-us.net>,
	 Benson Leung <bleung@chromium.org>, Lee Jones <lee@kernel.org>,
	Guenter Roeck <groeck@chromium.org>,
	 linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org,
	chrome-platform@lists.linux.dev,
	 Dustin Howett <dustin@howett.net>,
	Mario Limonciello <mario.limonciello@amd.com>,
	 Moritz Fischer <mdf@kernel.org>,
	Stephen Horvath <s.horvath@outlook.com.au>,
	 Rajas Paranjpe <paranjperajas@gmail.com>
Subject: Re: [PATCH v3 2/3] hwmon: add ChromeOS EC driver
Date: Tue, 28 May 2024 09:09:28 +0200	[thread overview]
Message-ID: <3025747e-658a-47fa-8799-86e9e974b796@t-8ch.de> (raw)
In-Reply-To: <ZlV8HWlsHfoz8QMc@google.com>

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.

  reply	other threads:[~2024-05-28  7:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27 20:58 [PATCH v3 0/3] ChromeOS Embedded controller hwmon driver Thomas Weißschuh
2024-05-27 20:58 ` [PATCH v3 1/3] platform/chrome: cros_ec_proto: Introduce cros_ec_cmd_readmem() Thomas Weißschuh
2024-05-28  6:39   ` Tzung-Bi Shih
2024-05-28  7:15     ` Thomas Weißschuh
2024-05-27 20:58 ` [PATCH v3 2/3] hwmon: add ChromeOS EC driver Thomas Weißschuh
2024-05-28  6:39   ` Tzung-Bi Shih
2024-05-28  7:09     ` Thomas Weißschuh [this message]
2024-05-28  7:30       ` Tzung-Bi Shih
2024-05-27 20:58 ` [PATCH v3 3/3] mfd: cros_ec: Register hardware monitoring subdevice Thomas Weißschuh

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=3025747e-658a-47fa-8799-86e9e974b796@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=dustin@howett.net \
    --cc=groeck@chromium.org \
    --cc=jdelvare@suse.com \
    --cc=lee@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mario.limonciello@amd.com \
    --cc=mdf@kernel.org \
    --cc=paranjperajas@gmail.com \
    --cc=s.horvath@outlook.com.au \
    --cc=tzungbi@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®