All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mikko Perttunen" <mperttunen@nvidia.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v5 3/7] pwm: tegra: Avoid hard-coded max clock frequency
Date: Fri, 29 May 2026 03:28:19 +0000	[thread overview]
Message-ID: <20260529032819.C38631F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260529-t264-pwm-v5-3-7bf9e405a96a@nvidia.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Potential division by zero during probe due to unvalidated dynamically fetched clock rate.
- [High] Logic error in `dev_pm_opp_set_rate()` usage causes probe failure on devices with OPP tables.
--

commit 74520499a078af31d704c76e29fb2e41b43c4ecc
Author: Yi-Wei Wang <yiweiw@nvidia.com>

pwm: tegra: Avoid hard-coded max clock frequency

This commit changes the Tegra PWM driver to dynamically fetch the max
clock rate from the current parent clock using dev_pm_opp_set_rate()
and removes the hard-coded maximum frequencies from the SoC data.

> diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
> index f8c5495a56a66..303e2720034d2 100644
> --- a/drivers/pwm/pwm-tegra.c
> +++ b/drivers/pwm/pwm-tegra.c
[ ... ]
> @@ -303,7 +300,7 @@ static int tegra_pwm_probe(struct platform_device *pdev)
>  		return ret;
>  
>  	/* Set maximum frequency of the IP */
> -	ret = dev_pm_opp_set_rate(&pdev->dev, pc->soc->max_frequency);
> +	ret = dev_pm_opp_set_rate(&pdev->dev, ULONG_MAX);

[Severity: High]
Does setting the target frequency to ULONG_MAX work safely with OPP tables?

dev_pm_opp_set_rate() will round ULONG_MAX to the clock driver's absolute
maximum frequency. If a platform (such as Tegra30) has an OPP table where
the highest defined OPP is lower than this absolute maximum,
dev_pm_opp_set_rate() will fail to find a matching OPP and return -ERANGE.

Could this failure inadvertently abort the driver probe on platforms with
such OPP tables?

>  	if (ret < 0) {
>  		dev_err(&pdev->dev, "Failed to set max frequency: %d\n", ret);
>  		goto put_pm;
> @@ -318,7 +315,7 @@ static int tegra_pwm_probe(struct platform_device *pdev)
>  
>  	/* Set minimum limit of PWM period for the IP */
>  	pc->min_period_ns =
> -	    (NSEC_PER_SEC / (pc->soc->max_frequency >> TEGRA_PWM_DUTY_WIDTH)) + 1;
> +	    (NSEC_PER_SEC / (pc->clk_rate >> TEGRA_PWM_DUTY_WIDTH)) + 1;

[Severity: High]
Is it possible for pc->clk_rate to be less than 256 here?

If clk_get_rate() returns 0 (such as when the clock is unconfigured) or a
value less than 1 << TEGRA_PWM_DUTY_WIDTH, the right shift will evaluate to
0.

Could this lead to a division by zero panic during device probe?

>  
>  	pc->rst = devm_reset_control_get_exclusive(&pdev->dev, "pwm");
>  	if (IS_ERR(pc->rst)) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260529-t264-pwm-v5-0-7bf9e405a96a@nvidia.com?part=3

  reply	other threads:[~2026-05-29  3:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29  2:47 [PATCH v5 0/7] Tegra264 PWM support Mikko Perttunen
2026-05-29  2:47 ` [PATCH v5 1/7] dt-bindings: pwm: Document Tegra264 controller Mikko Perttunen
2026-05-29  2:47 ` [PATCH v5 2/7] pwm: tegra: Prefix driver-local macros and functions Mikko Perttunen
2026-05-29  2:47 ` [PATCH v5 3/7] pwm: tegra: Avoid hard-coded max clock frequency Mikko Perttunen
2026-05-29  3:28   ` sashiko-bot [this message]
2026-05-29  2:47 ` [PATCH v5 4/7] pwm: tegra: Modify read/write accessors for multi-register channel Mikko Perttunen
2026-05-29  2:47 ` [PATCH v5 5/7] pwm: tegra: Parametrize duty and scale field widths Mikko Perttunen
2026-05-29  4:05   ` sashiko-bot
2026-05-29  2:47 ` [PATCH v5 6/7] pwm: tegra: Add support for Tegra264 Mikko Perttunen
2026-05-29  4:30   ` sashiko-bot
2026-05-29  2:47 ` [PATCH v5 7/7] arm64: tegra: Add PWM controllers on Tegra264 Mikko Perttunen
2026-06-02  9:16 ` [PATCH v5 0/7] Tegra264 PWM support Jon Hunter

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=20260529032819.C38631F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=mperttunen@nvidia.com \
    --cc=robh@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 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.