diff options
| author | Liang Jie <liangjie@lixiang.com> | 2025-12-09 13:02:17 +0300 |
|---|---|---|
| committer | Linus Walleij <linusw@kernel.org> | 2025-12-26 21:13:01 +0300 |
| commit | 255b721c96046d4c57fa2268e4c72607868ce91f (patch) | |
| tree | 68cc86ae5829c2789975827369c0dfb1b80ec0bc /include/linux/pps_kernel.h | |
| parent | a035b23b59c54c959cd4b89094aa4c44c6b41383 (diff) | |
| download | linux-255b721c96046d4c57fa2268e4c72607868ce91f.tar.xz | |
pinctrl: mediatek: make devm allocations safer and clearer in mtk_eint_do_init()
mtk_eint_do_init() allocates several pointer arrays which are then
populated in a per-instance loop and freed on error. The arrays are
currently allocated with devm_kmalloc(), so their entries are left
uninitialised until the per-instance allocations succeed.
On a failure in the middle of the loop, the error path iterates over
the full nbase range and calls devm_kfree() on each element. For
indices which were never initialised, the corresponding array entries
contain stack garbage. If any of those happen to be non-zero,
devm_kfree() will pass them to devres_destroy(), which will WARN
because there is no matching devm_kmalloc() resource for such bogus
pointers.
Improve the robustness and readability by:
- Using devm_kcalloc() for the pointer arrays so that all entries
start as NULL, ensuring that only genuinely initialised elements
may be freed and preventing spurious WARN_ON()s in the error path.
- Switching the allocations to sizeof(*ptr) / sizeof(**ptr) forms,
avoiding hard-coded element types and making the code more resilient
to future type changes.
- Dropping the redundant NULL checks before devm_kfree(), as
devm_kfree() safely handles NULL pointers.
The functional behaviour in the successful initialisation path remains
unchanged, while the error handling becomes simpler and less
error-prone.
Reviewed-by: fanggeng <fanggeng@lixiang.com>
Signed-off-by: Liang Jie <liangjie@lixiang.com>
Signed-off-by: Linus Walleij <linusw@kernel.org>
Diffstat (limited to 'include/linux/pps_kernel.h')
0 files changed, 0 insertions, 0 deletions
