Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Gary Guo" <gary@garyguo.net>
To: "Andrea della Porta" <andrea.porta@suse.com>,
	"Gary Guo" <gary@garyguo.net>
Cc: "Uwe Kleine-König" <ukleinek@kernel.org>,
	linux-pwm@vger.kernel.org, "Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Florian Fainelli" <florian.fainelli@broadcom.com>,
	"Broadcom internal kernel review list"
	<bcm-kernel-feedback-list@broadcom.com>,
	devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	"Naushir Patuck" <naush@raspberrypi.com>,
	"Stanimir Varbanov" <svarbanov@suse.de>,
	mbrugger@suse.com, "Sean Young" <sean@mess.org>,
	"Julian Braha" <julianbraha@gmail.com>,
	"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>
Subject: Re: [PATCH v9 2/3] pwm: rp1: Add RP1 PWM controller driver
Date: Thu, 24 Sep 2026 19:05:08 +0100	[thread overview]
Message-ID: <DLNQUO0EQW7M.29SAT06RE6IOV@garyguo.net> (raw)
In-Reply-To: <arP-P_a7OyhtMQyr@apocalypse>

On Wed Sep 23, 2026 at 5:28 PM BST, Andrea della Porta wrote:
> This driver implements only static PM ops so I think both pwm_get API or
> device_link_add should deal automatically with races.
> OTOH, what if the consumer obtains a reference to the PWM device via of_* API (or
> other means)? Thhose calls does not create device link and we would still have unsync
> critical paths.

of_pwm_get also registers a device link. In general you shouldn't have to worry
about synchronization when using supplier-consumer APIs, as synchronization has
been taken care for you. Regulator APIs for example also handles device links.

If this isn't true.. Then I'll be a driver core design issue and not that of
drivers :)

I think sending this part with your fan driver would be a better idea, and we
shall see if Sashiko still complains :)

>
>> >
>> > True, and I don't have any issue in converting back to MMIO call and drop the conditional for
>> > error checking, but please consider the following, since the driver may be extended in the
>> > future to support more features:
>> >
>> > - regmap gives you free debugfs view on the registers, which may be useful to test
>> >   the new features.
>> 
>> Do you have any register that we want to access that is not part of the PWM
>> facility, other than tachometer?
>
> Not at the moment, no. But I don't see how this impact the debugfs usefulness.
>

I don't think having debugfs alone is a convincing reason to use regmap.. Most
of the users who use this driver won't care.

>> 
>> > - regmap_write/read may still return an error in case the passed register is not in range.
>> >   This will be trapped at runtime only, but could still be useful during development
>> 
>> I think this is rather a anti-feature. Having additional error paths for some
>> thing that never happens is not a good idea, especially that you basically get 0
>> coverage for these paths.
>
> Sure. Well this is true once the code is crystallized and tested, so it's somewhat
> still useful (only) during future development. But I got the point, and I agree.
>
>> 
>> You already know the shape of the register region, so the bounds checking
>> provided by regmap would be better served by an ahead-of-time check:
>> 
>>     #define RP1_PWM_REG_MAX (RP1_PWM_DUTY(RP1_PWM_NUM_PWMS) + 4)
>> 
>>     struct resource *res;
>>     base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
>>     if (IS_ERR(base))
>>         return PTR_ERR(base);
>> 
>>     if (resource_size(res) < RP1_PWM_REG_MAX) ...
>
> Fine for the probe method, but regmap_read/write also check for the range, for free.

Well, you have to handle the possibility of error, and the compiler needs to
generate bound checks, so it's not free?

A probe time check is good because once you checked that the register space is
large enough, you never have to check again for accesses.

Using regmap_read/write to provide the check will give a false sense of "things
are working" when code runs past the probe, but if, say, the device tree is
messed up. And it'll fail much later..

Best,
Gary



  reply	other threads:[~2026-09-24 18:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  9:58 [PATCH v9 0/3] Add RP1 PWM controller support Andrea della Porta
2026-09-18  9:59 ` [PATCH v9 1/3] dt-bindings: pwm: Add Raspberry Pi RP1 PWM controller Andrea della Porta
2026-09-18  9:59 ` [PATCH v9 2/3] pwm: rp1: Add RP1 PWM controller driver Andrea della Porta
2026-09-22 19:51   ` Gary Guo
2026-09-23 12:51     ` Andrea della Porta
2026-09-23 13:46       ` Gary Guo
2026-09-23 16:28         ` Andrea della Porta
2026-09-24 18:05           ` Gary Guo [this message]
2026-09-18  9:59 ` [PATCH v9 3/3] arm64: dts: broadcom: rpi-5: Add RP1 PWM node Andrea della Porta

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=DLNQUO0EQW7M.29SAT06RE6IOV@garyguo.net \
    --to=gary@garyguo.net \
    --cc=andrea.porta@suse.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=florian.fainelli@broadcom.com \
    --cc=julianbraha@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=mbrugger@suse.com \
    --cc=naush@raspberrypi.com \
    --cc=robh@kernel.org \
    --cc=sean@mess.org \
    --cc=svarbanov@suse.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox