public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: <Claudiu.Beznea@microchip.com>
To: <jonathanh@nvidia.com>, <lgirdwood@gmail.com>, <broonie@kernel.org>
Cc: <s.hauer@pengutronix.de>, <ttynkkynen@nvidia.com>,
	<linus.walleij@linaro.org>, <axel.lin@ingics.com>,
	<linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-tegra@vger.kernel.org>
Subject: Re: [PATCH v3 1/6] regulator: core: validate selector against linear_min_sel
Date: Wed, 25 Nov 2020 10:46:48 +0000	[thread overview]
Message-ID: <756a43cf-b7b5-d8a2-ae5c-89bdc3eb26ba@microchip.com> (raw)
In-Reply-To: <37ae7275-3c85-e94e-4ed1-95b6b901c2ed@nvidia.com>



On 24.11.2020 15:41, Jon Hunter wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> On 24/11/2020 11:14, Claudiu.Beznea@microchip.com wrote:
> 
> ...
> 
>> I would say that a solution would be to have a new helper to retrieve the
>> linear_min_sel (e.g. regulator_min_sel()) and use this for all the
>> consumers of regulator_list_voltage() and the other APIs that patch
>> "regulator: core: validate selector against linear_min_sel" has changed
>> (regulator_list_voltage_table(), regulator_set_voltage_time()). With this
>> change the loop in find_vdd_map_entry_exact() should be b/w
>> regulator_min_sel() and regulator_count_voltages().
>>
>> Maybe Mark has a better solution for this.
> 
> 
> By the way, I don't think that Tegra is alone here. I see some other
> drivers doing some similar things [0][1][2] and so I am wondering if
> this is going to be a problem for a few drivers.
> 

As far as I can tell most of the regulator_list_voltage() consumers are
checking the return value against a [min_uV, max_uV] range or if the return
value is a negative error code or zero. The consumers are looking a
selector that respect the above rule for the entire [0,
regulator_count_voltages()] range (I have to double check for the rest of
functions modified by my patch). In case of clk-dfll.c the
find_vdd_map_entry_exact() returns if it finds the 1st invalid selector:

	n_voltages = regulator_count_voltages(td->vdd_reg);
	for (i = 0; i < n_voltages; i++) {
		reg_uV = regulator_list_voltage(td->vdd_reg, i);
		if (reg_uV < 0)
			break;

		reg_volt_id = reg_uV / td->soc->alignment.step_uv;

		if (align_step == reg_volt_id)
			return i;
	}

Maybe it would be better if the loop continues in case reg_uV is negative
or zero? (the zero case is good for this function as it will make the
(align_step == reg_volt_id) to be false). But as Mark said in the previous
email, there could be regulators with gaps in between min_sel and n_voltages.

With the previous code it seems it worked because the
regulator_list_voltage() calls the as3722's list_voltage which is
regulator_list_voltage_linear() which checks the selector against
min_selector and returns zero in case the selector is lower than the
min_selector. Please correct me if I'm wrong.

Anyway, I will prepare a fix for my previous patch to return zero in case
the regulator_count_voltages() receives an invalid selector. That should
also fix the case with this driver.

Thank you,
Claudiu

> Jon
> 
> [0]
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/mmc/core/regulator.c#n61
> [1]
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/cpufreq/s3c2416-cpufreq.c#n263
> [2]
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/leds/leds-regulator.c#n29
> 
> --
> nvpublic
> 

  reply	other threads:[~2020-11-25 10:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 15:21 [PATCH v3 0/6] regulator: mcp16502: add support for ramp delay Claudiu Beznea
2020-11-13 15:21 ` [PATCH v3 1/6] regulator: core: validate selector against linear_min_sel Claudiu Beznea
2020-11-24  9:36   ` Jon Hunter
2020-11-24 11:14     ` Claudiu.Beznea
2020-11-24 13:41       ` Jon Hunter
2020-11-25 10:46         ` Claudiu.Beznea [this message]
2020-11-24 14:11       ` Mark Brown
2020-11-25 11:34         ` [PATCH] regulator: core: return zero for selectors lower than linear_min_sel Claudiu Beznea
2020-11-25 17:03           ` Mark Brown
2020-11-13 15:21 ` [PATCH v3 2/6] regulator: core: do not continue if selector match Claudiu Beznea
2020-11-13 16:11   ` Mark Brown
2020-11-13 15:21 ` [PATCH v3 3/6] regulator: mcp16502: add linear_min_sel Claudiu Beznea
2020-11-13 15:21 ` [PATCH v3 4/6] regulator: mcp16502: adapt for get/set on other registers Claudiu Beznea
2020-11-13 15:21 ` [PATCH v3 5/6] regulator: mcp16502: add support for ramp delay Claudiu Beznea
2020-11-13 15:21 ` [PATCH v3 6/6] regulator: mcp16502: remove void documentation of struct mcp16502 Claudiu Beznea
2020-11-13 17:14 ` [PATCH v3 0/6] regulator: mcp16502: add support for ramp delay Mark Brown
2020-12-01 13:57 ` Mark Brown

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=756a43cf-b7b5-d8a2-ae5c-89bdc3eb26ba@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=axel.lin@ingics.com \
    --cc=broonie@kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=lgirdwood@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=ttynkkynen@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox