Skip to content

Commit c728950

Browse files
baruchsiachlinusw
authored andcommitted
pinctrl: pinconf-generic: scan also referenced phandle node
Make pinconf_generic_dt_node_to_map() also scan the dt pin configuration node directly referenced by phandle, not only its child nodes. The "parent scan" feature needs a few other changes: * Move the pinconf_generic_dt_node_to_map() error handling code to a common place, under the 'exit' label. * Move the pins/groups strings count earlier in pinconf_generic_dt_subnode_to_map(), to allow us to bail out early when these properties are missing or wrong Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent 12149a2 commit c728950

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

drivers/pinctrl/pinconf-generic.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,26 @@ int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
283283
struct device *dev = pctldev->dev;
284284
unsigned long *configs = NULL;
285285
unsigned num_configs = 0;
286-
unsigned reserve;
286+
unsigned reserve, strings_count;
287287
struct property *prop;
288288
const char *group;
289289
const char *subnode_target_type = "pins";
290290

291+
ret = of_property_count_strings(np, "pins");
292+
if (ret < 0) {
293+
ret = of_property_count_strings(np, "groups");
294+
if (ret < 0)
295+
/* skip this node; may contain config child nodes */
296+
return 0;
297+
if (type == PIN_MAP_TYPE_INVALID)
298+
type = PIN_MAP_TYPE_CONFIGS_GROUP;
299+
subnode_target_type = "groups";
300+
} else {
301+
if (type == PIN_MAP_TYPE_INVALID)
302+
type = PIN_MAP_TYPE_CONFIGS_PIN;
303+
}
304+
strings_count = ret;
305+
291306
ret = of_property_read_string(np, "function", &function);
292307
if (ret < 0) {
293308
/* EINVAL=missing, which is fine since it's optional */
@@ -309,21 +324,7 @@ int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
309324
if (num_configs)
310325
reserve++;
311326

312-
ret = of_property_count_strings(np, "pins");
313-
if (ret < 0) {
314-
ret = of_property_count_strings(np, "groups");
315-
if (ret < 0) {
316-
dev_err(dev, "could not parse property pins/groups\n");
317-
goto exit;
318-
}
319-
if (type == PIN_MAP_TYPE_INVALID)
320-
type = PIN_MAP_TYPE_CONFIGS_GROUP;
321-
subnode_target_type = "groups";
322-
} else {
323-
if (type == PIN_MAP_TYPE_INVALID)
324-
type = PIN_MAP_TYPE_CONFIGS_PIN;
325-
}
326-
reserve *= ret;
327+
reserve *= strings_count;
327328

328329
ret = pinctrl_utils_reserve_map(pctldev, map, reserved_maps,
329330
num_maps, reserve);
@@ -367,15 +368,22 @@ int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
367368
*map = NULL;
368369
*num_maps = 0;
369370

371+
ret = pinconf_generic_dt_subnode_to_map(pctldev, np_config, map,
372+
&reserved_maps, num_maps, type);
373+
if (ret < 0)
374+
goto exit;
375+
370376
for_each_child_of_node(np_config, np) {
371377
ret = pinconf_generic_dt_subnode_to_map(pctldev, np, map,
372378
&reserved_maps, num_maps, type);
373-
if (ret < 0) {
374-
pinctrl_utils_dt_free_map(pctldev, *map, *num_maps);
375-
return ret;
376-
}
379+
if (ret < 0)
380+
goto exit;
377381
}
378382
return 0;
383+
384+
exit:
385+
pinctrl_utils_dt_free_map(pctldev, *map, *num_maps);
386+
return ret;
379387
}
380388
EXPORT_SYMBOL_GPL(pinconf_generic_dt_node_to_map);
381389

0 commit comments

Comments
 (0)