From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796114227; b=RLP7Om6UWBgjHKU3zLKPuWwdb3nC9en+mDyyPRUXLvMH7/IeCxeuyCR79Mcwl6ro1bU7 +RaPdQuGuhcdmdGy5h5KLY+ZDEFN+aInpa9XKtKB1u1jZolQuzWi1RszpQmHCor6ufvO8 ReG+FhKa+S+zo7YvNfeO4t1IQRRwDXM4e/9jnisKlFaoyrsuolxUWH+YHBvahcsRoeIXB nrCfRrmsmG0MTGbw1tlBaExQekk5aDEH1beB4Pq/0astRMn/fJ9Z/ptwg9/IXZycfVund 0HS4nC1SnkAwCP/DB/+OmCyXGOJvi1g9p+BdOgrB9yY6pmdDQkV1/OXdYyaQ6zhFHqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796114227; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=7bDy8lNhWkz2OgTXSuBdWQRlwwUpsy1jAufHvgOB9Yw=; b=dCgZysnvcDNnn8mpF67zyEa2e3g0ovBqWWomQlDQI1M9ElBwbjHj+sFoWZGBIrk/B7SA MhLuORoBNveteD5VMiUN3mAsQA2dnzzmuscKa3l4XSiSm/2K0gCGN4lN/2Ul/Px4UM0LF 0Ub6+FseKc4OssMGB4ZWEr6etP33mQnHMRjua4ya0Y3RFAnL+XyJx+MIsGvVumfH2wxb/ x/vccCe1Pewve3YoORhnIFAduiZm/g3QbuCgefq/XhgPo/O1oLhojb9ulNC27LNe0nf2y dknnKFIcakDzkDtY9opZoJncku9UxkZEQzNIbOa26Ec5UcOgAeqQl+8oVGNoRDhsTCA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JzIeYYQp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C3BC606A31A; Tue, 1 Dec 2026 08:37:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=JzIeYYQp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 407A81F00898; Tue, 1 Dec 2026 08:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796114226; bh=7bDy8lNhWkz2OgTXSuBdWQRlwwUpsy1jAufHvgOB9Yw=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=JzIeYYQpkkSsAusG4CnPDFbBegK4gpeWLA848qBt5yyU5bDy9dFA519Klf6dUyFRe 2YqKNUd0fMo/Pxvn2lbTg1a0R8ldLv/+gh57oHii2jx24tT7BLGLhs051xzgicGyPJ PPWoWgbx7Yb5quDGH8SOppEcQ/6vROZ4saGrIE/ClFG4Bt5+tnjDO9Hh2iPZZuSM9C 8CLoVnSF9/B/e0FDeLdUf4UNAo4e+s3aFs5iVe0bZlR6vNRUKJINBeuFYRDW+1qXzn zBysO0vI3WI4mY4G2K52bQuiRKXcsCcGr9bNdXzSeZUWDD1it0+IvF9TCDVGjDYVu7 d/3oHIUjheTLg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v6 2/2] hwmon: Add support for TI INA4230 power monitor Reply-To: sashiko-reviews@lists.linux.dev To: "Alexey Charkov" Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261201-ina4230-v6-2-6b389e3b48bd@flipper.net> References: <20261201-ina4230-v6-0-6b389e3b48bd@flipper.net> <20261201-ina4230-v6-2-6b389e3b48bd@flipper.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 08:37:05 +0000 X-Mailing-List: linux-hwmon@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 restart= s 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 =3D regcache_sync_region(ina->regmap, 0, INA4230_CONFIG1 - 1); > + if (ret) > + return ret; > + > + ret =3D regcache_sync_region(ina->regmap, INA4230_CONFIG2, > + INA4230_DEVICE_ID); > + if (ret) > + return ret; > + > + return regcache_sync_region(ina->regmap, INA4230_CONFIG1, INA4230_CONFI= G1); > +} [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 en= able) > +{ > + struct ina4230_data *ina =3D dev_get_drvdata(dev); > + unsigned int config, mask =3D INA4230_CONFIG_CHx_EN(channel); > + int ret; > + > + ret =3D regmap_read(ina->regmap, INA4230_CONFIG1, &config); > + if (ret) > + return ret; > + > + /* Bypass if enable status is not being changed */ > + if (!!(config & mask) =3D=3D enable) > + return 0; > + > + if (enable && ina->inputs[channel].disconnected) > + return -ENODEV; > + > + /* For enabling routine, increase refcount and resume() at first */ > + if (enable) { > + ret =3D 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 n= ext > + * sync to apply, so the reference follows the cached enable bit. > + */ > + ret =3D 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 =3D map->write(map->bus_context, work_buf, map->format.reg_bytes + map->format.pad_bytes + val_len); kfree(buf); if (ret !=3D 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_CONFIG= 1) calls fail with -EBUSY, and ina4230_pm_disable() on unbind ignores the fail= ed 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 =3D dev->of_node; > + int ret; > + > + /* Compatible with non-DT platforms */ > + if (!np) > + return 0; > + > + ina->alert_active_high =3D of_property_read_bool(np, "ti,alert-polarity= -active-high"); > + > + for_each_child_of_node_scoped(np, child) { > + ret =3D ina4230_probe_child_from_dt(dev, child, ina); > + if (ret) > + return ret; > + } > + > + ret =3D devm_regulator_get_enable_optional(dev, "vs"); > + if (ret && ret !=3D -ENODEV) > + return dev_err_probe(dev, ret, "Failed to get regulator\n"); > + > + return 0; > +} [ ... ] > + ret =3D 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 reaso= n? 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 =3D dev_get_drvdata(dev); > + > + regcache_cache_only(ina->regmap, true); > + > + return 0; > +} > + > +static int ina4230_resume(struct device *dev) > +{ > + struct ina4230_data *ina =3D 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_re= sume, > + 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[] =3D { > + { "ina4230" }, > + { /* sentinel */ } > +}; [Severity: Low] This isn't a bug, but new struct i2c_device_id entries are expected to use named initializers ({ .name =3D "ina4230" }). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201-ina4230-v6= -0-6b389e3b48bd@flipper.net?part=3D2