summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Yingliang <yangyingliang@huawei.com>2022-10-08 19:56:16 +0800
committerRob Herring <robh@kernel.org>2022-10-16 17:58:54 -0500
commit16988c742968d5ceb2e832a57bd277f51f0a59d7 (patch)
treee208c02db6f827befef8ceb69dec98f169480959
parent9abf2313adc1ca1b6180c508c25f22f9395cc780 (diff)
of/address: introduce of_address_count() helper
Introduce of_address_count() helper to count the IO resources instead of open-coding it. Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Link: https://lore.kernel.org/r/20221008115617.3583890-2-yangyingliang@huawei.com Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r--include/linux/of_address.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 45598dbec269..265f26eeaf6b 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -154,4 +154,15 @@ static inline const __be32 *of_get_pci_address(struct device_node *dev, int bar_
return __of_get_address(dev, -1, bar_no, size, flags);
}
+static inline int of_address_count(struct device_node *np)
+{
+ struct resource res;
+ int count = 0;
+
+ while (of_address_to_resource(np, count, &res) == 0)
+ count++;
+
+ return count;
+}
+
#endif /* __OF_ADDRESS_H */