public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Various OF cleanups
@ 2010-03-11 17:31 Grant Likely
  2010-03-11 17:31 ` [PATCH 1/3] of/flattree: make of_fdt.h safe to unconditionally include Grant Likely
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Grant Likely @ 2010-03-11 17:31 UTC (permalink / raw)
  To: devicetree-discuss, benh, davem, jeremy.kerr, monstr; +Cc: linux-kernel

Here are some simple fixes to make the OF header files safe to include
when CONFIG_OF is not set, and add some debug context messages.

Cheers,
g.

---

Grant Likely (3):
      of: protect contents of of_platform.h and of_device.h
      of/flattree: Make unflatten_device_tree() safe to call from any arch
      of/flattree: make of_fdt.h safe to unconditionally include.


 drivers/of/fdt.c            |   15 +++++++++++++++
 include/linux/of_device.h   |    2 ++
 include/linux/of_fdt.h      |    4 ++++
 include/linux/of_platform.h |    2 ++
 4 files changed, 23 insertions(+), 0 deletions(-)

-- 
Signature

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] of/flattree: make of_fdt.h safe to unconditionally include.
  2010-03-11 17:31 [PATCH 0/3] Various OF cleanups Grant Likely
@ 2010-03-11 17:31 ` Grant Likely
  2010-03-11 17:32 ` [PATCH 2/3] of/flattree: Make unflatten_device_tree() safe to call from any arch Grant Likely
  2010-03-11 17:32 ` [PATCH 3/3] of: protect contents of of_platform.h and of_device.h Grant Likely
  2 siblings, 0 replies; 6+ messages in thread
From: Grant Likely @ 2010-03-11 17:31 UTC (permalink / raw)
  To: devicetree-discuss, benh, davem, jeremy.kerr, monstr; +Cc: linux-kernel

If CONFIG_OF_FLATTREE is not set, then don't process the body of
linux/of_fdt.h

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 include/linux/of_fdt.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index a1ca92c..f0fdd1f 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -57,6 +57,7 @@ struct boot_param_header {
 	__be32	dt_struct_size;		/* size of the DT structure block */
 };
 
+#if defined(CONFIG_OF_FLATTREE)
 /* TBD: Temporary export of fdt globals - remove when code fully merged */
 extern int __initdata dt_root_addr_cells;
 extern int __initdata dt_root_size_cells;
@@ -98,6 +99,7 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,
 /* Other Prototypes */
 extern void unflatten_device_tree(void);
 extern void early_init_devtree(void *);
+#endif /* CONFIG_OF_FLATTREE */
 
 #endif /* __ASSEMBLY__ */
 #endif /* _LINUX_OF_FDT_H */


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] of/flattree: Make unflatten_device_tree() safe to call from any arch
  2010-03-11 17:31 [PATCH 0/3] Various OF cleanups Grant Likely
  2010-03-11 17:31 ` [PATCH 1/3] of/flattree: make of_fdt.h safe to unconditionally include Grant Likely
@ 2010-03-11 17:32 ` Grant Likely
  2010-03-11 23:48   ` Stephen Rothwell
  2010-03-11 17:32 ` [PATCH 3/3] of: protect contents of of_platform.h and of_device.h Grant Likely
  2 siblings, 1 reply; 6+ messages in thread
From: Grant Likely @ 2010-03-11 17:32 UTC (permalink / raw)
  To: devicetree-discuss, benh, davem, jeremy.kerr, monstr; +Cc: linux-kernel

This patch makes unflatten_device_tree() safe to call from any arch
setup code with the following changes:
- Make sure initial_boot_params actually points to a device tree blob
  before unflattening
- Make sure the initial_boot_params->magic field is correct
- If CONFIG_OF_FLATTREE is not set, then make unflatten_device_tree()
  an empty #define.

This patch also adds some additional debug output to the top of
unflatten_device_tree().

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 drivers/of/fdt.c       |   15 +++++++++++++++
 include/linux/of_fdt.h |    2 ++
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 406757a..5ce7bd5 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -553,6 +553,21 @@ void __init unflatten_device_tree(void)
 
 	pr_debug(" -> unflatten_device_tree()\n");
 
+	if (!initial_boot_params) {
+		pr_debug("No device tree pointer\n");
+		return;
+	}
+
+	pr_debug("Unflattening device tree:\n");
+	pr_debug("magic: %08x\n", be32_to_cpu(initial_boot_params->magic));
+	pr_debug("size: %08x\n", be32_to_cpu(initial_boot_params->totalsize));
+	pr_debug("version: %08x\n", be32_to_cpu(initial_boot_params->version));
+
+	if (be32_to_cpu(initial_boot_params->magic) != OF_DT_HEADER) {
+		pr_err("Invalid device tree blob header\n");
+		return;
+	}
+
 	/* First pass, scan for size */
 	start = ((unsigned long)initial_boot_params) +
 		be32_to_cpu(initial_boot_params->off_dt_struct);
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index f0fdd1f..54399f1 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -99,6 +99,8 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,
 /* Other Prototypes */
 extern void unflatten_device_tree(void);
 extern void early_init_devtree(void *);
