From: sashiko-bot@kernel.org
To: "Sander Speetjens" <sander.speetjens@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 1/2] hwmon: add Raspberry Pi PMIC driver
Date: Thu, 19 Nov 2026 19:21:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-223866@kernel.org> (raw)
In-Reply-To: <20261119-hwmon-da9091-v2-1-d6c624272a9e@gmail.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] hwmon: (raspberrypi-pmic) missing !RASPBERRYPI_FIRMWARE under
COMPILE_TEST
- [Low] hwmon: raspberrypi-pmic: broken boolean condition in
rpi_pmic_is_visible()
- [Low] hwmon: raspberrypi-pmic: mixed C and C++ comment styles in
rpi_pmic_update()
- [Low] hwmon: raspberrypi-pmic: dead last_update init and unused
hwmon_dev in rpi_pmic_probe()
- [Low] hwmon: raspberrypi-pmic-hwmon: rpi_pmic_probe() still uses
da9091 hwmon name
- [Low] hwmon: (raspberrypi-pmic) rpi_pmic_probe() logs dev_err() on
-ENODEV
--
commit b45f4c2fa5a0bc70439e56dc5c7bc176f104a858
Author: Sander Speetjens <sander.speetjens@gmail.com>
hwmon: add Raspberry Pi PMIC driver
This commit adds a hwmon driver for the Raspberry Pi 5 PMIC that reads
voltage, current and temperature sensors through the VideoCore firmware
mailbox interface.
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 18c682e1a4756..2fd7e2fdad6c8 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -2020,6 +2020,17 @@ config SENSORS_RASPBERRYPI_HWMON
> This driver can also be built as a module. If so, the module
> will be called raspberrypi-hwmon.
>
> +config SENSORS_RASPBERRYPI_PMIC
> + tristate "Raspberry Pi PMIC monitor"
> + depends on RASPBERRYPI_FIRMWARE || COMPILE_TEST
[Severity: Medium]
Can this cause a link failure when CONFIG_COMPILE_TEST=y,
CONFIG_RASPBERRYPI_FIRMWARE=m and CONFIG_SENSORS_RASPBERRYPI_PMIC=y?
Because COMPILE_TEST is a boolean, RASPBERRYPI_FIRMWARE || COMPILE_TEST
allows SENSORS_RASPBERRYPI_PMIC to be built-in while the firmware driver is
a module. In include/soc/bcm2835/raspberrypi-firmware.h,
IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE) is true when
CONFIG_RASPBERRYPI_FIRMWARE=m, so vmlinux fails to link with undefined
references to devm_rpi_firmware_get() and rpi_firmware_property().
Using:
depends on RASPBERRYPI_FIRMWARE || (COMPILE_TEST && !RASPBERRYPI_FIRMWARE)
like SENSORS_RASPBERRYPI_HWMON caps SENSORS_RASPBERRYPI_PMIC to m when
RASPBERRYPI_FIRMWARE=m.
[ ... ]
> diff --git a/drivers/hwmon/raspberrypi-pmic-hwmon.c b/drivers/hwmon/raspberrypi-pmic-hwmon.c
> new file mode 100644
> index 0000000000000..ade0e1267aa02
> --- /dev/null
> +++ b/drivers/hwmon/raspberrypi-pmic-hwmon.c
> @@ -0,0 +1,299 @@
[ ... ]
> +struct rpi_pmic_data {
> + struct rpi_firmware *fw;
> + struct device *hwmon_dev;
> + u32 values[RPI_PMIC_NUM_CHANNELS];
> + u64 last_update;
> +};
[ ... ]
> +static int rpi_pmic_update(struct rpi_pmic_data *data)
> +{
> + struct rpi_pmic_adc_msg msg = {
> + .index = cpu_to_le32(0),
> + .length = cpu_to_le32(RPI_PMIC_NUM_CHANNELS),
> + };
> + int ret;
> + unsigned int i;
> +
> + ret = rpi_firmware_property(data->fw, RPI_FIRMWARE_GET_PMIC_ADC,
> + &msg, sizeof(msg));
> + if (ret)
> + return ret;
> +
> + // Sanity-check the response
> + if (le32_to_cpu(msg.length) != RPI_PMIC_NUM_CHANNELS)
> + return -EIO;
[Severity: Low]
This isn't a bug, but Documentation/hwmon/submitting-patches.rst asks not
to mix C and C++ comment styles in a single driver. The rest of this file
uses /* */ comments.
[ ... ]
> +static umode_t rpi_pmic_is_visible(const void *data,
> + enum hwmon_sensor_types type,
> + u32 attr, int channel)
> +{
> + switch (type) {
> + case hwmon_in:
> + if (channel < ARRAY_SIZE(rpi_pmic_in_idx) ||
> + attr == hwmon_in_input || attr == hwmon_in_label)
> + return 0444;
> + break;
> + case hwmon_curr:
> + if (channel < ARRAY_SIZE(rpi_pmic_curr_idx) ||
> + attr == hwmon_curr_input || attr == hwmon_curr_label)
> + return 0444;
> + break;
> + case hwmon_temp:
> + if (channel < ARRAY_SIZE(rpi_pmic_temp_idx) ||
> + attr == hwmon_temp_input || attr == hwmon_temp_label)
> + return 0444;
> + break;
> + default:
> + break;
> + }
> + return 0;
> +}
[Severity: Low]
Should the channel bounds checks in rpi_pmic_is_visible() use && instead of
|| before the attribute checks?
With ||, any valid channel index short-circuits the condition and returns
0444 regardless of attr, and any input or label attribute returns 0444 even
if channel is out of range for rpi_pmic_*_idx[].
[ ... ]
> +static int rpi_pmic_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct rpi_pmic_data *data;
> + struct rpi_firmware *fw;
> + int ret;
> +
> + fw = devm_rpi_firmware_get(dev, dev->parent->of_node);
> + if (!fw)
> + return -EPROBE_DEFER;
> +
> + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + data->fw = fw;
> + data->last_update = get_jiffies_64() - msecs_to_jiffies(RPI_PMIC_CACHE_MS);
[Severity: Low]
This isn't a bug, but data->last_update is immediately overwritten by
rpi_pmic_update() on the next line (or discarded if probe fails). Also,
data->hwmon_dev is only written in rpi_pmic_probe() and never read, so a
local struct device *hwmon_dev variable can replace the struct member.
> +
> + ret = rpi_pmic_update(data);
> + if (ret) {
> + dev_err(dev, "Failed to read PMIC ADC property: %d\n", ret);
> + return -ENODEV;
> + }
[Severity: Low]
As reported by Guenter Roeck on v1 [1], should rpi_pmic_probe() fail
silently without dev_err() when rpi_pmic_update() fails?
Because the platform device is registered unconditionally on Raspberry Pi 5
and calling rpi_pmic_update() is the only way to detect whether the running
firmware implements RPI_FIRMWARE_GET_PMIC_ADC, logging an error produces a
spurious message on systems with older firmware.
> +
> + data->hwmon_dev =
> + devm_hwmon_device_register_with_info(dev,
> + "da9091", data, &rpi_pmic_chip_info, NULL);
[Severity: Low]
As reported by Guenter Roeck on v1 [2], should the hwmon device name pass a
generic name such as "rpi_pmic" instead of "da9091" so the driver does not
reference a specific PMIC chip?
[1] https://lore.kernel.org/r/be16d42f-e6bf-45d5-83a8-28afbe54e3f8@roeck-us.net
[2] https://lore.kernel.org/r/be16d42f-e6bf-45d5-83a8-28afbe54e3f8@roeck-us.net
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-hwmon-da9091-v2-0-d6c624272a9e@gmail.com?part=1
next prev parent reply other threads:[~2026-11-19 19:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 19:02 [PATCH v2 0/2] hwmon: add Raspberry Pi 5 PMIC driver Sander Speetjens
2026-11-19 19:02 ` [PATCH v2 1/2] hwmon: add Raspberry Pi " Sander Speetjens
2026-11-19 19:21 ` sashiko-bot [this message]
2026-11-19 19:02 ` [PATCH v2 2/2] firmware: raspberrypi: Register PMIC hwmon driver on Pi 5 Sander Speetjens
2026-11-19 19:15 ` 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-223866@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=sander.speetjens@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox