Commit e2af1f56 authored by Sergei Shtylyov's avatar Sergei Shtylyov Committed by Rob Herring

of_pci: use of_property_read_u32_array()

of_pci_get_devfn() and of_pci_parse_bus_range() somehow didn't use
of_property_read_u32_array() though it was long available, basically
open-coding it.  Using the modern DT API saves several bytes and
also adds some prop sanity checks as a bonus...
Signed-off-by: default avatarSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
parent 56134e3c
...@@ -57,15 +57,14 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device); ...@@ -57,15 +57,14 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device);
*/ */
int of_pci_get_devfn(struct device_node *np) int of_pci_get_devfn(struct device_node *np)
{ {
unsigned int size; u32 reg[5];
const __be32 *reg; int error;
reg = of_get_property(np, "reg", &size);
if (!reg || size < 5 * sizeof(__be32)) error = of_property_read_u32_array(np, "reg", reg, ARRAY_SIZE(reg));
return -EINVAL; if (error)
return error;
return (be32_to_cpup(reg) >> 8) & 0xff; return (reg[0] >> 8) & 0xff;
} }
EXPORT_SYMBOL_GPL(of_pci_get_devfn); EXPORT_SYMBOL_GPL(of_pci_get_devfn);
...@@ -78,16 +77,17 @@ EXPORT_SYMBOL_GPL(of_pci_get_devfn); ...@@ -78,16 +77,17 @@ EXPORT_SYMBOL_GPL(of_pci_get_devfn);
*/ */
int of_pci_parse_bus_range(struct device_node *node, struct resource *res) int of_pci_parse_bus_range(struct device_node *node, struct resource *res)
{ {
const __be32 *values; u32 bus_range[2];
int len; int error;
values = of_get_property(node, "bus-range", &len); error = of_property_read_u32_array(node, "bus-range", bus_range,
if (!values || len < sizeof(*values) * 2) ARRAY_SIZE(bus_range));
return -EINVAL; if (error)
return error;
res->name = node->name; res->name = node->name;
res->start = be32_to_cpup(values++); res->start = bus_range[0];
res->end = be32_to_cpup(values); res->end = bus_range[1];
res->flags = IORESOURCE_BUS; res->flags = IORESOURCE_BUS;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment