Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <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>

authored by

Javier Carrasco and committed by
Dmitry Torokhov
8dee1dda d3dcadd6

+7 -13
+7 -13
drivers/input/touchscreen/88pm860x-ts.c
··· 117 117 struct pm860x_chip *chip, 118 118 int *res_x) 119 119 { 120 - struct device_node *np = pdev->dev.parent->of_node; 121 120 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ 122 121 : chip->companion; 123 122 int data, n, ret; 124 - if (!np) 123 + if (!pdev->dev.parent->of_node) 125 124 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"); 127 128 if (!np) { 128 129 dev_err(&pdev->dev, "Can't find touch node\n"); 129 130 return -EINVAL; ··· 142 141 if (data) { 143 142 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data); 144 143 if (ret < 0) 145 - goto err_put_node; 144 + return -EINVAL; 146 145 } 147 146 /* set tsi prebias time */ 148 147 if (!of_property_read_u32(np, "marvell,88pm860x-tsi-prebias", &data)) { 149 148 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data); 150 149 if (ret < 0) 151 - goto err_put_node; 150 + return -EINVAL; 152 151 } 153 152 /* set prebias & prechg time of pen detect */ 154 153 data = 0; ··· 159 158 if (data) { 160 159 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data); 161 160 if (ret < 0) 162 - goto err_put_node; 161 + return -EINVAL; 163 162 } 164 163 of_property_read_u32(np, "marvell,88pm860x-resistor-X", res_x); 165 164 166 - of_node_put(np); 167 - 168 165 return 0; 169 - 170 - err_put_node: 171 - of_node_put(np); 172 - 173 - return -EINVAL; 174 166 } 175 167 #else 176 168 #define pm860x_touch_dt_init(x, y, z) (-1)