[PATCH 20/21] dm: core: Reduce code size with dev_of_offset()

Simon Glass sjg at chromium.org
Wed Aug 31 05:08:16 CEST 2022


Update the function to mark it with the const attribute. Also avoid
calling it multiple times in the devfdt_get_addr_index() function.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/core/fdtaddr.c | 18 +++++++++---------
 include/dm/device.h    |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/core/fdtaddr.c b/drivers/core/fdtaddr.c
index c3a50a2b0c1..91bcd1a2c21 100644
--- a/drivers/core/fdtaddr.c
+++ b/drivers/core/fdtaddr.c
@@ -21,6 +21,8 @@ DECLARE_GLOBAL_DATA_PTR;
 fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 {
 #if CONFIG_IS_ENABLED(OF_REAL)
+	int offset = dev_of_offset(dev);
+	int parent = dev_of_offset(dev->parent);
 	fdt_addr_t addr;
 
 	if (CONFIG_IS_ENABLED(OF_TRANSLATE)) {
@@ -28,21 +30,19 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 		int len = 0;
 		int na, ns;
 
-		na = fdt_address_cells(gd->fdt_blob,
-				       dev_of_offset(dev->parent));
+		na = fdt_address_cells(gd->fdt_blob, parent);
 		if (na < 1) {
 			debug("bad #address-cells\n");
 			return FDT_ADDR_T_NONE;
 		}
 
-		ns = fdt_size_cells(gd->fdt_blob, dev_of_offset(dev->parent));
+		ns = fdt_size_cells(gd->fdt_blob, parent);
 		if (ns < 0) {
 			debug("bad #size-cells\n");
 			return FDT_ADDR_T_NONE;
 		}
 
-		reg = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "reg",
-				  &len);
+		reg = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
 		if (!reg || (len <= (index * sizeof(fdt32_t) * (na + ns)))) {
 			debug("Req index out of range\n");
 			return FDT_ADDR_T_NONE;
@@ -56,7 +56,7 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 			 * bus setups.
 			 */
 			addr = fdt_translate_address((void *)gd->fdt_blob,
-						     dev_of_offset(dev), reg);
+						     offset, reg);
 		} else {
 			/* Non translatable if #size-cells == 0 */
 			addr = fdt_read_number(reg, na);
@@ -66,9 +66,9 @@ fdt_addr_t devfdt_get_addr_index(const struct udevice *dev, int index)
 		 * Use the "simple" translate function for less complex
 		 * bus setups.
 		 */
-		addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
-				dev_of_offset(dev->parent), dev_of_offset(dev),
-				"reg", index, NULL, false);
+		addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob, parent,
+							offset, "reg", index,
+							NULL, false);
 		if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
 			if (device_get_uclass_id(dev->parent) ==
 			    UCLASS_SIMPLE_BUS)
diff --git a/include/dm/device.h b/include/dm/device.h
index 12c6ba37ff3..f3f953c9afc 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -253,7 +253,7 @@ static inline void dev_bic_flags(struct udevice *dev, u32 bic)
  * @dev:	device to check
  * Return: reference of the device's DT node
  */
-static inline ofnode dev_ofnode(const struct udevice *dev)
+static inline __attribute_const__ ofnode dev_ofnode(const struct udevice *dev)
 {
 #if CONFIG_IS_ENABLED(OF_REAL)
 	return dev->node_;
@@ -273,7 +273,7 @@ static inline ofnode dev_ofnode(const struct udevice *dev)
 #define dev_get_dma_offset(_dev)		0
 #endif
 
-static inline int dev_of_offset(const struct udevice *dev)
+static inline __attribute_const__ int dev_of_offset(const struct udevice *dev)
 {
 #if CONFIG_IS_ENABLED(OF_REAL)
 	return ofnode_to_offset(dev_ofnode(dev));
@@ -282,7 +282,7 @@ static inline int dev_of_offset(const struct udevice *dev)
 #endif
 }
 
-static inline bool dev_has_ofnode(const struct udevice *dev)
+static inline __attribute_const__ bool dev_has_ofnode(const struct udevice *dev)
 {
 #if CONFIG_IS_ENABLED(OF_REAL)
 	return ofnode_valid(dev_ofnode(dev));
-- 
2.37.2.672.g94769d06f0-goog



More information about the U-Boot mailing list