Skip to contentSkip to conversation

of: fix of_address_to_resource and of_iomap undefined

PATCH In review Chunyan Zhang 2 participants 3 messages Sep 2, 2021 – Sep 6, 2021 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of: fix of_address_to_resource and of_iomap undefined

From: Chunyan Zhang <[email protected]>

If CONFIG_OF is selected, but CONFIG_OF_ADDRESS is not, when compiling files (sunch as timer_of.c) in which the function of_iomap() is invoked, compiler would report 'undefined reference to of_iomap', the same case is for of_address_to_resource().

This patch also makes sure that of_iomap() and of_address_to_resource() are declared for sparc so that sparc can have its specific implementations in arch/sparc/kernel/of_device_common.c, even if including include/linux/of_address.h in it.

---
 include/linux/of_address.h | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
include/linux/of_address.h +17 -16
index 45598dbec269..02a719d58466 100644
@@ -80,6 +80,23 @@ static inline u64 of_translate_address(struct device_node *np,
 	return OF_BAD_ADDR;
 }
 
+#ifdef CONFIG_SPARC
+extern int of_address_to_resource(struct device_node *dev, int index,
+				  struct resource *r);
+void __iomem *of_iomap(struct device_node *device, int index);
+#else
+static inline int of_address_to_resource(struct device_node *dev, int index,
+					 struct resource *r)
+{
+	return -EINVAL;
+}
+
+static inline void __iomem *of_iomap(struct device_node *device, int index)
+{
+	return NULL;
+}
+#endif
+
 static inline const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
 					     u64 *size, unsigned int *flags)
 {
@@ -124,22 +141,6 @@ static inline bool of_dma_is_coherent(struct device_node *np)
 }
 #endif /* CONFIG_OF_ADDRESS */
 
-#ifdef CONFIG_OF
-extern int of_address_to_resource(struct device_node *dev, int index,
-				  struct resource *r);
-void __iomem *of_iomap(struct device_node *node, int index);
-#else
-static inline int of_address_to_resource(struct device_node *dev, int index,
-					 struct resource *r)
-{
-	return -EINVAL;
-}
-
-static inline void __iomem *of_iomap(struct device_node *device, int index)
-{
-	return NULL;
-}
-#endif
 #define of_range_parser_init of_pci_range_parser_init
 
 static inline const __be32 *of_get_address(struct device_node *dev, int index,
Signature · 1 line
2.25.1
#1 lore raw
Quoted 7 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

If CONFIG_OF is selected, but CONFIG_OF_ADDRESS is not, when compiling files (sunch as timer_of.c) in which the function of_iomap() is invoked, compiler would report 'undefined reference to of_iomap', the same case is for of_address_to_resource().

What arch and config are you building?

Quoted 15 lines

This patch also makes sure that of_iomap() and of_address_to_resource() are declared for sparc so that sparc can have its specific implementations in arch/sparc/kernel/of_device_common.c, even if including include/linux/of_address.h in it.

---
 include/linux/of_address.h | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
include/linux/of_address.h +0 -0
index 45598dbec269..02a719d58466 100644

include/linux/of_address.h static inline u64 of_translate_address(struct device_node *np, · line 86

Quoted 7 lines
include/linux/of_address.h +4 -0
@@ -80,6 +80,23 @@ static inline u64 of_translate_address(struct device_node *np,
        return OF_BAD_ADDR;
 }
 
+#ifdef CONFIG_SPARC
+extern int of_address_to_resource(struct device_node *dev, int index,
+                                 struct resource *r);
+void __iomem *of_iomap(struct device_node *device, int index);

This is now in the !CONFIG_OF_ADDRESS section. So for CONFIG_OF_ADDRESS, we'd never have a function declaration.

This change does not look right at all to me.

Quoted 42 lines
include/linux/of_address.h +13 -17
+#else
+static inline int of_address_to_resource(struct device_node *dev, int index,
+                                        struct resource *r)
+{
+       return -EINVAL;
+}
+
+static inline void __iomem *of_iomap(struct device_node *device, int index)
+{
+       return NULL;
+}
+#endif
+
 static inline const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
                                             u64 *size, unsigned int *flags)
 {
@@ -124,22 +141,6 @@ static inline bool of_dma_is_coherent(struct device_node *np)
 }
 #endif /* CONFIG_OF_ADDRESS */
 
-#ifdef CONFIG_OF
-extern int of_address_to_resource(struct device_node *dev, int index,
-                                 struct resource *r);
-void __iomem *of_iomap(struct device_node *node, int index);
-#else
-static inline int of_address_to_resource(struct device_node *dev, int index,
-                                        struct resource *r)
-{
-       return -EINVAL;
-}
-
-static inline void __iomem *of_iomap(struct device_node *device, int index)
-{
-       return NULL;
-}
-#endif
 #define of_range_parser_init of_pci_range_parser_init
 
 static inline const __be32 *of_get_address(struct device_node *dev, int index,
--

2.25.1

#2 lore raw
Quoted 11 lines · Rob Herring
Quoted 7 lines · Chunyan Zhang

From: Chunyan Zhang <[email protected]>

If CONFIG_OF is selected, but CONFIG_OF_ADDRESS is not, when compiling files (sunch as timer_of.c) in which the function of_iomap() is invoked, compiler would report 'undefined reference to of_iomap', the same case is for of_address_to_resource().

What arch and config are you building?

sparc, and the config is attached.

Quoted 19 lines
Quoted 19 lines

This patch also makes sure that of_iomap() and of_address_to_resource() are declared for sparc so that sparc can have its specific implementations in arch/sparc/kernel/of_device_common.c, even if including include/linux/of_address.h in it.

---
 include/linux/of_address.h | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
include/linux/of_address.h +0 -0
index 45598dbec269..02a719d58466 100644
@@ -80,6 +80,23 @@ static inline u64 of_translate_address(struct device_node *np,
        return OF_BAD_ADDR;
 }
 
Quoted 7 lines

include/linux/of_address.h static inline u64 of_translate_address(struct device_node *np, · line 86

Quoted 4 lines
include/linux/of_address.h +4 -0
+#ifdef CONFIG_SPARC
+extern int of_address_to_resource(struct device_node *dev, int index,
+                                 struct resource *r);
+void __iomem *of_iomap(struct device_node *device, int index);

This is now in the !CONFIG_OF_ADDRESS section. So for CONFIG_OF_ADDRESS, we'd never have a function declaration.

Not sure I got your point.
There are these two function declarations both in arch/sparc/kernel/of_device_common.c (CONFIG_SPARC && !CONFIG_OF_ADDRESS) and drivers/of/address.c (!CONFIG_SPARC && CONFIG_OF_ADDRESS).

Quoted 14 lines

This change does not look right at all to me.

include/linux/of_address.h static inline u64 of_translate_address(struct device_node *np, · line 98

Quoted 12 lines
include/linux/of_address.h +12 -0
+#else
+static inline int of_address_to_resource(struct device_node *dev, int index,
+                                        struct resource *r)
+{
+       return -EINVAL;
+}
+
+static inline void __iomem *of_iomap(struct device_node *device, int index)
+{
+       return NULL;
+}
+#endif

Now, I'm also not sure if this change is right, I learned in another patch recently that Linus prefers to avoid the extra code like this.

https://lkml.org/lkml/2021/7/2/511

Quoted 30 lines
Quoted 30 lines
include/linux/of_address.h +1 -17
+
 static inline const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
                                             u64 *size, unsigned int *flags)
 {
@@ -124,22 +141,6 @@ static inline bool of_dma_is_coherent(struct device_node *np)
 }
 #endif /* CONFIG_OF_ADDRESS */
 
-#ifdef CONFIG_OF
-extern int of_address_to_resource(struct device_node *dev, int index,
-                                 struct resource *r);
-void __iomem *of_iomap(struct device_node *node, int index);
-#else
-static inline int of_address_to_resource(struct device_node *dev, int index,
-                                        struct resource *r)
-{
-       return -EINVAL;
-}
-
-static inline void __iomem *of_iomap(struct device_node *device, int index)
-{
-       return NULL;
-}
-#endif
 #define of_range_parser_init of_pci_range_parser_init
 
 static inline const __be32 *of_get_address(struct device_node *dev, int index,
--

2.25.1