All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Benedikt Niedermayr" <benedikt.niedermayr@siemens.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH 1/1] hwmon: simatic-ipc-ec-sensors: add BX-54A EC driver
Date: Mon, 16 Nov 2026 16:50:46 +0000	[thread overview]
Message-ID: <sashiko-outbox-217386@kernel.org> (raw)
In-Reply-To: <20261116163257.1303207-2-benedikt.niedermayr@siemens.com>

Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] hwmon: simatic-ipc-ec-sensors: temp limits exposed as *_alarm
  attributes
- [High] hwmon: pointer-sign mismatch passing s8 * to ec_read() in temp
  read callback
- [Medium] hwmon: premature s8 cast before clamp() in
  simatic_ipc_ec_temp_write()
- [Medium] hwmon: u8 truncation in simatic_ipc_ec_fan_write() bypasses
  range check
- [Medium] hwmon: uninitialized reads on ec_read() error in temp and fan
  read callbacks
- [Medium] hwmon: devm buffer stored in global struct in
  simatic_ipc_ec_hwmon_probe()
- [Low] hwmon: unsanitized and unlowercased chip_name in
  simatic_ipc_ec_fan_probe()
- [Low] hwmon: simatic-ipc-ec-sensors: missing Documentation/hwmon/
  driver doc
--

commit 830c0088242b1976cce59ca2195a3aaabae749d2
Author: Benedikt Niedermayr <benedikt.niedermayr@siemens.com>

hwmon: simatic-ipc-ec-sensors: add BX-54A EC driver

This commit adds a hardware monitoring driver for temperature sensors and
fan control on the embedded controller of Siemens SIMATIC IPC BX-54A
systems.

> diff --git a/MAINTAINERS b/MAINTAINERS
> index ccbcdc0799b9f..8e567b60f6487 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -25763,6 +25763,12 @@ F:	drivers/media/mmc/siano/
>  F:	drivers/media/usb/siano/
>  F:	drivers/media/usb/siano/
>  
> +SIEMENS IPC EC SENSORS DRIVER
> +M:	Benedikt Niedermayr <benedikt.niedermayr@siemens.com>
> +L:	linux-hwmon@vger.kernel.org
> +S:	Maintained
> +F:	drivers/hwmon/simatic-ipc-ec-sensors.c

[Severity: Low]
New hwmon drivers require a documentation file under
Documentation/hwmon/simatic-ipc-ec-sensors.rst per
Documentation/hwmon/submitting-patches.rst.

[ ... ]

> diff --git a/drivers/hwmon/simatic-ipc-ec-sensors.c b/drivers/hwmon/simatic-ipc-ec-sensors.c
> new file mode 100644
> index 0000000000000..690da5dde2bf8
> --- /dev/null
> +++ b/drivers/hwmon/simatic-ipc-ec-sensors.c
> @@ -0,0 +1,568 @@

[ ... ]