+#else /* CONFIG_OF_FLATTREE */
+static inline void define unflatten_device_tree(void) {}
 #endif /* CONFIG_OF_FLATTREE */
 
 #endif /* __ASSEMBLY__ */


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] of: protect contents of of_platform.h and of_device.h
  2010-03-11 17:31 [PATCH 0/3] Various OF cleanups Grant Likely
  2010-03-11 17:31 ` [PATCH 1/3] of/flattree: make of_fdt.h safe to unconditionally include Grant Likely
  2010-03-11 17:32 ` [PATCH 2/3] of/flattree: Make unflatten_device_tree() safe to call from any arch Grant Likely
@ 2010-03-11 17:32 ` Grant Likely
  2 siblings, 0 replies; 6+ messages in thread
From: Grant Likely @ 2010-03-11 17:32 UTC (permalink / raw)
  To: devicetree-discuss, benh, davem, jeremy.kerr, monstr; +Cc: linux-kernel

Only process contents of of_platform.h and of_device.h if
CONFIG_OF_DEVICE is set.
---

 include/linux/of_device.h   |    2 ++
 include/linux/of_platform.h |    2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index d3a74e0..e7904a9 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -1,6 +1,7 @@
 #ifndef _LINUX_OF_DEVICE_H
 #define _LINUX_OF_DEVICE_H
 
+#ifdef CONFIG_OF_DEVICE
 #include <linux/device.h>
 #include <linux/of.h>
 #include <linux/mod_devicetable.h>
@@ -26,5 +27,6 @@ static inline void of_device_free(struct of_device *dev)
 
 extern ssize_t of_device_get_modalias(struct of_device *ofdev,
 					char *str, ssize_t len);
+#endif /* CONFIG_OF_DEVICE */
 
 #endif /* _LINUX_OF_DEVICE_H */
diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h
index 9084066..ac3ae07 100644
--- a/include/linux/of_platform.h
+++ b/include/linux/of_platform.h
@@ -11,6 +11,7 @@
  *
  */
 
+#ifdef CONFIG_OF_DEVICE
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
@@ -66,5 +67,6 @@ static inline void of_unregister_platform_driver(struct of_platform_driver *drv)
 extern struct of_device *of_find_device_by_node(struct device_node *np);
 
 extern int of_bus_type_init(struct bus_type *bus, const char *name);
+#endif /* CONFIG_OF_DEVICE */
 
 #endif	/* _LINUX_OF_PLATFORM_H */


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] of/flattree: Make unflatten_device_tree() safe to call from any arch
  2010-03-11 17:32 ` [PATCH 2/3] of/flattree: Make unflatten_device_tree() safe to call from any arch Grant Likely
@ 2010-03-11 23:48   ` Stephen Rothwell
  2010-03-12  4:55     ` Grant Likely
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Rothwell @ 2010-03-11 23:48 UTC (permalink / raw)
  To: Grant Likely
  Cc: devicetree-discuss, benh, davem, jeremy.kerr, monstr,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 868 bytes --]

Hi Grant,

On Thu, 11 Mar 2010 10:32:03 -0700 Grant Likely <grant.likely@secretlab.ca> wrote:
>
> - If CONFIG_OF_FLATTREE is not set, then make unflatten_device_tree()
>   an empty #define.

"an empty static inline funtion."

> diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
> index f0fdd1f..54399f1 100644
> --- a/include/linux/of_fdt.h
> +++ b/include/linux/of_fdt.h
> @@ -99,6 +99,8 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,
>  /* Other Prototypes */
>  extern void unflatten_device_tree(void);
>  extern void early_init_devtree(void *);
> +#else /* CONFIG_OF_FLATTREE */
> +static inline void define unflatten_device_tree(void) {}
                      ^^^^^^
You need to remove that.

-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] of/flattree: Make unflatten_device_tree() safe to  call from any arch
  2010-03-11 23:48   ` Stephen Rothwell
@ 2010-03-12  4:55     ` Grant Likely
  0 siblings, 0 replies; 6+ messages in thread
From: Grant Likely @ 2010-03-12  4:55 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: devicetree-discuss, benh, davem, jeremy.kerr, monstr,
	linux-kernel

On Thu, Mar 11, 2010 at 4:48 PM, Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> Hi Grant,
>
> On Thu, 11 Mar 2010 10:32:03 -0700 Grant Likely <grant.likely@secretlab.ca> wrote:
>>
>> - If CONFIG_OF_FLATTREE is not set, then make unflatten_device_tree()
>>   an empty #define.
>
> "an empty static inline funtion."
>
>> diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
>> index f0fdd1f..54399f1 100644
>> --- a/include/linux/of_fdt.h
>> +++ b/include/linux/of_fdt.h
>> @@ -99,6 +99,8 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname,
>>  /* Other Prototypes */
>>  extern void unflatten_device_tree(void);
>>  extern void early_init_devtree(void *);
>> +#else /* CONFIG_OF_FLATTREE */
>> +static inline void define unflatten_device_tree(void) {}
>                      ^^^^^^
> You need to remove that.

Fixed.  Thanks.

g.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-03-12  4:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-11 17:31 [PATCH 0/3] Various OF cleanups Grant Likely
2010-03-11 17:31 ` [PATCH 1/3] of/flattree: make of_fdt.h safe to unconditionally include Grant Likely
2010-03-11 17:32 ` [PATCH 2/3] of/flattree: Make unflatten_device_tree() safe to call from any arch Grant Likely
2010-03-11 23:48   ` Stephen Rothwell
2010-03-12  4:55     ` Grant Likely
2010-03-11 17:32 ` [PATCH 3/3] of: protect contents of of_platform.h and of_device.h Grant Likely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox