diff options
author | Dong Aisheng <dong.aisheng@linaro.org> | 2012-04-10 00:41:34 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2012-04-18 07:53:11 -0400 |
commit | ad8bb720c23a80233e45ed31d67458f5e5b7ab31 (patch) | |
tree | 6b1da7d3dc99bacd03167a0235785e3f881b03b3 /drivers/pinctrl/pinmux.c | |
parent | a1d31f71e6ed2f714830df8885ec07dfe1f6632e (diff) |
pinctrl: add some error checking for user interfaces
This patch can avoid kernel oops in case the mux or config
function is not supported by driver.
Acked-by: Stephen Warren <swarren@wwwdotorg.org>
Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinmux.c')
-rw-r--r-- | drivers/pinctrl/pinmux.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c index 8849830e5190..c494c37bf167 100644 --- a/drivers/pinctrl/pinmux.c +++ b/drivers/pinctrl/pinmux.c | |||
@@ -323,6 +323,11 @@ int pinmux_map_to_setting(struct pinctrl_map const *map, | |||
323 | const unsigned *pins; | 323 | const unsigned *pins; |
324 | unsigned num_pins; | 324 | unsigned num_pins; |
325 | 325 | ||
326 | if (!pmxops) { | ||
327 | dev_err(pctldev->dev, "does not support mux function\n"); | ||
328 | return -EINVAL; | ||
329 | } | ||
330 | |||
326 | setting->data.mux.func = | 331 | setting->data.mux.func = |
327 | pinmux_func_name_to_selector(pctldev, map->data.mux.function); | 332 | pinmux_func_name_to_selector(pctldev, map->data.mux.function); |
328 | if (setting->data.mux.func < 0) | 333 | if (setting->data.mux.func < 0) |
@@ -481,11 +486,14 @@ static int pinmux_functions_show(struct seq_file *s, void *what) | |||
481 | { | 486 | { |
482 | struct pinctrl_dev *pctldev = s->private; | 487 | struct pinctrl_dev *pctldev = s->private; |
483 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; | 488 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; |
484 | unsigned nfuncs = pmxops->get_functions_count(pctldev); | 489 | unsigned nfuncs; |
485 | unsigned func_selector = 0; | 490 | unsigned func_selector = 0; |
486 | 491 | ||
487 | mutex_lock(&pinctrl_mutex); | 492 | if (!pmxops) |
493 | return 0; | ||
488 | 494 | ||
495 | mutex_lock(&pinctrl_mutex); | ||
496 | nfuncs = pmxops->get_functions_count(pctldev); | ||
489 | while (func_selector < nfuncs) { | 497 | while (func_selector < nfuncs) { |
490 | const char *func = pmxops->get_function_name(pctldev, | 498 | const char *func = pmxops->get_function_name(pctldev, |
491 | func_selector); | 499 | func_selector); |
@@ -520,6 +528,9 @@ static int pinmux_pins_show(struct seq_file *s, void *what) | |||
520 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; | 528 | const struct pinmux_ops *pmxops = pctldev->desc->pmxops; |
521 | unsigned i, pin; | 529 | unsigned i, pin; |
522 | 530 | ||
531 | if (!pmxops) | ||
532 | return 0; | ||
533 | |||
523 | seq_puts(s, "Pinmux settings per pin\n"); | 534 | seq_puts(s, "Pinmux settings per pin\n"); |
524 | seq_puts(s, "Format: pin (name): mux_owner gpio_owner hog?\n"); | 535 | seq_puts(s, "Format: pin (name): mux_owner gpio_owner hog?\n"); |
525 | 536 | ||