Input: ipaq-micro-keys - add error handling for devm_kmemdup
authorHaoran Liu <liuhaoran14@163.com>
Sun, 3 Dec 2023 19:00:23 +0000 (19:00 +0000)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 3 Dec 2023 19:04:34 +0000 (19:04 +0000)
Check the return value of i2c_add_adapter. Static analysis revealed that
the function did not properly handle potential failures of
i2c_add_adapter, which could lead to partial initialization of the I2C
adapter and unstable operation.

Signed-off-by: Haoran Liu <liuhaoran14@163.com>
Link: https://lore.kernel.org/r/20231203164653.38983-1-liuhaoran14@163.com
Fixes: d7535ffa427b ("Input: driver for microcontroller keys on the iPaq h3xxx")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/ipaq-micro-keys.c

index 7b509bce2b332f6fd09e2a098d9bb93bd2188f3b..1d71dd79ffd289cb563271eb3c0547ade0dccdd0 100644 (file)
@@ -105,6 +105,9 @@ static int micro_key_probe(struct platform_device *pdev)
        keys->codes = devm_kmemdup(&pdev->dev, micro_keycodes,
                           keys->input->keycodesize * keys->input->keycodemax,
                           GFP_KERNEL);
+       if (!keys->codes)
+               return -ENOMEM;
+
        keys->input->keycode = keys->codes;
 
        __set_bit(EV_KEY, keys->input->evbit);