> +static umode_t simatic_ipc_ec_temp_is_visible(const struct simatic_ipc_ec_temp *temp,
> +					      u32 attr, int channel)
> +{
> +	switch (attr) {
> +	case hwmon_temp_input:
> +		return 0444;
> +	case hwmon_temp_max_alarm:
> +	case hwmon_temp_min_alarm:
> +	case hwmon_temp_crit:
> +		return 0644;
> +	default:
> +		break;
> +	}
> +
> +	return 0;
> +}
> +
> +static int simatic_ipc_ec_temp_read(const struct simatic_ipc_ec_temp *temp, u32 attr,
> +				    int channel, long *val)
> +{
> +	s8 value;
> +	int ret;
> +	u8 reg;
> +
> +	switch (attr) {
> +	case hwmon_temp_input:
> +		reg = temp_reg(temp->base, channel, TEMP_REG_VALUE);
> +		break;
> +	case hwmon_temp_max_alarm:
> +		reg = temp_reg(temp->base, channel, TEMP_REG_ALARM_HIGHLIMIT);
> +		break;
> +	case hwmon_temp_min_alarm:
> +		reg = temp_reg(temp->base, channel, TEMP_REG_ALARM_LOWLIMIT);
> +		break;
> +	case hwmon_temp_crit:
> +		reg = temp_reg(temp->base, channel, TEMP_REG_CRITICAL);
> +		break;
> +	default:
> +		return -EOPNOTSUPP;
> +	}

[Severity: High]
Should the low and high temperature thresholds use hwmon_temp_min and
hwmon_temp_max (with HWMON_T_MIN and HWMON_T_MAX in
simatic_ipc_ec_hwmon_probe()) instead of hwmon_temp_min_alarm and
hwmon_temp_max_alarm?

Under the hwmon ABI, tempX_min_alarm and tempX_max_alarm are read-only
boolean flags (0 or 1), so exposing writable millidegree Celsius limits
there causes tools like libsensors to treat any non-zero limit as an
active alarm while missing the min and max thresholds.

> +
> +	ret = ec_read(reg, &value);

[Severity: High]
Does passing &value (s8 *) to ec_read(u8, u8 *) trigger a -Wpointer-sign
warning (and build failure under CONFIG_WERROR)?

> +
> +	/* Degree Celsius to millidegree Celsius */
> +	*val = value * 1000;
> +
> +	return ret;
> +}
> +
> +static int simatic_ipc_ec_temp_write(const struct simatic_ipc_ec_temp *temp, u32 attr,
> +				     int channel, long val)
> +{
> +	/*
> +	 * Millidegree Celsius to degree Celsius
> +	 */
> +	s8 value = (s8)clamp((s8)DIV_ROUND_CLOSEST(val, 1000), (s8)-128, (s8)127);

[Severity: Medium]
Does casting the result of DIV_ROUND_CLOSEST(val, 1000) to s8 before
clamp() make clamp() a no-op?

Because the first argument is already truncated to s8, writing a threshold
outside [-128000, 127499] wraps modulo 256 instead of saturating (for
example, 130000 wraps to -126 C), and values near LONG_MAX or LONG_MIN can
also overflow DIV_ROUND_CLOSEST(val, 1000) unless val is clamped before
division.

[ ... ]

> +static int simatic_ipc_ec_fan_read(struct simatic_ipc_ec_fan *fan, enum hwmon_sensor_types type,
> +				   u32 attr, int channel, long *val)
> +{
> +	u16 value_u16;
> +	u8 value_u8;
> +	int ret;
> +	u8 reg;
> +
> +	switch (type) {
> +	case hwmon_fan:
> +		switch (attr) {
> +		case hwmon_fan_input:
> +			reg = fan_reg(fan->base, FAN_REG_SPEED);
> +			ret = simatic_ipc_ec_read_block(reg, &value_u16, sizeof(value_u16));
> +			*val = value_u16;
> +			return ret;
> +		default:
> +			break;
> +		}
> +		break;
> +	case hwmon_pwm:
> +		switch (attr) {
> +		case hwmon_pwm_input:
> +			reg = fan_reg(fan->base, FAN_REG_DUTY_LEVEL);
> +			ret = ec_read(reg, &value_u8);
> +			*val = value_u8;
> +			return ret;
> +		case hwmon_pwm_enable:
> +			reg = fan_reg(fan->base, FAN_REG_MODE);
> +			ret = ec_read(reg, &value_u8);
> +			*val = CONTROL_MODE_GET(value_u8);
> +			return ret;

[Severity: Medium]
When ec_read() or simatic_ipc_ec_read_block() fails here and in
simatic_ipc_ec_temp_read(), does assigning *val read uninitialized stack
variables (value_u16, value_u8, and value)?  ec_read() leaves its output
parameter untouched on error, which triggers KMSAN uninitialized-memory
warnings when *val is computed before checking ret.

[ ... ]

> +static int simatic_ipc_ec_fan_set_control_mode(struct simatic_ipc_ec_fan *fan, u8 ctrl_mode)
> +{
> +	int ret;
> +	u8 mode;
> +
> +	/* 0: full speed, 1: mannual control, 2: auto-control */
> +	if (ctrl_mode > 2)
> +		return -EINVAL;

[ ... ]

> +static int simatic_ipc_ec_fan_write(struct simatic_ipc_ec_fan *fan, u32 attr, int channel,
> +				    long val)
> +{
> +	switch (attr) {
> +	case hwmon_pwm_input:
> +		if (val < 0 || val > 0xFF)
> +			return -EINVAL;
> +		return ec_write(fan_reg(fan->base, FAN_REG_DUTY_LEVEL), (u8)val);
> +	case hwmon_pwm_enable:
> +		return simatic_ipc_ec_fan_set_control_mode(fan, (u8)val);

[Severity: Medium]
Does casting val to u8 before calling simatic_ipc_ec_fan_set_control_mode()
allow out-of-range values such as 256 or -255 to bypass the ctrl_mode > 2
check and change the EC fan control mode?

[ ... ]

> +static struct hwmon_channel_info simatic_ipc_ec_temp_ch_info = {
> +	.type = hwmon_temp,
> +	.config = NULL
> +};

[ ... ]

> +static int simatic_ipc_ec_hwmon_probe(struct device *dev, struct simatic_ipc_ec_sensor *data)
> +{

[ ... ]

> +	temp_config = devm_kzalloc(dev, (temp_count + 1) * sizeof(u32), GFP_KERNEL);
> +	if (!temp_config)
> +		return -ENOMEM;
> +
> +	simatic_ipc_ec_temp_ch_info.config = temp_config;

[Severity: Medium]
Can storing the per-device devm-allocated temp_config into the static
global simatic_ipc_ec_temp_ch_info.config leave a dangling pointer on probe
failure or unbind, or overwrite another instance's config if more than one
110A5004 device is probed?

[ ... ]

> +static int simatic_ipc_ec_fan_probe(struct device *dev, struct simatic_ipc_ec_sensor *data)
> +{

[ ... ]

> +	if (fan_name) {
> +		char *p;
> +
> +		snprintf(fan->chip_name, CHIP_NAME_MAX_LEN, "simatic_ipc_ec_%s", fan_name);
> +		for (p = fan->chip_name; *p; p++)
> +			*p = tolower(*p);
> +	} else {
> +		snprintf(fan->chip_name, CHIP_NAME_MAX_LEN, "simatic_ipc_ec_%s", label);
> +	}

[Severity: Low]
What happens if label contains uppercase characters when fan_name is
absent, or if either string contains characters disallowed in hwmon chip
names such as '-' or spaces?

The else branch skips the tolower() loop, and neither branch sanitizes
characters rejected by __hwmon_device_register() (or via
devm_hwmon_sanitize_name()).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116163257.1303207-1-benedikt.niedermayr@siemens.com?part=1

  reply	other threads:[~2026-11-16 16:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 16:32 [PATCH 0/1] hwmon: simatic-ipc-ec-sensors: add BX-54A EC driver Benedikt Niedermayr
2026-11-16 16:32 ` [PATCH 1/1] " Benedikt Niedermayr
2026-11-16 16:50   ` sashiko-bot [this message]
2026-11-16 20:38     ` 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=sashiko-outbox-217386@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=benedikt.niedermayr@siemens.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 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.