Skip to content

Commit 4e1e211

Browse files
keeskrzk
authored andcommitted
pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct exynos_muxed_weint_data. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier. Cc: Tomasz Figa <tomasz.figa@gmail.com> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Cc: Sylwester Nawrocki <s.nawrocki@samsung.com> Cc: Alim Akhtar <alim.akhtar@samsung.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-samsung-soc@vger.kernel.org Cc: linux-gpio@vger.kernel.org Cc: linux-hardening@vger.kernel.org Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Link: https://lore.kernel.org/r/20231006201707.work.405-kees@kernel.org Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
1 parent 0bb80ec commit 4e1e211

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

drivers/pinctrl/samsung/pinctrl-exynos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
616616
+ muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL);
617617
if (!muxed_data)
618618
return -ENOMEM;
619+
muxed_data->nr_banks = muxed_banks;
619620

620621
irq_set_chained_handler_and_data(irq, exynos_irq_demux_eint16_31,
621622
muxed_data);
@@ -628,7 +629,6 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
628629

629630
muxed_data->banks[idx++] = bank;
630631
}
631-
muxed_data->nr_banks = muxed_banks;
632632

633633
return 0;
634634
}

drivers/pinctrl/samsung/pinctrl-exynos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct exynos_weint_data {
159159
*/
160160
struct exynos_muxed_weint_data {
161161
unsigned int nr_banks;
162-
struct samsung_pin_bank *banks[];
162+
struct samsung_pin_bank *banks[] __counted_by(nr_banks);
163163
};
164164

165165
int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d);

0 commit comments

Comments
 (0)