2024-06-02 16:13:40

by Erick Archer

[permalink] [raw]
Subject: [PATCH 0/2] atmel: at76c50x: improve code robustness

Hi,

This series of patches attempts to improve the at76c50x code
robustness.

In the first patch, it is preferred to use sizeof(*pointer) instead
of sizeof(type) due to the type of the variable can change and one
needs not change the former (unlike the latter).

The second patch is an effort to get rid of all multiplications
from allocation functions in order to prevent integer overflows
[1][2]. As the "struct at76_command" ends in a flexible array the
preferred way in the kernel is to use the struct_size() helper to
do the arithmetic instead of the calculation "size + count" in the
kmalloc() function.

At the same time, 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).

This way, the code is more readable and safer.

Regards,
Erick

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
Link: https://github.com/KSPP/linux/issues/160 [2]
---
Erick Archer (2):
atmel: at76c50x: use sizeof(*pointer) instead of sizeof(type)
atmel: at76c50x: prefer struct_size over open coded arithmetic

drivers/net/wireless/atmel/at76c50x-usb.c | 56 ++++++++++-------------
drivers/net/wireless/atmel/at76c50x-usb.h | 2 +-
2 files changed, 26 insertions(+), 32 deletions(-)

--
2.25.1