]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: mtk-pmic-keys - switch to for_each_child_of_node_scoped
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Sun, 20 Oct 2024 03:59:49 +0000 (20:59 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 20 Oct 2024 04:21:37 +0000 (21:21 -0700)
Use the scoped variant of the macro to simplify the code and error
handling. This makes the error handling more robust by ensuring that
the child node is always freed.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20241010-input_automate_of_node_put-v1-2-ebc62138fbf8@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/mtk-pmic-keys.c

index 4364c3401ff1c60702a2251bfa0ce836b4bf14c2..5ad6be9141603ad1e1bf8cb1dcab7ec6e54d2335 100644 (file)
@@ -307,7 +307,7 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
        int error, index = 0;
        unsigned int keycount;
        struct mt6397_chip *pmic_chip = dev_get_drvdata(pdev->dev.parent);
-       struct device_node *node = pdev->dev.of_node, *child;
+       struct device_node *node = pdev->dev.of_node;
        static const char *const irqnames[] = { "powerkey", "homekey" };
        static const char *const irqnames_r[] = { "powerkey_r", "homekey_r" };
        struct mtk_pmic_keys *keys;
@@ -343,24 +343,20 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
-       for_each_child_of_node(node, child) {
+       for_each_child_of_node_scoped(node, child) {
                keys->keys[index].regs = &mtk_pmic_regs->keys_regs[index];
 
                keys->keys[index].irq =
                        platform_get_irq_byname(pdev, irqnames[index]);
-               if (keys->keys[index].irq < 0) {
-                       of_node_put(child);
+               if (keys->keys[index].irq < 0)
                        return keys->keys[index].irq;
-               }
 
                if (of_device_is_compatible(node, "mediatek,mt6358-keys")) {
                        keys->keys[index].irq_r = platform_get_irq_byname(pdev,
                                                                          irqnames_r[index]);
 
-                       if (keys->keys[index].irq_r < 0) {
-                               of_node_put(child);
+                       if (keys->keys[index].irq_r < 0)
                                return keys->keys[index].irq_r;
-                       }
                }
 
                error = of_property_read_u32(child,
@@ -369,7 +365,6 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
                        dev_err(keys->dev,
                                "failed to read key:%d linux,keycode property: %d\n",
                                index, error);
-                       of_node_put(child);
                        return error;
                }
 
@@ -377,10 +372,8 @@ static int mtk_pmic_keys_probe(struct platform_device *pdev)
                        keys->keys[index].wakeup = true;
 
                error = mtk_pmic_key_setup(keys, &keys->keys[index]);
-               if (error) {
-                       of_node_put(child);
+               if (error)
                        return error;
-               }
 
                index++;
        }