From: sashiko-bot@kernel.org
To: "Hal Feng" <hal.feng@starfivetech.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v24 2/2] pwm: Add OpenCores PTC PWM driver
Date: Sat, 07 Nov 2026 03:36:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-202533@kernel.org> (raw)
In-Reply-To: <20261107031251.98972-3-hal.feng@starfivetech.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] pwm: ocores: clk_get_rate() called before enabling clock in
ocores_pwm_probe()
- [Low] pwm: ocores: unlocked and pre-enable clk_get_rate() in
ocores_pwm_probe()
--
commit 33c73933621c3feed0e1d70460454bd0821561cc
Author: Hal Feng <hal.feng@starfivetech.com>
pwm: Add OpenCores PTC PWM driver
This commit adds a PWM driver for the OpenCores PTC IP core.
> diff --git a/drivers/pwm/pwm-ocores.c b/drivers/pwm/pwm-ocores.c
> new file mode 100644
> index 0000000000000..4c7e87cb009f6
> --- /dev/null
> +++ b/drivers/pwm/pwm-ocores.c
[ ... ]
> +static int ocores_pwm_probe(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct ocores_pwm_device *ddata;
> + struct pwm_chip *chip;
> + int ret;
> +
> + chip = devm_pwmchip_alloc(dev, 1, sizeof(*ddata));
> + if (IS_ERR(chip))
> + return PTR_ERR(chip);
> +
> + chip->ops = &ocores_pwm_ops;
> + ddata = pwmchip_get_drvdata(chip);
> +
> + ddata->base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(ddata->base))
> + return dev_err_probe(dev, PTR_ERR(ddata->base),
> + "Failed to map IO resources\n");
> +
> + ddata->clk = devm_clk_get(dev, NULL);
> + if (IS_ERR(ddata->clk))
> + return dev_err_probe(dev, PTR_ERR(ddata->clk),
> + "Failed to get clock\n");
> +
> + ddata->clk_rate = clk_get_rate(ddata->clk);
> + if (!ddata->clk_rate || ddata->clk_rate > NSEC_PER_SEC)
> + return dev_err_probe(dev, -EINVAL,
> + "Invalid clock rate: %lu\n", ddata->clk_rate);
[Severity: Low]
Does caching ddata->clk_rate here without locking the clock rate via
devm_clk_rate_exclusive_get() and after enabling the clock leave the
driver vulnerable to an invalid initial rate or runtime clock rate
changes? If the parent clock rate changes after probe, ocores_pwm_apply()
and ocores_pwm_get_state() will compute inaccurate periods and duty cycles
from the stale rate, or violate the NSEC_PER_SEC bound.
> +
> + ddata->rst = devm_reset_control_get_optional_shared(dev, NULL);
> + if (IS_ERR(ddata->rst))
> + return dev_err_probe(dev, PTR_ERR(ddata->rst),
> + "Failed to get reset\n");
> +
> + platform_set_drvdata(pdev, ddata);
> +
> + ret = ocores_pwm_runtime_resume(dev);
> + if (ret)
> + return ret;
[Severity: Low]
Should clk_get_rate(ddata->clk) be called after
ocores_pwm_runtime_resume() enables the clock? The clk API only
guarantees a valid rate once the clock is enabled, so querying it before
clk_prepare_enable() can return 0 (failing probe with -EINVAL) or a stale
rate on clock providers that compute their rate on enable.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261107031251.98972-1-hal.feng@starfivetech.com?part=2
prev parent reply other threads:[~2026-11-07 3:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 3:12 [PATCH v24 0/2] Add OpenCores PTC PWM support Hal Feng
2026-11-07 3:12 ` [PATCH v24 1/2] dt-bindings: pwm: opencores: Update compatibles, examples and maintainers Hal Feng
2026-11-07 3:12 ` [PATCH v24 2/2] pwm: Add OpenCores PTC PWM driver Hal Feng
2026-11-07 3:36 ` sashiko-bot [this message]
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=sashiko-outbox-202533@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hal.feng@starfivetech.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox