All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea della Porta <andrea.porta@suse.com>
To: Gary Guo <gary@garyguo.net>
Cc: Andrea della Porta <andrea.porta@suse.com>,
	sashiko-reviews@lists.linux.dev, devicetree@vger.kernel.org,
	conor+dt@kernel.org, robh@kernel.org, ukleinek@kernel.org
Subject: Re: [PATCH v7 2/3] pwm: rp1: Add RP1 PWM controller driver
Date: Fri, 4 Sep 2026 15:53:16 +0200	[thread overview]
Message-ID: <aprNTF0278NuH55k@apocalypse> (raw)
In-Reply-To: <DKY8USKYJJVM.17HQ78YIYZMFV@garyguo.net>

Hi Gary,

On 19:42 Tue 25 Aug     , Gary Guo wrote:
> On Fri Jul 24, 2026 at 4:04 PM BST, Andrea della Porta wrote:
> > Hi,
> >
> > On 10:02 Mon 20 Jul     , sashiko-bot@kernel.org wrote:
> >> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
> >> - [High] Missing `.remove` callback leads to Use-After-Free in the PWM and Syscon cores and leaks clock resources on driver unbind.
> >> - [High] Register context loss on suspend/resume silently breaks PWM output.
> >> - [High] Unclamped hardware duty ticks lead to integer underflow in the PWM core for normal polarity.
> >> --
> >> 
> >> --- Patch [2]: [PATCH v7 2/3] pwm: rp1: Add RP1 PWM controller driver ---
> >> commit 0c98703d857577902e57d25b42a3d46dfbde5795
> >> Author: Naushir Patuck <naush@raspberrypi.com>
> >> 
> >> pwm: rp1: Add RP1 PWM controller driver
> >> 
> >> The Raspberry Pi RP1 southbridge features an embedded PWM controller with
> >> 4 output channels, alongside an RPM interface to read the fan speed on the
> >> Raspberry Pi 5. Add the supporting driver.
> > 
> >> > +static struct platform_driver rp1_pwm_driver = {
> >> > +	.probe = rp1_pwm_probe,
> >> > +	/*
> >> > +	 * .remove is not needed because this driver cannot be removed/unbound
> >> > +	 * cause it relies on syscon which cannot be removed
> >> > +	 */
> >> > +	.driver = {
> >> > +		.name = "rp1-pwm",
> >> 
> >> [Severity: High]
> >> Is it safe to omit the remove callback here?
> >> 
> >> Even with suppress_bind_attrs set on the driver, if the parent RP1 PCIe
> >> device is removed, reset, or unbound via sysfs, it will forcibly unbind all
> >> child devices.
> >> 
> >> Without a remove callback to run cleanup, pwmchip_remove() is never called
> >> and the clock is left enabled. Because the backing memory is devm-managed,
> >> the devres subsystem will eventually free the pwm_chip and regmap memory.
> >> This can leave dangling pointers in the core pwm_chips IDR and the global
> >> syscon_list, which could result in a use-after-free.
> >
> > This is true. Uwe, I guess I should reintroduce the .remove callback,
> > what do you think?
> >
> 
> How is remove going to work with syscon? The previous version seems to just
> ignore it completely.

True, unfortunately we have not much choice with syscon because it does not
contemplate a corresponding remove function. The best well-behaved code could
just deal with clocks and resources that can be released, while syscon is
unfortunately not among them.

On the other hand, I'd like to emphasize the following:

- the driver could not be unbinded nor unloaded (directly) by the user, and...
- ...PWM driver removal as a consequence of the pci bus device being forcibly
  removed will almost surely leave the system unusable.

As a matter of fact, even though it's not impossible for the remove callback
to be called, it seems highly unlikely. So maybe it's not that big deal.

> 
> Also, do you actually need syscon here? Given that the pwm fan device is going
> to depend on the PWM fan device anyway, you could just EXPORT_SYMBOL_NS an API
> from the rp1 driver that returns the tachometer reading when supplied with a rp1
> pwm device pointer?

I'm not devoted to syscon so if everyone agrees on the EXPORT_SYMBOL_NS solution
I'm perfectly fine. It seems to be used throughout several drivers and as long as
it's not considered to couple the consumer and the PWM producer too much, I think
it's an easy alternative. Uwe, are you fine with that?

Many thanks,
Andrea

> 
> Best,
> Gary
> 

  reply	other threads:[~2026-09-04 13:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20  9:44 [PATCH v7 0/3] Add RP1 PWM controller support Andrea della Porta
2026-07-20  9:44 ` [PATCH v7 1/3] dt-bindings: pwm: Add Raspberry Pi RP1 PWM controller Andrea della Porta
2026-07-20  9:50   ` sashiko-bot
2026-07-24 14:16     ` Andrea della Porta
2026-07-20  9:44 ` [PATCH v7 2/3] pwm: rp1: Add RP1 PWM controller driver Andrea della Porta
2026-07-20 10:02   ` sashiko-bot
2026-07-24 15:04     ` Andrea della Porta
2026-08-25 18:42       ` Gary Guo
2026-09-04 13:53         ` Andrea della Porta [this message]
2026-09-04 14:05           ` Gary Guo
2026-09-04 16:42             ` Andrea della Porta
2026-09-03 20:36   ` Christophe JAILLET
2026-09-04 16:31     ` Andrea della Porta
2026-07-20  9:44 ` [PATCH v7 3/3] arm64: dts: broadcom: rpi-5: Add RP1 PWM node Andrea della Porta
2026-09-03 20:11 ` [PATCH v7 0/3] Add RP1 PWM controller support Florian Fainelli

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=aprNTF0278NuH55k@apocalypse \
    --to=andrea.porta@suse.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gary@garyguo.net \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=ukleinek@kernel.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 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.