]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Input: 88pm860x - use cleanup facility for device_node
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Sun, 20 Oct 2024 04:14:57 +0000 (21:14 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 20 Oct 2024 04:21:41 +0000 (21:21 -0700)
Use the '__free(device_node)' macro to simplify the code and error
handling. This makes the code more robust by ensuring that the device
node is always freed.

Drop the first assignment to 'pdev->dev.parent->of_node', as it was only
a shortcut, and tie 'np' to its usage as a child node.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20241010-input_automate_of_node_put-v1-7-ebc62138fbf8@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/touchscreen/88pm860x-ts.c

index 81a3ea4b9a3dd149d2f8c8a30503011275fbde4e..0468ce2b216f63a8fc8120b54b57ee348704746b 100644 (file)
@@ -117,13 +117,14 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
                                          struct pm860x_chip *chip,
                                          int *res_x)
 {
-       struct device_node *np = pdev->dev.parent->of_node;
        struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
                                 : chip->companion;
        int data, n, ret;
-       if (!np)
+       if (!pdev->dev.parent->of_node)
                return -ENODEV;
-       np = of_get_child_by_name(np, "touch");
+
+       struct device_node *np __free(device_node) =
+               of_get_child_by_name(pdev->dev.parent->of_node, "touch");
        if (!np) {
                dev_err(&pdev->dev, "Can't find touch node\n");
                return -EINVAL;
@@ -141,13 +142,13 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
        if (data) {
                ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
                if (ret < 0)
-                       goto err_put_node;
+                       return -EINVAL;
        }
        /* set tsi prebias time */
        if (!of_property_read_u32(np, "marvell,88pm860x-tsi-prebias", &data)) {
                ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
                if (ret < 0)
-                       goto err_put_node;
+                       return -EINVAL;
        }
        /* set prebias & prechg time of pen detect */
        data = 0;
@@ -158,18 +159,11 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
        if (data) {
                ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
                if (ret < 0)
-                       goto err_put_node;
+                       return -EINVAL;
        }
        of_property_read_u32(np, "marvell,88pm860x-resistor-X", res_x);
 
-       of_node_put(np);
-
        return 0;
-
-err_put_node:
-       of_node_put(np);
-
-       return -EINVAL;
 }
 #else
 #define pm860x_touch_dt_init(x, y, z)  (-1)