diff options
author | Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> | 2017-07-23 22:41:46 +0300 |
---|---|---|
committer | Rob Herring <robh@kernel.org> | 2017-07-24 10:00:52 -0500 |
commit | e2af1f561168897de43b179e5b9d513392721eff (patch) | |
tree | 2392edc5a458df18577ec9618be7f756e40fd217 /drivers/of | |
parent | 56134e3c649b97085df50fe85ae479e3d3a87d7f (diff) | |
download | linux-stable-e2af1f561168897de43b179e5b9d513392721eff.tar.gz linux-stable-e2af1f561168897de43b179e5b9d513392721eff.tar.bz2 linux-stable-e2af1f561168897de43b179e5b9d513392721eff.zip |
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: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/of_pci.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 0162e4ba30e2..e9ec931f5b9a 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -57,15 +57,14 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device); */ int of_pci_get_devfn(struct device_node *np) { - unsigned int size; - const __be32 *reg; - - reg = of_get_property(np, "reg", &size); + u32 reg[5]; + int error; - if (!reg || size < 5 * sizeof(__be32)) - return -EINVAL; + error = of_property_read_u32_array(np, "reg", reg, ARRAY_SIZE(reg)); + if (error) + return error; - return (be32_to_cpup(reg) >> 8) & 0xff; + return (reg[0] >> 8) & 0xff; } 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) { - const __be32 *values; - int len; + u32 bus_range[2]; + int error; - values = of_get_property(node, "bus-range", &len); - if (!values || len < sizeof(*values) * 2) - return -EINVAL; + error = of_property_read_u32_array(node, "bus-range", bus_range, + ARRAY_SIZE(bus_range)); + if (error) + return error; res->name = node->name; - res->start = be32_to_cpup(values++); - res->end = be32_to_cpup(values); + res->start = bus_range[0]; + res->end = bus_range[1]; res->flags = IORESOURCE_BUS; return 0; |