Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ali Rouhi" <arouhi@sitime.com>
Cc: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v17 11/13] dpll: sit9531x: add support to adjust output phase
Date: Wed, 02 Dec 2026 23:52:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-246777@kernel.org> (raw)
In-Reply-To: <20261201235202.97645-12-arouhi@sitime.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dpll: sit9531x: missed error-path notifications on output
  phase adjust
--

commit f7ad586c8e835e06e0aa7cf8709834f57ca7e16b
Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>

dpll: sit9531x: add support to adjust output phase

This commit adds output phase-adjust get and set support to the sit9531x
DPLL driver, including delay quantization, re-timing across output rate
changes, and poll/removal retries for pending phase updates and flushes.

> diff --git a/drivers/dpll/sit9531x/dpll.c b/drivers/dpll/sit9531x/dpll.c
> index b0403c0bc1320..502b25f22be4a 100644
> --- a/drivers/dpll/sit9531x/dpll.c
> +++ b/drivers/dpll/sit9531x/dpll.c

[ ... ]

> @@ -790,12 +794,119 @@ sit9531x_dpll_output_pin_state_on_dpll_set(const struct dpll_pin *pin,
>  	return rc;
>  }
>  
> +/*
> + * Report the delay as programmed after quantization, including one whose flush
> + * is pending. An output whose PLL has no valid Fvco has no delay value.
> + */
> +static int
> +sit9531x_dpll_output_pin_phase_adjust_get(const struct dpll_pin *pin,
> +					  void *pin_priv,
> +					  const struct dpll_device *dpll,
> +					  void *dpll_priv, s32 *phase_adjust,
> +					  struct netlink_ext_ack *extack)
> +{
> +	struct sit9531x_dpll_pin *dpin = pin_priv;
> +	struct sit9531x_dpll *sitdpll = dpll_priv;
> +	struct sit9531x_dev *sitdev = sitdpll->dev;
> +	s64 phase_adj;
> +	bool none;
> +	int rc;
> +
> +	mutex_lock(&sitdev->multiop_lock);
> +	/*
> +	 * A pending re-time has no delay to report: its bytes are for the old
> +	 * rate or wait for their small-change update. With no value the core
> +	 * passes every request on, the old delay included.
> +	 */
> +	if (sitdev->out[dpin->id].retime_pending) {
> +		mutex_unlock(&sitdev->multiop_lock);
> +		return -ENODATA;
> +	}
> +	if (sitdev->out[dpin->id].phase_stale) {
> +		bool beyond;
> +		s64 phase_ps;
> +
> +		rc = sit9531x_output_phase_read(sitdev, dpin->id, &phase_ps,
> +						&beyond);
> +		/* -ENODATA: no delay value; another error fails the pin dump */
> +		if (rc && rc != -ENODATA) {
> +			mutex_unlock(&sitdev->multiop_lock);
> +			dev_warn_ratelimited(sitdev->dev,
> +					     "out%u: delay not read back: %d\n",
> +					     dpin->id, rc);
> +			return -ENODATA;
> +		}
> +		sitdev->out[dpin->id].phase_none = rc == -ENODATA;
> +		if (!rc) {
> +			sitdev->out[dpin->id].phase_adj = phase_ps;
> +			sitdev->out[dpin->id].phase_armed = !beyond && phase_ps;
> +		}
> +		sitdev->out[dpin->id].phase_stale = false;
> +	}
> +	none = sit9531x_out_state_get(sitdev, dpin->id)->phase_none;
> +	phase_adj = sit9531x_out_state_get(sitdev, dpin->id)->phase_adj;
> +	mutex_unlock(&sitdev->multiop_lock);
> +
> +	/*
> +	 * A delay found on the part is reported as found, also beyond the
> +	 * advertised range, which bounds a request; one beyond the s32
> +	 * attribute is left out.
> +	 */
> +	if (none || phase_adj > S32_MAX)
> +		return -ENODATA;
> +	*phase_adjust = phase_adj;
> +
> +	return 0;
> +}
> +
> +/* Program the per-output PRG_RST_DELAY registers */
> +static int
> +sit9531x_dpll_output_pin_phase_adjust_set(const struct dpll_pin *pin,
> +					  void *pin_priv,
> +					  const struct dpll_device *dpll,
> +					  void *dpll_priv, s32 phase_adjust,
> +					  struct netlink_ext_ack *extack)
> +{
> +	struct sit9531x_dpll_pin *dpin = pin_priv;
> +	struct sit9531x_dpll *sitdpll = dpll_priv;
> +	struct sit9531x_dev *sitdev = sitdpll->dev;
> +	const struct sit9531x_out *out;
> +	bool moved;
> +	s64 was;
> +	int rc;
> +
> +	out = sit9531x_out_state_get(sitdev, dpin->id);
> +
> +	mutex_lock(&sitdev->multiop_lock);
> +	was = out->phase_adj;
> +	rc = sit9531x_output_phase_adjust_set(sitdev, dpin->id, phase_adjust);
> +	moved = out->phase_adj != was || out->phase_stale;
> +	mutex_unlock(&sitdev->multiop_lock);
> +
> +	if (rc) {
> +		struct dpll_pin *dpll_pin;
> +
> +		NL_SET_ERR_MSG(extack, "Phase adjust failed");
> +		/* The core notifies only a request that succeeded */
> +		dpll_pin = READ_ONCE(dpin->dpll_pin);
> +		if (moved && dpll_pin && __dpll_pin_change_ntf(dpll_pin)) {
> +			mutex_lock(&sitdev->multiop_lock);
> +			sitdev->out[dpin->id].ntf_pending = true;
> +			mutex_unlock(&sitdev->multiop_lock);
> +		}
> +	}
> +
> +	return rc;
> +}

[Severity: Medium]
Can the error-path notification in sit9531x_dpll_output_pin_phase_adjust_set()
(and sit9531x_dpll_output_pin_frequency_set()) leave out->phase_stale set
without arming out->ntf_pending?

When a setter fails after touching the hardware registers, out->phase_stale is
set and the error path calls __dpll_pin_change_ntf(). That invokes
sit9531x_dpll_output_pin_phase_adjust_get(), which tries to refresh
out->phase_stale via sit9531x_output_phase_read(). If that I2C read also fails,
sit9531x_dpll_output_pin_phase_adjust_get() leaves out->phase_stale set and
returns -ENODATA. Because dpll_msg_add_pin_phase_adjust() treats -ENODATA as 0
and omits the attribute, __dpll_pin_change_ntf() returns 0, so out->ntf_pending
is never armed and sit9531x_dpll_output_ntf_pending() will not retry the
notification once the bus recovers.

Also, moved only compares out->phase_adj != was || out->phase_stale, without
checking whether out->phase_none or out->retime_pending changed. If one of
those flags was set while out->phase_adj still held its previous value, and a
new request latches a delay equal to was (clearing phase_none and
retime_pending) before failing at the phase flush, moved is false and no
notification is sent even though the phase-adjust attribute transitioned from
absent to present.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201235202.97645-1-arouhi@sitime.com?part=11

  reply	other threads:[~2026-12-02 23:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 23:52 [PATCH net-next v17 00/13] dpll: add SiTime SiT9531x DPLL clock driver Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 01/13] dpll: omit pin phase attributes the driver has no value for Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 02/13] dt-bindings: vendor-prefixes: add SiTime Corporation Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 03/13] dt-bindings: dpll: add SiTime SiT95316 clock generator Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 04/13] dpll: add basic SiTime SiT9531x support Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 06/13] dpll: sit9531x: register DPLL devices and pins Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 05/13] dpll: sit9531x: read DPLL types and pin properties from system firmware Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 07/13] dpll: sit9531x: implement input pin state on a DPLL Ali Rouhi
2026-12-02 23:52   ` sashiko-bot
2026-12-01 23:52 ` [PATCH net-next v17 08/13] dpll: sit9531x: add support to get and set priority on input pins Ali Rouhi
2026-12-02 23:52   ` sashiko-bot
2026-12-01 23:52 ` [PATCH net-next v17 10/13] dpll: sit9531x: implement output pin state on a DPLL Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 09/13] dpll: sit9531x: add support to get and set frequency on pins Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 12/13] dpll: sit9531x: add support to get phase offset on the connected input Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 11/13] dpll: sit9531x: add support to adjust output phase Ali Rouhi
2026-12-02 23:52   ` sashiko-bot [this message]
2026-12-01 23:52 ` [PATCH net-next v17 13/13] dpll: sit9531x: model the inter-PLL sync line as a pair of pins Ali Rouhi
2026-12-02 23:53   ` 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=sashiko-outbox-246777@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arouhi@sitime.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --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