devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of/fdt: fix error checking for earlycon address
@ 2015-10-23 11:47 Masahiro Yamada
  2015-10-23 13:15 ` Peter Hurley
  2015-10-29  4:07 ` Rob Herring
  0 siblings, 2 replies; 5+ messages in thread
From: Masahiro Yamada @ 2015-10-23 11:47 UTC (permalink / raw)
  To: devicetree
  Cc: Rob Herring, linux-serial, Peter Hurley, Masahiro Yamada,
	Frank Rowand, Rob Herring, linux-kernel, Grant Likely

fdt_translate_address() returns OF_BAD_ADDR on error.  It is defined as
a u64 value, so the variable "addr" should be defined as u64 as well.

Fixes: fb11ffe74c79 ("of/fdt: add FDT serial scanning for earlycon")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 drivers/of/fdt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 9fc3568..196e449 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -822,14 +822,15 @@ static int __init early_init_dt_scan_chosen_serial(void)
 		return -ENODEV;
 
 	while (match->compatible[0]) {
-		unsigned long addr;
+		u64 addr;
+
 		if (fdt_node_check_compatible(fdt, offset, match->compatible)) {
 			match++;
 			continue;
 		}
 
 		addr = fdt_translate_address(fdt, offset);
-		if (!addr)
+		if (addr == OF_BAD_ADDR)
 			return -ENXIO;
 
 		of_setup_earlycon(addr, match->data);
-- 
1.9.1

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

* Re: [PATCH] of/fdt: fix error checking for earlycon address
  2015-10-23 11:47 [PATCH] of/fdt: fix error checking for earlycon address Masahiro Yamada
@ 2015-10-23 13:15 ` Peter Hurley
       [not found]   ` <562A32EA.20808-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
  2015-10-29  4:07 ` Rob Herring
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Hurley @ 2015-10-23 13:15 UTC (permalink / raw)
  To: Masahiro Yamada, devicetree
  Cc: Rob Herring, linux-serial, Frank Rowand, Rob Herring,
	linux-kernel, Grant Likely, Ley Foon Tan

Hi Masahiro,

On 10/23/2015 07:47 AM, Masahiro Yamada wrote:
> fdt_translate_address() returns OF_BAD_ADDR on error.  It is defined as
> a u64 value, so the variable "addr" should be defined as u64 as well.

Good catch.

I would prefer if fdt_translate_address() returned resource_size_t (which
is the proper type for handling addresses as integers) and that type
was propagated through early_init_dt_scan_chosen_serial => of_setup_earlycon.

Regards,
Peter Hurley


PS - It seems that there is a new user of fdt_translate_address() in the
nios arch:

commit e8bf5bc776edef44777b13b2eb4461d653519bae
Author: Ley Foon Tan <lftan@altera.com>
Date:   Tue Feb 10 23:21:08 2015 +0800

    nios2: add early printk support
    
    Signed-off-by: Ley Foon Tan <lftan@altera.com>

I've copied the author as that should have been an earlycon in the
altera uart driver(s) rather than early_printk. Oh well.


> Fixes: fb11ffe74c79 ("of/fdt: add FDT serial scanning for earlycon")
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
> 
>  drivers/of/fdt.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 9fc3568..196e449 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -822,14 +822,15 @@ static int __init early_init_dt_scan_chosen_serial(void)
>  		return -ENODEV;
>  
>  	while (match->compatible[0]) {
> -		unsigned long addr;
> +		u64 addr;
> +
>  		if (fdt_node_check_compatible(fdt, offset, match->compatible)) {
>  			match++;
>  			continue;
>  		}
>  
>  		addr = fdt_translate_address(fdt, offset);
> -		if (!addr)
> +		if (addr == OF_BAD_ADDR)
>  			return -ENXIO;
>  
>  		of_setup_earlycon(addr, match->data);
> 

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

* Re: [PATCH] of/fdt: fix error checking for earlycon address
       [not found]   ` <562A32EA.20808-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
@ 2015-10-27 20:46     ` Rob Herring
       [not found]       ` <CAL_JsqK6UJxvGt3_y5T+VMxpr7G=PCmQ_Nx0QW-EfeTHOCDMKQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Rob Herring @ 2015-10-27 20:46 UTC (permalink / raw)
  To: Peter Hurley
  Cc: Masahiro Yamada,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Frank Rowand,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Grant Likely, Ley Foon Tan

On Fri, Oct 23, 2015 at 8:15 AM, Peter Hurley <peter-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org> wrote:
> Hi Masahiro,
>
> On 10/23/2015 07:47 AM, Masahiro Yamada wrote:
>> fdt_translate_address() returns OF_BAD_ADDR on error.  It is defined as
>> a u64 value, so the variable "addr" should be defined as u64 as well.
>
> Good catch.
>
> I would prefer if fdt_translate_address() returned resource_size_t (which
> is the proper type for handling addresses as integers) and that type
> was propagated through early_init_dt_scan_chosen_serial => of_setup_earlycon.

That can be problematic in the DT code. The size of resource_size_t
can vary on 32-bit as it is based on phys_addr_t which in turn is
based on CONFIG_LPAE setting. However, the address sizes in DT are
fixed and may be 64-bit. So we stick with u64 in the DT code.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] of/fdt: fix error checking for earlycon address
       [not found]       ` <CAL_JsqK6UJxvGt3_y5T+VMxpr7G=PCmQ_Nx0QW-EfeTHOCDMKQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2015-10-28 14:56         ` Peter Hurley
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Hurley @ 2015-10-28 14:56 UTC (permalink / raw)
  To: Rob Herring
  Cc: Masahiro Yamada,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Frank Rowand,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Grant Likely, Ley Foon Tan

