]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: atkbd - use __free() cleanup facility in when parsing FW keymap
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Sat, 21 Feb 2026 02:57:58 +0000 (18:57 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 1 Mar 2026 02:20:48 +0000 (18:20 -0800)
Annotating the temporary keymap pointer as __free(kfree) ensures that it
will get released when exiting the function and explicit freeing in all
the return paths can be removed.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/atkbd.c

index 7e6fa0e3cbd8ff2885e6ee1768fe04b4bb4a2169..4459de0e661563f89f76ce1e71cb841631e68ab0 100644 (file)
@@ -1088,7 +1088,6 @@ static int atkbd_get_keymap_from_fwnode(struct atkbd *atkbd)
 {
        struct device *dev = &atkbd->ps2dev.serio->dev;
        int i, n;
-       u32 *ptr;
        u16 scancode, keycode;
 
        /* Parse "linux,keymap" property */
@@ -1096,13 +1095,12 @@ static int atkbd_get_keymap_from_fwnode(struct atkbd *atkbd)
        if (n <= 0 || n > ATKBD_KEYMAP_SIZE)
                return -ENXIO;
 
-       ptr = kcalloc(n, sizeof(u32), GFP_KERNEL);
+       u32 *ptr __free(kfree) = kcalloc(n, sizeof(*ptr), GFP_KERNEL);
        if (!ptr)
                return -ENOMEM;
 
        if (device_property_read_u32_array(dev, "linux,keymap", ptr, n)) {
                dev_err(dev, "problem parsing FW keymap property\n");
-               kfree(ptr);
                return -EINVAL;
        }
 
@@ -1113,13 +1111,11 @@ static int atkbd_get_keymap_from_fwnode(struct atkbd *atkbd)
                if (scancode >= ATKBD_KEYMAP_SIZE) {
                        dev_warn(dev, "invalid scancode %#x in FW keymap entry %d\n",
                                 scancode, i);
-                       kfree(ptr);
                        return -EINVAL;
                }
                atkbd->keycode[scancode] = keycode;
        }
 
-       kfree(ptr);
        return 0;
 }