Messages in this thread Patch in this message | ![/](/images/icornerl.gif) | | From | Duoming Zhou <> | Subject | [PATCH v2] ARM: mvebu: Add error handling in i2c_quirk to prevent bugs | Date | Sun, 25 Feb 2024 22:29:32 +0800 |
| |
The kzalloc() and the two kstrdup in i2c_quirk() will return null if the physical memory has run out. As a result, if we dereference these null values, the null pointer dereference bugs will happen.
This patch adds error handling to avoid null pointer dereference.
Fixes: 5fd62066d290 ("ARM: mvebu: Add thermal quirk for the Armada 375 DB board") Signed-off-by: Duoming Zhou <duoming@zju.edu.cn> --- Changes in v2: - Adds checks to judge whether two kstrdup() fail.
arch/arm/mach-mvebu/board-v7.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/arm/mach-mvebu/board-v7.c b/arch/arm/mach-mvebu/board-v7.c index fd5d0c8ff69..c31ac08d24a 100644 --- a/arch/arm/mach-mvebu/board-v7.c +++ b/arch/arm/mach-mvebu/board-v7.c @@ -125,12 +125,20 @@ static void __init i2c_quirk(void) struct property *new_compat; new_compat = kzalloc(sizeof(*new_compat), GFP_KERNEL); + if (!new_compat) + continue; new_compat->name = kstrdup("compatible", GFP_KERNEL); new_compat->length = sizeof("marvell,mv78230-a0-i2c"); new_compat->value = kstrdup("marvell,mv78230-a0-i2c", GFP_KERNEL); + if (!new_compat->name || !new_compat->value) { + kfree(new_compat->name); + kfree(new_compat->value); + kfree(new_compat); + continue; + } of_update_property(np, new_compat); } } -- 2.17.1
| ![\](/images/icornerr.gif) |