On 10/27/2015 04:46 PM, Rob Herring wrote:
> On Fri, Oct 23, 2015 at 8:15 AM, Peter Hurley <peter-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org> wrote:
>> Hi Masahiro,
>>
>> On 10/23/2015 07:47 AM, Masahiro Yamada wrote:
>>> fdt_translate_address() returns OF_BAD_ADDR on error.  It is defined as
>>> a u64 value, so the variable "addr" should be defined as u64 as well.
>>
>> Good catch.
>>
>> I would prefer if fdt_translate_address() returned resource_size_t (which
>> is the proper type for handling addresses as integers) and that type
>> was propagated through early_init_dt_scan_chosen_serial => of_setup_earlycon.
> 
> That can be problematic in the DT code. The size of resource_size_t
> can vary on 32-bit as it is based on phys_addr_t which in turn is
> based on CONFIG_LPAE setting. However, the address sizes in DT are
> fixed and may be 64-bit. So we stick with u64 in the DT code.

I think I see your point about fdt_translate_address(); you want it to
mirror of_translate_address(), yes?  If so, then I have no objection
to this patch and will mark it reviewed.

But the u64 value from fdt_translate_address() should be preserved
at least to the ioremap()/set_fixmap() in earlycon_map() .
I could roll that change into my earlycon series that moves
fdt_translate_address() into of_setup_earlycon(), thus preserving
the u64 value until it's assigned to a phys_addr_t.

Regards,
Peter Hurley
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] of/fdt: fix error checking for earlycon address
  2015-10-23 11:47 [PATCH] of/fdt: fix error checking for earlycon address Masahiro Yamada
  2015-10-23 13:15 ` Peter Hurley
@ 2015-10-29  4:07 ` Rob Herring
  1 sibling, 0 replies; 5+ messages in thread
From: Rob Herring @ 2015-10-29  4:07 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: devicetree@vger.kernel.org, linux-serial@vger.kernel.org,
	Peter Hurley, Frank Rowand, linux-kernel@vger.kernel.org,
	Grant Likely

On Fri, Oct 23, 2015 at 6:47 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> fdt_translate_address() returns OF_BAD_ADDR on error.  It is defined as
> a u64 value, so the variable "addr" should be defined as u64 as well.
>
> Fixes: fb11ffe74c79 ("of/fdt: add FDT serial scanning for earlycon")
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Applied, thanks.

Rob

> ---
>
>  drivers/of/fdt.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 9fc3568..196e449 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -822,14 +822,15 @@ static int __init early_init_dt_scan_chosen_serial(void)
>                 return -ENODEV;
>
>         while (match->compatible[0]) {
> -               unsigned long addr;
> +               u64 addr;
> +
>                 if (fdt_node_check_compatible(fdt, offset, match->compatible)) {
>                         match++;
>                         continue;
>                 }
>
>                 addr = fdt_translate_address(fdt, offset);
> -               if (!addr)
> +               if (addr == OF_BAD_ADDR)
>                         return -ENXIO;
>
>                 of_setup_earlycon(addr, match->data);
> --
> 1.9.1
>

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

end of thread, other threads:[~2015-10-29  4:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-23 11:47 [PATCH] of/fdt: fix error checking for earlycon address Masahiro Yamada
2015-10-23 13:15 ` Peter Hurley
     [not found]   ` <562A32EA.20808-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2015-10-27 20:46     ` Rob Herring
     [not found]       ` <CAL_JsqK6UJxvGt3_y5T+VMxpr7G=PCmQ_Nx0QW-EfeTHOCDMKQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-10-28 14:56         ` Peter Hurley
2015-10-29  4:07 ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).