From: sashiko-bot@kernel.org
To: "Carl Lee" <carl.lee@amd.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH] hwmon: (pmbus/ltc4286) Add runtime shunt_resistor control
Date: Thu, 03 Sep 2026 09:33:05 +0000 [thread overview]
Message-ID: <20260903093305.7CDEB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260903-hwmon-pmbus-ltc4286-add-runtime-shunt-resistor-control-v1-1-aca2d49a1418@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The shared variable `data->rsense` is read without lock protection in the sysfs show function, causing a data race with concurrent store operations.
--
commit ba83e29a82adf5c7ae93ecbb0408db51473aa280
Author: Carl Lee <carl.lee@amd.com>
hwmon: (pmbus/ltc4286) Add runtime shunt_resistor control
This commit exposes a writable shunt_resistor sysfs attribute for the
ltc4286/ltc4287 drivers. It allows userspace to update the shunt resistor
value at runtime and updates the corresponding direct-format scaling
coefficients.
> diff --git a/drivers/hwmon/pmbus/ltc4286.c b/drivers/hwmon/pmbus/ltc4286.c
> index 8715d380784a0..e80c9ecea0997 100644
> --- a/drivers/hwmon/pmbus/ltc4286.c
> +++ b/drivers/hwmon/pmbus/ltc4286.c
[ ... ]
> @@ -16,6 +17,75 @@
>
> #define LTC4286_MFR_ID_SIZE 3
>
> +struct ltc4286_data {
> + struct pmbus_driver_info info;
> + u32 rsense;
> + bool vrange_low_enable;
> +};
> +
> +#define to_ltc4286_data(x) container_of((x), struct ltc4286_data, info)
> +
> +static ssize_t ltc4286_rsense_show(struct device *dev,
> + struct device_attribute *devattr,
> + char *buf)
> +{
> + struct i2c_client *client = to_i2c_client(dev->parent);
> + const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
> + struct ltc4286_data *data = to_ltc4286_data(info);
> +
> + return sysfs_emit(buf, "%u\n", data->rsense);
[Severity: Low]
Is it safe to read data->rsense here without holding a lock?
Since ltc4286_rsense_store() updates data->rsense under the protection of
pmbus_lock_interruptible(), a concurrent sysfs read and write could trigger
a KCSAN data race warning.
> +}
> +
> +static ssize_t ltc4286_rsense_store(struct device *dev,
> + struct device_attribute *devattr,
> + const char *buf, size_t count)
> +{
> + struct i2c_client *client = to_i2c_client(dev->parent);
> + const struct pmbus_driver_info *info_ro = pmbus_get_driver_info(client);
> + struct ltc4286_data *data = to_ltc4286_data(info_ro);
> + struct pmbus_driver_info *info = &data->info;
> + u32 rsense;
> + int ret;
> +
> + ret = kstrtou32(buf, 10, &rsense);
> + if (ret)
> + return ret;
> +
> + if (rsense == 0)
> + return -EINVAL;
> +
> + if (rsense > (INT_MAX / 1024))
> + return -EINVAL;
> +
> + ret = pmbus_lock_interruptible(client);
> + if (ret)
> + return ret;
> +
> + data->rsense = rsense;
> + info->m[PSC_CURRENT_OUT] = 1024 * rsense;
> + info->m[PSC_POWER] = data->vrange_low_enable ? 4 * rsense : rsense;
> +
> + pmbus_unlock(client);
> +
> + return count;
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260903-hwmon-pmbus-ltc4286-add-runtime-shunt-resistor-control-v1-1-aca2d49a1418@amd.com?part=1
next prev parent reply other threads:[~2026-09-03 9:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 9:23 [PATCH] hwmon: (pmbus/ltc4286) Add runtime shunt_resistor control Carl Lee
2026-09-03 9:33 ` sashiko-bot [this message]
2026-09-03 12:57 ` 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=20260903093305.7CDEB1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=carl.lee@amd.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.