From: Claudiu Beznea <claudiu.beznea@microchip.com> To: <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>, Claudiu Beznea <claudiu.beznea@microchip.com> Subject: [PATCH v2 1/6] regulator: core: validate selector against linear_min_sel Date: Wed, 11 Nov 2020 11:06:13 +0200 [thread overview] Message-ID: <1605085578-6783-2-git-send-email-claudiu.beznea@microchip.com> (raw) In-Reply-To: <1605085578-6783-1-git-send-email-claudiu.beznea@microchip.com> There are regulators who's min selector is not zero. Selectors loops (looping b/w zero and regulator::desc::n_voltages) might throw errors because invalid selectors are used (lower than regulator::desc::linear_min_sel). For this situations validate selectors against regulator::desc::linear_min_sel. Fixes: 3a40cfc36bb3d ("regulator: core: create unlocked version of regulator_list_voltage") Fixes: 04eca28cde52c ("regulator: Add helpers for low-level register access") Fixes: 88cd222b259d6 ("regulator: provide consumer interface for fall/rise time") Fixes: d295f7670127e ("regulator: core: Move list_voltage_{linear,linear_range,table} to helpers.c") Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> --- drivers/regulator/core.c | 9 +++++++-- drivers/regulator/helpers.c | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 2e1ea18221ef..1d0d35f14f37 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2958,7 +2958,8 @@ static int _regulator_list_voltage(struct regulator_dev *rdev, return rdev->desc->fixed_uV; if (ops->list_voltage) { - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; if (lock) regulator_lock(rdev); @@ -3109,7 +3110,8 @@ int regulator_list_hardware_vsel(struct regulator *regulator, struct regulator_dev *rdev = regulator->rdev; const struct regulator_ops *ops = rdev->desc->ops; - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap) return -EOPNOTSUPP; @@ -4032,6 +4034,9 @@ int regulator_set_voltage_time(struct regulator *regulator, for (i = 0; i < rdev->desc->n_voltages; i++) { /* We only look for exact voltage matches here */ + if (i < rdev->desc->linear_min_sel) + continue; + voltage = regulator_list_voltage(regulator, i); if (voltage < 0) return -EINVAL; diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index e4bb09bbd3fa..974f1a63993d 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -647,7 +647,8 @@ int regulator_list_voltage_table(struct regulator_dev *rdev, return -EINVAL; } - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; return rdev->desc->volt_table[selector]; -- 2.7.4
WARNING: multiple messages have this Message-ID (diff)
From: Claudiu Beznea <claudiu.beznea@microchip.com> To: <lgirdwood@gmail.com>, <broonie@kernel.org> Cc: axel.lin@ingics.com, s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, Claudiu Beznea <claudiu.beznea@microchip.com>, ttynkkynen@nvidia.com, linus.walleij@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 1/6] regulator: core: validate selector against linear_min_sel Date: Wed, 11 Nov 2020 11:06:13 +0200 [thread overview] Message-ID: <1605085578-6783-2-git-send-email-claudiu.beznea@microchip.com> (raw) In-Reply-To: <1605085578-6783-1-git-send-email-claudiu.beznea@microchip.com> There are regulators who's min selector is not zero. Selectors loops (looping b/w zero and regulator::desc::n_voltages) might throw errors because invalid selectors are used (lower than regulator::desc::linear_min_sel). For this situations validate selectors against regulator::desc::linear_min_sel. Fixes: 3a40cfc36bb3d ("regulator: core: create unlocked version of regulator_list_voltage") Fixes: 04eca28cde52c ("regulator: Add helpers for low-level register access") Fixes: 88cd222b259d6 ("regulator: provide consumer interface for fall/rise time") Fixes: d295f7670127e ("regulator: core: Move list_voltage_{linear,linear_range,table} to helpers.c") Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> --- drivers/regulator/core.c | 9 +++++++-- drivers/regulator/helpers.c | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 2e1ea18221ef..1d0d35f14f37 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2958,7 +2958,8 @@ static int _regulator_list_voltage(struct regulator_dev *rdev, return rdev->desc->fixed_uV; if (ops->list_voltage) { - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; if (lock) regulator_lock(rdev); @@ -3109,7 +3110,8 @@ int regulator_list_hardware_vsel(struct regulator *regulator, struct regulator_dev *rdev = regulator->rdev; const struct regulator_ops *ops = rdev->desc->ops; - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; if (ops->set_voltage_sel != regulator_set_voltage_sel_regmap) return -EOPNOTSUPP; @@ -4032,6 +4034,9 @@ int regulator_set_voltage_time(struct regulator *regulator, for (i = 0; i < rdev->desc->n_voltages; i++) { /* We only look for exact voltage matches here */ + if (i < rdev->desc->linear_min_sel) + continue; + voltage = regulator_list_voltage(regulator, i); if (voltage < 0) return -EINVAL; diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index e4bb09bbd3fa..974f1a63993d 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -647,7 +647,8 @@ int regulator_list_voltage_table(struct regulator_dev *rdev, return -EINVAL; } - if (selector >= rdev->desc->n_voltages) + if (selector >= rdev->desc->n_voltages || + selector < rdev->desc->linear_min_sel) return -EINVAL; return rdev->desc->volt_table[selector]; -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2020-11-11 9:07 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-11-11 9:06 [PATCH v2 0/6] regulator: mcp16502: add support for ramp delay Claudiu Beznea 2020-11-11 9:06 ` Claudiu Beznea 2020-11-11 9:06 ` Claudiu Beznea [this message] 2020-11-11 9:06 ` [PATCH v2 1/6] regulator: core: validate selector against linear_min_sel Claudiu Beznea 2020-11-11 9:06 ` [PATCH v2 2/6] regulator: core: do not continue if selector match Claudiu Beznea 2020-11-11 9:06 ` Claudiu Beznea 2020-11-11 9:06 ` [PATCH v2 3/6] regulator: mcp16502: add linear_min_sel Claudiu Beznea 2020-11-11 9:06 ` Claudiu Beznea 2020-11-11 9:06 ` [PATCH v2 4/6] regulator: mcp16502: adapt for get/set on other registers Claudiu Beznea 2020-11-11 9:06 ` Claudiu Beznea 2020-11-11 9:06 ` [PATCH v2 5/6] regulator: mcp16502: add support for ramp delay Claudiu Beznea 2020-11-11 9:06 ` Claudiu Beznea 2020-11-13 7:41 ` kernel test robot 2020-11-13 7:41 ` kernel test robot 2020-11-13 7:41 ` kernel test robot 2020-11-11 9:06 ` [PATCH v2 6/6] regulator: mcp16502: remove void documentation of struct mcp16502 Claudiu Beznea 2020-11-11 9:06 ` Claudiu Beznea 2020-11-13 17:14 ` [PATCH v2 0/6] regulator: mcp16502: add support for ramp delay Mark Brown 2020-11-13 17:14 ` 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=1605085578-6783-2-git-send-email-claudiu.beznea@microchip.com \ --to=claudiu.beznea@microchip.com \ --cc=axel.lin@ingics.com \ --cc=broonie@kernel.org \ --cc=lgirdwood@gmail.com \ --cc=linus.walleij@linaro.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@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: linkBe 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.