Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Praveen Talari" <praveen.talari@oss.qualcomm.com>
Cc: linux-serial@vger.kernel.org
Subject: Re: [PATCH v2 2/9] soc: qcom: geni-se: Populate clk_perf_tbl with SE source clock frequencies from perf OPP table
Date: Thu, 27 Aug 2026 18:16:59 +0000	[thread overview]
Message-ID: <20260827181700.53B941F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827-derive_clk_perf_tbl_from_perf_domain_opp_table-v2-2-091697dbeb02@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Populating `clk_perf_tbl` with OPP performance levels instead of frequencies breaks clock divider math, introduces division-by-zero risks, and fails `dev_pm_opp_set_rate()`.
- [High] Fragile OPP iteration loop will fail the probe if the OPP table contains duplicate levels.
--

commit f430a1f0dd5802c00d71aa7a1d541115aa32fe57
Author: Praveen Talari <praveen.talari@oss.qualcomm.com>

soc: qcom: geni-se: Populate clk_perf_tbl with SE source clock frequencies from perf OPP table

This commit populates clk_perf_tbl with SE source clock frequencies
from the perf OPP table. It treats the OPP table as the actual SE hardware
supported source clock frequencies, allowing protocol drivers to compute
the correct source clock and divider.

> diff --git a/drivers/soc/qcom/qcom-geni-se.c b/drivers/soc/qcom/qcom-geni-se.c
> index 873bfbd6b2b7b..447b9cc6babf6 100644
> --- a/drivers/soc/qcom/qcom-geni-se.c
> +++ b/drivers/soc/qcom/qcom-geni-se.c
[ ... ]
> @@ -1175,6 +1181,31 @@ int geni_se_domain_attach(struct geni_se *se)
>  	else if (ret < 0)
>  		return ret;
>  
> +	perf_dev = se->pd_list->pd_devs[DOMAIN_IDX_PERF];
> +
> +	num_opps = dev_pm_opp_get_opp_count(perf_dev);
> +	if (num_opps < 0)
> +		return num_opps;
> +	if (num_opps == 0)
> +		return -ENODEV;
> +
> +	se->clk_perf_tbl = devm_kcalloc(se->dev, num_opps,
> +					sizeof(*se->clk_perf_tbl),
> +					GFP_KERNEL);
> +	if (!se->clk_perf_tbl)
> +		return -ENOMEM;
> +
> +	for (i = 0, level = 0; i < num_opps; i++, level++) {
> +		opp = dev_pm_opp_find_level_ceil(perf_dev, &level);
> +		if (IS_ERR(opp))
> +			return PTR_ERR(opp);

[Severity: High]
Does this iteration loop safely handle duplicate or missing OPP levels?

If the OPP table contains duplicate levels (e.g., same performance state but
different voltages), or if opp-level is unpopulated for some entries,
dev_pm_opp_find_level_ceil() will skip the duplicates.

This means the loop will run out of unique levels before 'i' reaches
'num_opps', returning -ERANGE or -ENODEV and failing the entire GENI SE probe.

[Severity: Critical]
Does fetching the OPP performance level here instead of the clock frequency
break the clock divider math later on?

When this loop uses dev_pm_opp_find_level_ceil() instead of
dev_pm_opp_find_freq_ceil(), it retrieves abstract performance levels
(which can be 0 for OFF/minimum states) rather than actual Hz frequencies.

> +
> +		se->clk_perf_tbl[i] = level;

These performance levels are then stored in se->clk_perf_tbl, which is meant
for Hz frequencies.

When protocol drivers call geni_se_clk_freq_match() to configure their source
clock, the following math is used:

	divider = DIV_ROUND_UP(tbl[i], req_freq);
	new_delta = req_freq - tbl[i] / divider;

If a performance level in tbl[i] is 0, 'divider' evaluates to 0, which leads
to a divide-by-zero kernel panic.

Even if the level is non-zero, it is treated as a tiny frequency, causing
dev_pm_opp_set_rate() to either fail with -ERANGE or force the clock to its
minimum state, breaking serial communication.

Should this use dev_pm_opp_find_freq_ceil() to populate the table with
opp-hz instead?

> +		dev_pm_opp_put(opp);
> +	}
> +	se->num_clk_levels = num_opps;
> +	se->has_opp = true;
>  
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260827-derive_clk_perf_tbl_from_perf_domain_opp_table-v2-0-091697dbeb02@oss.qualcomm.com?part=2

  reply	other threads:[~2026-08-27 18:17 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 17:59 [PATCH v2 0/9] soc: qcom: geni: Derive SE clock configuration from OPP table on SA8255P Praveen Talari
2026-08-27 17:59 ` [PATCH v2 1/9] pmdomain: arm: Fix -EINVAL from scmi_pd_set_perf_state() on state 0 Praveen Talari
2026-08-27 18:16   ` sashiko-bot
2026-09-01 14:31   ` Ulf Hansson
2026-08-27 17:59 ` [PATCH v2 2/9] soc: qcom: geni-se: Populate clk_perf_tbl with SE source clock frequencies from perf OPP table Praveen Talari
2026-08-27 18:16   ` sashiko-bot [this message]
2026-08-27 17:59 ` [PATCH v2 3/9] soc: qcom: geni-se: Add helper to set SE clock rate via OPP Praveen Talari
2026-08-27 18:14   ` sashiko-bot
2026-09-04  9:01   ` Konrad Dybcio
2026-08-27 17:59 ` [PATCH v2 4/9] soc: qcom: geni-se: Remove OPP rate reset from resource deactivation Praveen Talari
2026-08-27 18:14   ` sashiko-bot
2026-09-04  8:49   ` Konrad Dybcio
2026-09-11 17:13     ` Praveen Talari
2026-08-27 17:59 ` [PATCH v2 5/9] serial: qcom-geni: Use geni_se_set_rate() for source clock configuration Praveen Talari
2026-08-27 18:12   ` sashiko-bot
2026-08-27 17:59 ` [PATCH v2 6/9] spi: qcom-geni: Use geni_se_set_rate() for setting source clock frequency Praveen Talari
2026-08-27 18:12   ` sashiko-bot
2026-08-27 17:59 ` [PATCH v2 7/9] i2c: qcom-geni: Vote for SE clock rate using OPP Praveen Talari
2026-08-27 18:11   ` sashiko-bot
2026-09-04  8:52   ` Konrad Dybcio
2026-09-11 17:42     ` Praveen Talari
2026-08-27 17:59 ` [PATCH v2 8/9] i2c: qcom-geni: Use common GENI resource initialization helper Praveen Talari
2026-08-27 18:16   ` sashiko-bot
2026-08-27 17:59 ` [PATCH v2 9/9] i2c: qcom-geni: Use geni_se_set_rate() for setting source clock frequency Praveen Talari
2026-08-27 18:25   ` sashiko-bot
2026-09-01 14:52 ` [PATCH v2 0/9] soc: qcom: geni: Derive SE clock configuration from OPP table on SA8255P Ulf Hansson
2026-09-01 16:48   ` Praveen Talari
2026-09-04  7:56     ` Ulf Hansson
2026-09-04  9:00       ` Konrad Dybcio
2026-09-11 17:33         ` Praveen Talari
2026-09-09  6:32       ` Praveen Talari

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=20260827181700.53B941F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=praveen.talari@oss.qualcomm.com \
    --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