aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-02-22 16:25:58 -0500
committerLinus Walleij <linus.walleij@linaro.org>2012-02-24 00:24:52 -0500
commit1681f5ae4ca25bddb6f7b6d4f463cc83e3d1ad01 (patch)
treefc37580130beadbc5e0898ddb9b5fec32b662859 /drivers
parentf7b9006f4598dd252dca5225f3cf88179c36276f (diff)
pinctrl: disallow map table entries with NULL dev_name field
Hog entries are mapping table entries with .ctrl_dev_name == .dev_name. All other mapping table entries need .dev_name set so that they will match some pinctrl_get() call. All extant PIN_MAP*() macros set .dev_name. So, there is no reason to allow mapping table entries without .dev_name set. Update the code and documentation to disallow this. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Dong Aisheng <dong.aisheng@linaro.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/pinctrl/core.c73
1 files changed, 22 insertions, 51 deletions
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index fb3fbb76932e..5411e32bb3f6 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -479,24 +479,21 @@ EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
479static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name) 479static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
480{ 480{
481 struct pinctrl_dev *pctldev = NULL; 481 struct pinctrl_dev *pctldev = NULL;
482 const char *devname = NULL; 482 const char *devname;
483 struct pinctrl *p; 483 struct pinctrl *p;
484 bool found_map;
485 unsigned num_maps = 0; 484 unsigned num_maps = 0;
486 int ret = -ENODEV; 485 int ret = -ENODEV;
487 struct pinctrl_maps *maps_node; 486 struct pinctrl_maps *maps_node;
488 int i; 487 int i;
489 struct pinctrl_map const *map; 488 struct pinctrl_map const *map;
490 489
491 /* We must have dev or ID or both */ 490 /* We must have a dev name */
492 if (!dev && !name) 491 if (WARN_ON(!dev))
493 return ERR_PTR(-EINVAL); 492 return ERR_PTR(-EINVAL);
494 493
495 if (dev) 494 devname = dev_name(dev);
496 devname = dev_name(dev);
497 495
498 pr_debug("get pin control handle %s for device %s\n", name, 496 pr_debug("get pin control handle device %s state %s\n", devname, name);
499 devname ? devname : "(none)");
500 497
501 /* 498 /*
502 * create the state cookie holder struct pinctrl for each 499 * create the state cookie holder struct pinctrl for each
@@ -511,8 +508,6 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
511 508
512 /* Iterate over the pin control maps to locate the right ones */ 509 /* Iterate over the pin control maps to locate the right ones */
513 for_each_maps(maps_node, i, map) { 510 for_each_maps(maps_node, i, map) {
514 found_map = false;
515
516 /* 511 /*
517 * First, try to find the pctldev given in the map 512 * First, try to find the pctldev given in the map
518 */ 513 */
@@ -529,6 +524,10 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
529 pr_debug("in map, found pctldev %s to handle function %s", 524 pr_debug("in map, found pctldev %s to handle function %s",
530 dev_name(pctldev->dev), map->function); 525 dev_name(pctldev->dev), map->function);
531 526
527 /* Map must be for this device */
528 if (strcmp(map->dev_name, devname))
529 continue;
530
532 /* 531 /*
533 * If we're looking for a specific named map, this must match, 532 * If we're looking for a specific named map, this must match,
534 * else we loop and look for the next. 533 * else we loop and look for the next.
@@ -540,30 +539,12 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
540 continue; 539 continue;
541 } 540 }
542 541
543 /* 542 ret = pinmux_apply_muxmap(pctldev, p, dev, devname, map);
544 * This is for the case where no device name is given, we 543 if (ret) {
545 * already know that the function name matches from above 544 kfree(p);
546 * code. 545 return ERR_PTR(ret);
547 */
548 if (!map->dev_name && (name != NULL))
549 found_map = true;
550
551 /* If the mapping has a device set up it must match */
552 if (map->dev_name &&
553 (!devname || !strcmp(map->dev_name, devname)))
554 /* MATCH! */
555 found_map = true;
556
557 /* If this map is applicable, then apply it */
558 if (found_map) {
559 ret = pinmux_apply_muxmap(pctldev, p, dev,
560 devname, map);
561 if (ret) {
562 kfree(p);
563 return ERR_PTR(ret);
564 }
565 num_maps++;
566 } 546 }
547 num_maps++;
567 } 548 }
568 549
569 /* 550 /*
@@ -578,9 +559,7 @@ static struct pinctrl *pinctrl_get_locked(struct device *dev, const char *name)
578 dev_info(dev, "zero maps found for mapping %s\n", name); 559 dev_info(dev, "zero maps found for mapping %s\n", name);
579 560
580 pr_debug("found %u mux maps for device %s, UD %s\n", 561 pr_debug("found %u mux maps for device %s, UD %s\n",
581 num_maps, 562 num_maps, devname, name ? name : "(undefined)");
582 devname ? devname : "(anonymous)",
583 name ? name : "(undefined)");
584 563
585 /* Add the pinmux to the global list */ 564 /* Add the pinmux to the global list */
586 mutex_lock(&pinctrl_list_mutex); 565 mutex_lock(&pinctrl_list_mutex);
@@ -707,14 +686,11 @@ int pinctrl_register_mappings(struct pinctrl_map const *maps,
707 return -EINVAL; 686 return -EINVAL;
708 } 687 }
709 688
710 if (!maps[i].dev_name) 689 if (!maps[i].dev_name) {
711 pr_debug("add system map %s function %s with no device\n", 690 pr_err("failed to register map %s (%d): no device given\n",
712 maps[i].name, 691 maps[i].name, i);
713 maps[i].function); 692 return -EINVAL;
714 else 693 }
715 pr_debug("register map %s, function %s\n",
716 maps[i].name,
717 maps[i].function);
718 } 694 }
719 695
720 maps_node = kzalloc(sizeof(*maps_node), GFP_KERNEL); 696 maps_node = kzalloc(sizeof(*maps_node), GFP_KERNEL);
@@ -938,13 +914,8 @@ static int pinctrl_maps_show(struct seq_file *s, void *what)
938 mutex_lock(&pinctrl_maps_mutex); 914 mutex_lock(&pinctrl_maps_mutex);
939 for_each_maps(maps_node, i, map) { 915 for_each_maps(maps_node, i, map) {
940 seq_printf(s, "%s:\n", map->name); 916 seq_printf(s, "%s:\n", map->name);
941 if (map->dev_name) 917 seq_printf(s, " device: %s\n", map->dev_name);
942 seq_printf(s, " device: %s\n", 918 seq_printf(s, " controlling device %s\n", map->ctrl_dev_name);
943 map->dev_name);
944 else
945 seq_printf(s, " SYSTEM MUX\n");
946 seq_printf(s, " controlling device %s\n",
947 map->ctrl_dev_name);
948 seq_printf(s, " function: %s\n", map->function); 919 seq_printf(s, " function: %s\n", map->function);
949 seq_printf(s, " group: %s\n", map->group ? map->group : 920 seq_printf(s, " group: %s\n", map->group ? map->group :
950 "(default)"); 921 "(default)");