Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: regulator: fix error case in regulator_supported_voltages() + split asserts #6784

Merged
merged 2 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 16 additions & 12 deletions core/drivers/regulator/regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,30 @@ TEE_Result regulator_supported_voltages(struct regulator *regulator,
struct regulator_voltages_desc **desc,
const int **levels)
{
assert(regulator && desc && levels);
TEE_Result res = TEE_ERROR_NOT_SUPPORTED;

if (regulator->ops->supported_voltages) {
TEE_Result res = TEE_ERROR_GENERIC;
assert(regulator && desc && levels);

if (regulator->ops->supported_voltages)
res = regulator->ops->supported_voltages(regulator, desc,
levels);
if (res != TEE_ERROR_NOT_SUPPORTED)
return res;
} else {
if (res == TEE_ERROR_NOT_SUPPORTED) {
*desc = &regulator->voltages_fallback.desc;
*levels = regulator->voltages_fallback.levels;
} else if (res) {
return res;
}

assert(((*desc)->type == VOLTAGE_TYPE_FULL_LIST &&
(*levels)[0] >= regulator->min_uv && (*desc)->num_levels &&
(*levels)[(*desc)->num_levels - 1] <= regulator->max_uv) ||
((*desc)->type == VOLTAGE_TYPE_INCREMENT &&
(*levels)[0] >= regulator->min_uv &&
(*levels)[1] <= regulator->max_uv));
if ((*desc)->type == VOLTAGE_TYPE_FULL_LIST) {
assert((*desc)->num_levels);
assert((*levels)[0] >= regulator->min_uv);
assert((*levels)[(*desc)->num_levels - 1] <= regulator->max_uv);
} else if ((*desc)->type == VOLTAGE_TYPE_INCREMENT) {
assert((*levels)[0] >= regulator->min_uv);
assert((*levels)[1] <= regulator->max_uv);
} else {
assert(0);
}

return TEE_SUCCESS;
}
Expand Down