Skip to content

Commit 8dee1dd

Browse files
javiercarrascocruzdtor
authored andcommitted
Input: 88pm860x - use cleanup facility for device_node
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent d3dcadd commit 8dee1dd

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

drivers/input/touchscreen/88pm860x-ts.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
117117
struct pm860x_chip *chip,
118118
int *res_x)
119119
{
120-
struct device_node *np = pdev->dev.parent->of_node;
121120
struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
122121
: chip->companion;
123122
int data, n, ret;
124-
if (!np)
123+
if (!pdev->dev.parent->of_node)
125124
return -ENODEV;
126-
np = of_get_child_by_name(np, "touch");
125+
126+
struct device_node *np __free(device_node) =
127+
of_get_child_by_name(pdev->dev.parent->of_node, "touch");
127128
if (!np) {
128129
dev_err(&pdev->dev, "Can't find touch node\n");
129130
return -EINVAL;
@@ -141,13 +142,13 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
141142
if (data) {
142143
ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
143144
if (ret < 0)
144-
goto err_put_node;
145+
return -EINVAL;
145146
}
146147
/* set tsi prebias time */
147148
if (!of_property_read_u32(np, "marvell,88pm860x-tsi-prebias", &data)) {
148149
ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
149150
if (ret < 0)
150-
goto err_put_node;
151+
return -EINVAL;
151152
}
152153
/* set prebias & prechg time of pen detect */
153154
data = 0;
@@ -158,18 +159,11 @@ static int pm860x_touch_dt_init(struct platform_device *pdev,
158159
if (data) {
159160
ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
160161
if (ret < 0)
161-
goto err_put_node;
162+
return -EINVAL;
162163
}
163164
of_property_read_u32(np, "marvell,88pm860x-resistor-X", res_x);
164165

165-
of_node_put(np);
166-
167166
return 0;
168-
169-
err_put_node:
170-
of_node_put(np);
171-
172-
return -EINVAL;
173167
}
174168
#else
175169
#define pm860x_touch_dt_init(x, y, z) (-1)

0 commit comments

Comments
 (0)