Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shubham Chakraborty" <chakrabortyshubham66@gmail.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2 2/2] hwmon: raspberrypi: Add voltage input support
Date: Sat, 16 May 2026 19:45:02 +0000	[thread overview]
Message-ID: <20260516194503.3B563C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260516191555.17978-3-chakrabortyshubham66@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Unconditional self-rescheduling of the background workqueue leads to a use-after-free on device removal.
- [Medium] The driver incorrectly detects and exposes unsupported voltage channels due to unverified firmware responses.
--

commit aa874218705dba1c84bc41a7c3b61abd93bbf0a2
Author: Shubham Chakraborty <chakrabortyshubham66@gmail.com>

hwmon: raspberrypi: Add voltage input support

This commit extends the raspberrypi-hwmon driver to expose firmware-provided
voltage measurements. It adds core and SDRAM voltage inputs, converting
the values from microvolts to millivolts for the hwmon subsystem.
Inputs are only exposed if the firmware reports support for the corresponding
voltage ID.

> diff --git a/drivers/hwmon/raspberrypi-hwmon.c b/drivers/hwmon/raspberrypi-hwmon.c
> index a2938881ccd2f..4f96f37116f32 100644
> --- a/drivers/hwmon/raspberrypi-hwmon.c
> +++ b/drivers/hwmon/raspberrypi-hwmon.c

[ ... ]

> @@ -56,6 +70,23 @@ static void rpi_firmware_get_throttled(struct rpi_hwmon_data *data)
>  	hwmon_notify_event(data->hwmon_dev, hwmon_in, hwmon_in_lcrit_alarm, 0);
>  }
>  
> +static int rpi_firmware_get_voltage(struct rpi_hwmon_data *data, u32 id,
> +				    long *val)
> +{
> +	struct rpi_firmware_get_value packet;
> +	int ret;
> +
> +	packet.id = cpu_to_le32(id);
> +	packet.val = 0;
> +	ret = rpi_firmware_property(data->fw, RPI_FIRMWARE_GET_VOLTAGE,
> +				    &packet, sizeof(packet));

If the firmware does not support the RPI_FIRMWARE_GET_VOLTAGE tag or the
specific voltage ID, could the mailbox transaction still return 0 without
modifying the tag buffer?

If so, packet.val would remain 0 and this function would return success.
During probe, this would cause the channel to be incorrectly flagged as
supported, exposing sysfs files that permanently read 0mV.

Would it be safer to initialize packet.val to a sentinel value like ~0
before querying the firmware to verify the voltage ID is actually supported?

> +	if (ret)
> +		return ret;
> +
> +	*val = le32_to_cpu(packet.val) / 1000;
> +	return 0;
> +}
> +
>  static void get_values_poll(struct work_struct *work)
>  {
>  	struct rpi_hwmon_data *data;

Does the unconditional rescheduling in get_values_poll() cause a
use-after-free regression during driver removal?

If the work function executes concurrently with driver unbind,
cancel_delayed_work_sync() will wait for it to finish. However,
get_values_poll() currently reschedules itself just before returning:

get_values_poll() {
        ...
        schedule_delayed_work(&data->get_values_poll_work, 2 * HZ);
}

After cancellation completes, devres frees the memory for data. When the
rescheduled work executes later, it accesses the freed data pointer.

Could a shutdown flag be added to safely prevent rescheduling during
teardown?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260516191555.17978-1-chakrabortyshubham66@gmail.com?part=2

  reply	other threads:[~2026-05-16 19:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260516164407.25255-1-chakrabortyshubham66@gmail.com>
2026-05-16 16:44 ` [PATCH 2/2] hwmon: raspberrypi: Add voltage input support Shubham Chakraborty
2026-05-16 17:13   ` Guenter Roeck
2026-05-16 18:24     ` Guenter Roeck
2026-05-16 19:15 ` [PATCH v2 0/2] raspberrypi: firmware and hwmon voltage support Shubham Chakraborty
2026-05-16 19:15   ` [PATCH v2 1/2] soc: bcm2835: raspberrypi-firmware: Add voltage domain IDs Shubham Chakraborty
2026-05-16 19:22     ` sashiko-bot
2026-05-16 23:09     ` Guenter Roeck
2026-05-16 19:15   ` [PATCH v2 2/2] hwmon: raspberrypi: Add voltage input support Shubham Chakraborty
2026-05-16 19:45     ` sashiko-bot [this message]
2026-05-16 23:22       ` Guenter Roeck
2026-05-16 23:20     ` Guenter Roeck
2026-05-17  8:04 ` [PATCH v3 0/3] raspberrypi-hwmon voltage support and teardown fix Shubham Chakraborty
2026-05-17  8:04   ` [PATCH v3 1/3] soc: bcm2835: raspberrypi-firmware: Add voltage domain IDs Shubham Chakraborty
2026-05-18 22:17     ` Guenter Roeck
2026-05-19 15:29     ` Florian Fainelli
2026-05-20 13:35     ` Guenter Roeck
2026-05-17  8:04   ` [PATCH v3 2/3] hwmon: raspberrypi: Add voltage input support Shubham Chakraborty
2026-05-19 15:28     ` Florian Fainelli
2026-05-20 13:37     ` Guenter Roeck
2026-05-17  8:04   ` [PATCH v3 3/3] hwmon: raspberrypi: Fix delayed-work teardown race Shubham Chakraborty
2026-05-20 13:39     ` 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=20260516194503.3B563C19425@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chakrabortyshubham66@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox