Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit e314e15

Browse files
keesbroonie
authored andcommitted
regulator: s5m8767: Bounds check id indexing into arrays
The compiler has no way to know if "id" is within the array bounds of the regulators array. Add a check for this and a build-time check that the regulators and reg_voltage_map arrays are sized the same. Seen with GCC 13: ../drivers/regulator/s5m8767.c: In function 's5m8767_pmic_probe': ../drivers/regulator/s5m8767.c:936:35: warning: array subscript [0, 36] is outside array bounds of 'struct regulator_desc[37]' [-Warray-bounds=] 936 | regulators[id].vsel_reg = | ~~~~~~~~~~^~~~ Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Cc: Liam Girdwood <lgirdwood@gmail.com> Cc: Mark Brown <broonie@kernel.org> Cc: linux-samsung-soc@vger.kernel.org Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20230128005358.never.313-kees@kernel.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 4fd8bce commit e314e15

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/regulator/s5m8767.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,10 +923,14 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
923923

924924
for (i = 0; i < pdata->num_regulators; i++) {
925925
const struct sec_voltage_desc *desc;
926-
int id = pdata->regulators[i].id;
926+
unsigned int id = pdata->regulators[i].id;
927927
int enable_reg, enable_val;
928928
struct regulator_dev *rdev;
929929

930+
BUILD_BUG_ON(ARRAY_SIZE(regulators) != ARRAY_SIZE(reg_voltage_map));
931+
if (WARN_ON_ONCE(id >= ARRAY_SIZE(regulators)))
932+
continue;
933+
930934
desc = reg_voltage_map[id];
931935
if (desc) {
932936
regulators[id].n_voltages =

0 commit comments

Comments
 (0)