From: "NG, TZE YEE" <tze.yee.ng@altera.com>
To: Guenter Roeck <linux@roeck-us.net>,
Dinh Nguyen <dinguyen@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH v8 1/2] firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device
Date: Mon, 27 Jul 2026 06:42:07 +0000 [thread overview]
Message-ID: <3350cd23-6a0c-4f8e-8de8-d6e26aa82d7d@altera.com> (raw)
In-Reply-To: <20260723061418.423A81F000E9@smtp.kernel.org>
On 23/7/2026 2:14 pm, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
>
> New issues:
> - [Medium] Hardware monitoring functionality is improperly registered as a platform device instead of an auxiliary device.
>
I'll keep the platform device registration for this series. I’m
happy to look at converting socfpga-hwmon to an auxiliary device in a
follow-up if preferred.
> Pre-existing issues:
> - [High] Pre-existing Use-After-Free race condition during module removal due to improper teardown ordering of child devices.
It is fixed in
https://lore.kernel.org/all/6630a1568f162d9455e0580f7ccadc262db4718e.1784007275.git.adrian.ho.yin.ng@altera.com/
> --
>
> --- Patch [1]: [PATCH v8 1/2] firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device ---
> commit 5ba2e4fb155f074de568280aeede81883f87924e
> Author: Tze Yee Ng <tze.yee.ng@altera.com>
>
> firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device
>
> Add asynchronous Stratix 10 service layer support for hardware monitor
> temperature and voltage read commands. Register a socfpga-hwmon platform
> device from the service layer driver when hardware monitor support is enabled.
>
>> diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c
>> index c24ca5823078f..fc38afed5b7fe 100644
>> --- a/drivers/firmware/stratix10-svc.c
>> +++ b/drivers/firmware/stratix10-svc.c
>
> [ ... ]
>
>> @@ -2013,16 +2028,38 @@ static int stratix10_svc_drv_probe(struct platform_device *pdev)
>> if (ret)
>> goto err_put_device;
>>
>> + if (IS_ENABLED(CONFIG_SENSORS_ALTERA_SOCFPGA_HWMON)) {
>> + svc->stratix10_svc_hwmon =
>> + platform_device_alloc(SOCFPGA_HWMON, 0);
>
> [Severity: Medium]
> According to the hardware monitoring subsystem guidelines, if the main
> functionality of a chip is not hardware monitoring, its secondary hardware
> monitoring functionality should be implemented as an auxiliary device driver.
>
> Since the primary purpose of this module is the firmware service layer,
> does registering the hardware monitoring functionality as a platform device
> violate the subsystem API layering? Could this be implemented via the
> auxiliary bus instead of using platform_device_alloc()?
>
>> + if (!svc->stratix10_svc_hwmon) {
>> + dev_err(dev, "failed to allocate %s device\n",
>> + SOCFPGA_HWMON);
>> + } else {
>> + svc->stratix10_svc_hwmon->dev.parent = dev;
>> +
>> + ret = platform_device_add(svc->stratix10_svc_hwmon);
>> + if (ret) {
>> + dev_err(dev, "failed to add %s device: %d\n",
>> + SOCFPGA_HWMON, ret);
>> + platform_device_put(svc->stratix10_svc_hwmon);
>> + svc->stratix10_svc_hwmon = NULL;
>> + }
>> + }
>> + }
>> +
>> ret = of_platform_default_populate(dev_of_node(dev), NULL, dev);
>
> [ ... ]
>
>> @@ -2046,6 +2083,9 @@ static void stratix10_svc_drv_remove(struct platform_device *pdev)
>> struct stratix10_svc_controller *ctrl = platform_get_drvdata(pdev);
>> struct stratix10_svc *svc = ctrl->svc;
>>
>> + if (svc->stratix10_svc_hwmon)
>> + platform_device_unregister(svc->stratix10_svc_hwmon);
>> +
>> stratix10_svc_async_exit(ctrl);
>>
>> of_platform_depopulate(ctrl->dev);
>
> [Severity: High]
> This is a pre-existing issue, but does this teardown order create a
> use-after-free race condition during module removal?
>
> The stratix10_svc_drv_remove() function calls stratix10_svc_async_exit()
> before unregistering the remaining OF child devices and the RSU child device.
> The async exit function destroys the async structures and frees the
> asynchronous channels and handlers.
>
> If userspace concurrently accesses sysfs attributes for the child devices
> while the module unloads, could it invoke stratix10_svc_async_send()
> or stratix10_svc_async_poll() after the async channels have been freed?
>
> For example, stratix10_svc_async_send() performs lockless reads of achan:
>
> stratix10_svc_async_send() {
> ...
> achan = chan->async_chan;
> ctrl = chan->ctrl;
> actrl = &ctrl->actrl;
>
> if (!actrl->initialized) {
> ...
> }
>
> Would this lead to memory corruption if the structures are already deallocated?
> Should the child devices be fully unregistered before calling
> stratix10_svc_async_exit() to ensure no concurrent accesses are possible?
>
next prev parent reply other threads:[~2026-07-27 6:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 6:02 [PATCH v8 0/2] hwmon: add Altera SoC FPGA hardware monitoring support tze.yee.ng
2026-07-23 6:02 ` [PATCH v8 1/2] firmware: stratix10-svc: add async HWMON read commands and register socfpga-hwmon device tze.yee.ng
[not found] ` <20260723061418.423A81F000E9@smtp.kernel.org>
2026-07-27 6:42 ` NG, TZE YEE [this message]
2026-07-27 16:21 ` Guenter Roeck
2026-07-27 17:02 ` Dinh Nguyen
2026-07-27 18:45 ` Guenter Roeck
2026-07-23 6:02 ` [PATCH v8 2/2] hwmon: add Altera SoC FPGA hardware monitoring driver tze.yee.ng
[not found] ` <20260723061515.BAA0E1F000E9@smtp.kernel.org>
2026-07-28 6:51 ` NG, TZE YEE
2026-07-28 14:17 ` Guenter Roeck
2026-07-29 2:40 ` Dinh Nguyen
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=3350cd23-6a0c-4f8e-8de8-d6e26aa82d7d@altera.com \
--to=tze.yee.ng@altera.com \
--cc=corbet@lwn.net \
--cc=dinguyen@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=skhan@linuxfoundation.org \
/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
all inboxes | Powered by JetHome®