diff mbox

[V1,10/29] xen/dts: Remove device_get_reg call in process_cpu_node

Message ID 1377701263-3319-11-git-send-email-julien.grall@linaro.org
State Superseded, archived
Headers show

Commit Message

Julien Grall Aug. 28, 2013, 2:47 p.m. UTC
The "reg" property is only composed of one uint32. device_get_reg can be
replaced by dt_read_number.

Signed-off-by: Julien Grall <julien.grall@linaro.org>

---
    Changes in v2:
        - Rework the commit message
---
 xen/common/device_tree.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Comments

Ian Campbell Sept. 6, 2013, 4:36 p.m. UTC | #1
On Wed, 2013-08-28 at 15:47 +0100, Julien Grall wrote:
> The "reg" property is only composed of one uint32. device_get_reg can be
> replaced by dt_read_number.
> 
> Signed-off-by: Julien Grall <julien.grall@linaro.org>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

Although I notice Linux has helpers like dt_property_read_u32 etc. Would
be useful for us too I suppose?

> 
> ---
>     Changes in v2:
>         - Rework the commit message
> ---
>  xen/common/device_tree.c |   19 ++++++++++++-------
>  1 file changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
> index 833d67d..9568250 100644
> --- a/xen/common/device_tree.c
> +++ b/xen/common/device_tree.c
> @@ -426,21 +426,26 @@ static void __init process_cpu_node(const void *fdt, int node,
>                                      u32 address_cells, u32 size_cells)
>  {
>      const struct fdt_property *prop;
> -    const u32 *cell;
> -    paddr_t start, size;
> -
> +    u32 cpuid;
> +    int len;
>  
> -    prop = fdt_get_property(fdt, node, "reg", NULL);
> +    prop = fdt_get_property(fdt, node, "reg", &len);
>      if ( !prop )
>      {
>          early_printk("fdt: node `%s': missing `reg' property\n", name);
>          return;
>      }
>  
> -    cell = (const u32 *)prop->data;
> -    device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
> +    if ( len < sizeof (cpuid) )
> +    {
> +        dt_printk("fdt: node `%s': `reg` property length is too short\n",
> +                  name);
> +        return;
> +    }
> +
> +    cpuid = dt_read_number((const __be32 *)prop->data, 1);
>  
> -    cpumask_set_cpu(start, &cpu_possible_map);
> +    cpumask_set_cpu(cpuid, &cpu_possible_map);
>  }
>  
>  static void __init process_multiboot_node(const void *fdt, int node,
Julien Grall Sept. 9, 2013, 9:43 a.m. UTC | #2
On 09/06/2013 05:36 PM, Ian Campbell wrote:
> On Wed, 2013-08-28 at 15:47 +0100, Julien Grall wrote:
>> The "reg" property is only composed of one uint32. device_get_reg can be
>> replaced by dt_read_number.
>>
>> Signed-off-by: Julien Grall <julien.grall@linaro.org>
>
> Acked-by: Ian Campbell <ian.campbell@citrix.com>
>
> Although I notice Linux has helpers like dt_property_read_u32 etc. Would
> be useful for us too I suppose?

The device tree API already have dt_property_read_u32. It was added by 
Chen a couple of weeks ago. But this function only works with the device 
tree structure.
Here, we are using the flat device tree, because the memory layout has 
not yet been setup (so no possibility to allocate memory for the structure).

>>
>> ---
>>      Changes in v2:
>>          - Rework the commit message
>> ---
>>   xen/common/device_tree.c |   19 ++++++++++++-------
>>   1 file changed, 12 insertions(+), 7 deletions(-)
>>
>> diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
>> index 833d67d..9568250 100644
>> --- a/xen/common/device_tree.c
>> +++ b/xen/common/device_tree.c
>> @@ -426,21 +426,26 @@ static void __init process_cpu_node(const void *fdt, int node,
>>                                       u32 address_cells, u32 size_cells)
>>   {
>>       const struct fdt_property *prop;
>> -    const u32 *cell;
>> -    paddr_t start, size;
>> -
>> +    u32 cpuid;
>> +    int len;
>>
>> -    prop = fdt_get_property(fdt, node, "reg", NULL);
>> +    prop = fdt_get_property(fdt, node, "reg", &len);
>>       if ( !prop )
>>       {
>>           early_printk("fdt: node `%s': missing `reg' property\n", name);
>>           return;
>>       }
>>
>> -    cell = (const u32 *)prop->data;
>> -    device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
>> +    if ( len < sizeof (cpuid) )
>> +    {
>> +        dt_printk("fdt: node `%s': `reg` property length is too short\n",
>> +                  name);
>> +        return;
>> +    }
>> +
>> +    cpuid = dt_read_number((const __be32 *)prop->data, 1);
>>
>> -    cpumask_set_cpu(start, &cpu_possible_map);
>> +    cpumask_set_cpu(cpuid, &cpu_possible_map);
>>   }
>>
>>   static void __init process_multiboot_node(const void *fdt, int node,
>
>
diff mbox

Patch

diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c
index 833d67d..9568250 100644
--- a/xen/common/device_tree.c
+++ b/xen/common/device_tree.c
@@ -426,21 +426,26 @@  static void __init process_cpu_node(const void *fdt, int node,
                                     u32 address_cells, u32 size_cells)
 {
     const struct fdt_property *prop;
-    const u32 *cell;
-    paddr_t start, size;
-
+    u32 cpuid;
+    int len;
 
-    prop = fdt_get_property(fdt, node, "reg", NULL);
+    prop = fdt_get_property(fdt, node, "reg", &len);
     if ( !prop )
     {
         early_printk("fdt: node `%s': missing `reg' property\n", name);
         return;
     }
 
-    cell = (const u32 *)prop->data;
-    device_tree_get_reg(&cell, address_cells, size_cells, &start, &size);
+    if ( len < sizeof (cpuid) )
+    {
+        dt_printk("fdt: node `%s': `reg` property length is too short\n",
+                  name);
+        return;
+    }
+
+    cpuid = dt_read_number((const __be32 *)prop->data, 1);
 
-    cpumask_set_cpu(start, &cpu_possible_map);
+    cpumask_set_cpu(cpuid, &cpu_possible_map);
 }
 
 static void __init process_multiboot_node(const void *fdt, int node,