Skip to content

Commit 0ec6f58

Browse files
javiercarrascocruzdtor
authored andcommitted
Input: sun4i-lradc-keys - switch to for_each_child_of_node_scoped
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 <[email protected]> Reviewed-by: Andre Przywara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 2e6980c commit 0ec6f58

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

drivers/input/keyboard/sun4i-lradc-keys.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static void sun4i_lradc_close(struct input_dev *dev)
202202
static int sun4i_lradc_load_dt_keymap(struct device *dev,
203203
struct sun4i_lradc_data *lradc)
204204
{
205-
struct device_node *np, *pp;
205+
struct device_node *np;
206206
int i;
207207
int error;
208208

@@ -223,28 +223,25 @@ static int sun4i_lradc_load_dt_keymap(struct device *dev,
223223
return -ENOMEM;
224224

225225
i = 0;
226-
for_each_child_of_node(np, pp) {
226+
for_each_child_of_node_scoped(np, pp) {
227227
struct sun4i_lradc_keymap *map = &lradc->chan0_map[i];
228228
u32 channel;
229229

230230
error = of_property_read_u32(pp, "channel", &channel);
231231
if (error || channel != 0) {
232232
dev_err(dev, "%pOFn: Inval channel prop\n", pp);
233-
of_node_put(pp);
234233
return -EINVAL;
235234
}
236235

237236
error = of_property_read_u32(pp, "voltage", &map->voltage);
238237
if (error) {
239238
dev_err(dev, "%pOFn: Inval voltage prop\n", pp);
240-
of_node_put(pp);
241239
return -EINVAL;
242240
}
243241

244242
error = of_property_read_u32(pp, "linux,code", &map->keycode);
245243
if (error) {
246244
dev_err(dev, "%pOFn: Inval linux,code prop\n", pp);
247-
of_node_put(pp);
248245
return -EINVAL;
249246
}
250247

0 commit comments

Comments
 (0)