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

Input: 88pm860x-ts - fix child-node lookup

Fix child node-lookup during probe, which ended up searching the whole
device tree depth-first starting at parent rather than just matching on
its children.

To make things worse, the parent node was prematurely freed, while the
child node was leaked.

Fixes: 2e57d56747e6 ("mfd: 88pm860x: Device tree support")
Cc: stable <stable@vger.kernel.org> # 3.7
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Johan Hovold and committed by
Dmitry Torokhov
906bf7da dcaf12a8

+12 -4
+12 -4
drivers/input/touchscreen/88pm860x-ts.c
··· 126 126 int data, n, ret; 127 127 if (!np) 128 128 return -ENODEV; 129 - np = of_find_node_by_name(np, "touch"); 129 + np = of_get_child_by_name(np, "touch"); 130 130 if (!np) { 131 131 dev_err(&pdev->dev, "Can't find touch node\n"); 132 132 return -EINVAL; ··· 144 144 if (data) { 145 145 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data); 146 146 if (ret < 0) 147 - return -EINVAL; 147 + goto err_put_node; 148 148 } 149 149 /* set tsi prebias time */ 150 150 if (!of_property_read_u32(np, "marvell,88pm860x-tsi-prebias", &data)) { 151 151 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data); 152 152 if (ret < 0) 153 - return -EINVAL; 153 + goto err_put_node; 154 154 } 155 155 /* set prebias & prechg time of pen detect */ 156 156 data = 0; ··· 161 161 if (data) { 162 162 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data); 163 163 if (ret < 0) 164 - return -EINVAL; 164 + goto err_put_node; 165 165 } 166 166 of_property_read_u32(np, "marvell,88pm860x-resistor-X", res_x); 167 + 168 + of_node_put(np); 169 + 167 170 return 0; 171 + 172 + err_put_node: 173 + of_node_put(np); 174 + 175 + return -EINVAL; 168 176 } 169 177 #else 170 178 #define pm860x_touch_dt_init(x, y, z) (-1)