of: reserved_mem: fix cell count for memory-region property
[linux-3.10.git] / drivers / of / of_reserved_mem.c
index c00df97..2275432 100644 (file)
@@ -243,23 +243,33 @@ static inline struct reserved_mem *__find_rmem(struct device_node *node)
  * This function assign memory region pointed by "memory-region" device tree
  * property to the given device.
  */
-void of_reserved_mem_device_init(struct device *dev)
+int of_reserved_mem_device_init(struct device *dev)
 {
        struct reserved_mem *rmem;
-       struct device_node *np;
+       struct of_phandle_iter iter;
+       int err = -ENODEV;
 
-       np = of_parse_phandle(dev->of_node, "memory-region", 0);
-       if (!np)
-               return;
+       of_property_for_each_phandle_with_args(iter, dev->of_node, "memory-region",
+                                              NULL, 0) {
+               struct of_phandle_args *ret = &iter.out_args;
 
-       rmem = __find_rmem(np);
-       of_node_put(np);
+               if (!ret->np)
+                       return -ENODEV;
 
-       if (!rmem || !rmem->ops || !rmem->ops->device_init)
-               return;
+               of_node_get(ret->np);
+               rmem = __find_rmem(ret->np);
+               of_node_put(ret->np);
+
+               if (!rmem || !rmem->ops || !rmem->ops->device_init)
+                       return -EINVAL;
+
+               err = rmem->ops->device_init(rmem, dev);
+               if (err != 0)
+                       break;
+               dev_info(dev, "assigned reserved memory node %s\n", rmem->name);
+       }
 
-       rmem->ops->device_init(rmem, dev);
-       dev_info(dev, "assigned reserved memory node %s\n", rmem->name);
+       return err;
 }
 
 /**
@@ -271,17 +281,22 @@ void of_reserved_mem_device_init(struct device *dev)
 void of_reserved_mem_device_release(struct device *dev)
 {
        struct reserved_mem *rmem;
-       struct device_node *np;
+       struct of_phandle_iter iter;
 
-       np = of_parse_phandle(dev->of_node, "memory-region", 0);
-       if (!np)
-               return;
+       of_property_for_each_phandle_with_args(iter, dev->of_node, "memory-region",
+                                              NULL, 1) {
+               struct of_phandle_args *ret = &iter.out_args;
 
-       rmem = __find_rmem(np);
-       of_node_put(np);
+               if (!ret->np)
+                       return;
 
-       if (!rmem || !rmem->ops || !rmem->ops->device_release)
-               return;
+               of_node_get(ret->np);
+               rmem = __find_rmem(ret->np);
+               of_node_put(ret->np);
 
-       rmem->ops->device_release(rmem, dev);
+               if (!rmem || !rmem->ops || !rmem->ops->device_release)
+                       return;
+
+               rmem->ops->device_release(rmem, dev);
+       }
 }