All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>
Cc: wsa+renesas@sang-engineering.com, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v3 2/3] ptp: Add driver for R-Car Gen4
Date: Thu, 02 Jul 2026 09:06:54 +0000	[thread overview]
Message-ID: <20260702090654.E80891F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260701090607.1108208-3-niklas.soderlund+renesas@ragnatech.se>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The probe function leaks runtime PM references and leaves the device active if `ptp_clock_register()` fails.
- [High] The return value of `pm_runtime_get_sync()` is unchecked, which can lead to a synchronous external abort if powering the device fails.
- [High] The driver divides by the unchecked result of `clk_get_rate()`, risking a division by zero panic and potential type overflow.
- [Medium] The PTP clock is registered and exposed to user-space before the underlying hardware timer is enabled.
--

commit 523fe97d56330aedad6aa7c19dcf2bc206269fe3
Author: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
ptp: Add driver for R-Car Gen4

Add driver for the gPTP timer found on R-Car Gen4 devices. The timer is
system-wide and shared by different Ethernet devices on each Gen4
platform.

> diff --git a/drivers/ptp/ptp_rcar_gen4.c b/drivers/ptp/ptp_rcar_gen4.c
> new file mode 100644
> index 0000000000000..ab0be2431be8d
> --- /dev/null
> +++ b/drivers/ptp/ptp_rcar_gen4.c
[ ... ]
> +static int ptp_rcar_gen4_probe(struct platform_device *pdev)
> +{
[ ... ]
> +	priv->info = ptp_rcar_gen4_info;
> +
> +	/* Default timer increment in ns.
> +	 * bit[31:27] - integer
> +	 * bit[26:0]  - decimal
> +	 * increment[ns] = perid[ns] * 2^27 => (1ns * 2^27) / rate[hz]
> +	 */
> +	priv->default_addend =
> +		div_s64(1000000000LL << 27, clk_get_rate(priv->clk));

[Severity: High]
Could this lead to a division by zero if clk_get_rate() returns 0?

Also, since div_s64() takes an s32 divisor, would an unsigned long clock rate
overflow to a negative value for rates above 2.14 GHz?  Should this verify
the rate is non-zero and use div64_ul() instead?

> +
> +	pm_runtime_enable(dev);
> +	pm_runtime_get_sync(dev);
> +
> +	iowrite32(priv->default_addend, priv->base + PTPTIVC0_REG);

[Severity: High]
Does this need to check the return value of pm_runtime_get_sync()?

If the PM domain fails to power on and returns a negative error code,
unconditionally proceeding to write to the MMIO registers might cause a
synchronous external abort.

> +
> +	priv->clock = ptp_clock_register(&priv->info, dev);
> +	if (IS_ERR(priv->clock))
> +		return PTR_ERR(priv->clock);

[Severity: High]
If ptp_clock_register() fails, does this leave the PM usage counter
unbalanced?  It looks like this error path returns without calling
pm_runtime_put_sync() or pm_runtime_disable() to clean up the state
initialized earlier in ptp_rcar_gen4_probe().

[Severity: Medium]
Is there a race condition here?

By calling ptp_clock_register() before enabling the hardware timer on the
next line, is it possible for a fast user-space process to execute a gettime
or settime request on disabled hardware?

> +
> +	iowrite32(1, priv->base + PTPTMEC_REG);
> +
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260701090607.1108208-1-niklas.soderlund+renesas@ragnatech.se?part=2

  parent reply	other threads:[~2026-07-02  9:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  9:06 [PATCH net-next v3 0/3] ptp: Add driver for R-Car Gen4 gPTP timer Niklas Söderlund
2026-07-01  9:06 ` [PATCH net-next v3 1/3] dt-bindings: ptp: renesas,rcar-gen4-gptp: Add R-Car Gen4 Niklas Söderlund
2026-07-02  9:06   ` sashiko-bot
2026-07-01  9:06 ` [PATCH net-next v3 2/3] ptp: Add driver for " Niklas Söderlund
2026-07-01 21:47   ` Vadim Fedorenko
2026-07-02  8:46     ` Niklas Söderlund
2026-07-02  9:06   ` sashiko-bot [this message]
2026-07-01  9:06 ` [PATCH net-next v3 3/3] arm64: dts: renesas: r8a779g0: Add gPTP node Niklas Söderlund
2026-07-02  9:06   ` sashiko-bot

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=20260702090654.E80891F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /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.