From: sashiko-bot@kernel.org
To: "Alexey Charkov" <alchark@flipper.net>
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 2/2] hwmon: Add support for TI INA4230 power monitor
Date: Tue, 01 Dec 2026 08:37:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-242857@kernel.org> (raw)
In-Reply-To: <20261201-ina4230-v6-2-6b389e3b48bd@flipper.net>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] hwmon: ina4230: missing regcache_mark_dirty() in
ina4230_restore()
- [Medium] hwmon: ina4230: wrong regcache error assumption in
ina4230_write_enable()
- [Medium] hwmon: (ina4230) missing power-down in ina4230_suspend() and
destructive reset in ina4230_resume()
- [Low] hwmon: ina4230: duplicate dev_err_probe() and DT-only regulator
enable
- [Low] hwmon: ina4230: positional initializer in struct i2c_device_id
table
--
commit 1dfb5515b4af2021a38a681fc5d177a15b51cd15
Author: Alexey Charkov <alchark@flipper.net>
hwmon: Add support for TI INA4230 power monitor
This commit adds a hwmon driver for the Texas Instruments INA4230 4-channel
I2C current, voltage, power, and energy monitor.
> diff --git a/drivers/hwmon/ina4230.c b/drivers/hwmon/ina4230.c
> new file mode 100644
> index 0000000000000..cb7750abdbf55
> --- /dev/null
> +++ b/drivers/hwmon/ina4230.c
[ ... ]
> +/*
> + * Restore the cached configuration to the chip. Writing CONFIG1 restarts the
> + * conversions, so write it last, once the ranges and calibration are in place.
> + */
> +static int ina4230_restore(struct ina4230_data *ina)
> +{
> + int ret;
> +
> + ret = regcache_sync_region(ina->regmap, 0, INA4230_CONFIG1 - 1);
> + if (ret)
> + return ret;
> +
> + ret = regcache_sync_region(ina->regmap, INA4230_CONFIG2,
> + INA4230_DEVICE_ID);
> + if (ret)
> + return ret;
> +
> + return regcache_sync_region(ina->regmap, INA4230_CONFIG1, INA4230_CONFIG1);
> +}
[Severity: High]
Does ina4230_restore() need to call regcache_mark_dirty(ina->regmap) before
syncing the regions?
regcache_sync_region() returns immediately without writing anything to the
bus when map->cache_dirty is false, and map->cache_dirty is only set when
regcache_mark_dirty() is called or a register is written while in
cache_only mode. After an external chip reset (in ina4230_recover_reset())
or a suspend/resume cycle with no intervening cached writes (where
ina4230_resume() -> ina4230_init_chip() resets the chip), ina4230_restore()
is a no-op, leaving the hardware calibration and configuration registers at
their reset defaults so current, power, and energy readings stay zero and
4x gain shunt voltages read four times too low.
[ ... ]
> +static int ina4230_write_enable(struct device *dev, int channel, bool enable)
> +{
> + struct ina4230_data *ina = dev_get_drvdata(dev);
> + unsigned int config, mask = INA4230_CONFIG_CHx_EN(channel);
> + int ret;
> +
> + ret = regmap_read(ina->regmap, INA4230_CONFIG1, &config);
> + if (ret)
> + return ret;
> +
> + /* Bypass if enable status is not being changed */
> + if (!!(config & mask) == enable)
> + return 0;
> +
> + if (enable && ina->inputs[channel].disconnected)
> + return -ENODEV;
> +
> + /* For enabling routine, increase refcount and resume() at first */
> + if (enable) {
> + ret = pm_runtime_resume_and_get(ina->pm_dev);
> + if (ret < 0) {
> + dev_err(dev, "Failed to get PM runtime\n");
> + return ret;
> + }
> + }
> +
> + /*
> + * Even if the bus write fails, the cache takes the new value for the next
> + * sync to apply, so the reference follows the cached enable bit.
> + */
> + ret = regmap_update_bits(ina->regmap, INA4230_CONFIG1, mask,
> + enable ? mask : 0);
> +
> + /* For disabling routine, decrease refcount or suspend() at last */
> + if (!enable)
> + pm_runtime_put_sync(ina->pm_dev);
> +
> + return ret;
> +}
[Severity: Medium]
Does INA4230_CONFIG1 actually remain in the regmap cache when
regmap_update_bits() fails on the I2C bus?
For regmap_i2c with a cache, _regmap_raw_write_impl() drops the written
register entry from the cache on a bus write error:
drivers/base/regmap/regmap.c:_regmap_raw_write_impl() {
...
ret = map->write(map->bus_context, work_buf,
map->format.reg_bytes +
map->format.pad_bytes +
val_len);
kfree(buf);
if (ret != 0 && !map->cache_bypass && map->format.parse_val)
map->cache_ops->drop(map, reg, reg + 1);
...
}
If enabling a channel fails, the hardware bit is still cleared and the next
read repopulates the cache from the chip, leaking the runtime PM reference
taken by pm_runtime_resume_and_get(). If disabling the last active channel
fails, pm_runtime_put_sync() suspends the device into cache_only mode with
INA4230_CONFIG1 evicted from the cache, so later regmap_read(INA4230_CONFIG1)
calls fail with -EBUSY, and ina4230_pm_disable() on unbind ignores the failed
regmap_read() and loops over an uninitialized stack variable config when
calling pm_runtime_put_noidle().
[ ... ]
> +static int ina4230_probe_from_dt(struct device *dev, struct ina4230_data *ina)
> +{
> + const struct device_node *np = dev->of_node;
> + int ret;
> +
> + /* Compatible with non-DT platforms */
> + if (!np)
> + return 0;
> +
> + ina->alert_active_high = of_property_read_bool(np, "ti,alert-polarity-active-high");
> +
> + for_each_child_of_node_scoped(np, child) {
> + ret = ina4230_probe_child_from_dt(dev, child, ina);
> + if (ret)
> + return ret;
> + }
> +
> + ret = devm_regulator_get_enable_optional(dev, "vs");
> + if (ret && ret != -ENODEV)
> + return dev_err_probe(dev, ret, "Failed to get regulator\n");
> +
> + return 0;
> +}
[ ... ]
> + ret = ina4230_probe_from_dt(dev, ina);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Unable to probe from device tree\n");
[Severity: Low]
Every error path in ina4230_probe_from_dt() and ina4230_probe_child_from_dt()
already calls dev_err_probe(), so should ina4230_probe() return ret directly
to avoid logging a duplicate error and overwriting the deferred-probe reason?
Also, should devm_regulator_get_enable_optional(dev, "vs") run before the
!np early return (or in ina4230_probe()) so the supply is enabled on non-DT
platforms as well?
[ ... ]
> +static int ina4230_suspend(struct device *dev)
> +{
> + struct ina4230_data *ina = dev_get_drvdata(dev);
> +
> + regcache_cache_only(ina->regmap, true);
> +
> + return 0;
> +}
> +
> +static int ina4230_resume(struct device *dev)
> +{
> + struct ina4230_data *ina = dev_get_drvdata(dev);
> +
> + regcache_cache_only(ina->regmap, false);
> +
> + return ina4230_init_chip(ina);
> +}
> +
> +static DEFINE_RUNTIME_DEV_PM_OPS(ina4230_pm, ina4230_suspend, ina4230_resume,
> + NULL);
[Severity: Medium]
Should ina4230_suspend() put the chip into INA4230_MODE_POWERDOWN, and does
ina4230_resume() need to issue a full chip reset via ina4230_init_chip()?
Because DEFINE_RUNTIME_DEV_PM_OPS() also wires these callbacks for system
sleep via pm_runtime_force_suspend() and pm_runtime_force_resume(), leaving
INA4230_CONFIG1 untouched in ina4230_suspend() keeps active channels running
continuous conversions throughout system suspend. On resume, calling
ina4230_init_chip() writes INA4230_CONFIG2_RST, which zeroes all four
hardware energy accumulators even when vs remained powered across suspend,
and if ina4230_init_chip() fails, cache_only is left false while the device
remains suspended.
[ ... ]
> +static const struct i2c_device_id ina4230_ids[] = {
> + { "ina4230" },
> + { /* sentinel */ }
> +};
[Severity: Low]
This isn't a bug, but new struct i2c_device_id entries are expected to use
named initializers ({ .name = "ina4230" }).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-ina4230-v6-0-6b389e3b48bd@flipper.net?part=2
next prev parent reply other threads:[~2026-12-01 8:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 8:17 [PATCH v6 0/2] Add support for Texas Instruments INA4230 power monitor Alexey Charkov
2026-12-01 8:17 ` [PATCH v6 1/2] dt-bindings: hwmon: Add TI INA4230 4-channel I2C " Alexey Charkov
2026-12-01 8:17 ` [PATCH v6 2/2] hwmon: Add support for TI INA4230 " Alexey Charkov
2026-12-01 8:37 ` sashiko-bot [this message]
2026-12-01 8:49 ` Alexey Charkov
2026-12-01 8:37 ` [PATCH v6 0/2] Add support for Texas Instruments " sashiko-bot
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-242857@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alchark@flipper.net \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=robh@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.