[U-Boot,3/4] lib: decode_timing_property should return -NOENT when proprty is not found

Message ID 20190209133957.12713-4-megous@megous.com
State Superseded
Delegated to: Tom Rini
Headers show
Series
  • Random small sunxi fixes
Related show

Commit Message

Ondřej Jirman Feb. 9, 2019, 1:39 p.m.
From: Ondrej Jirman <megous@megous.com>

Length may be unitialized when fdt_getprop fails.

Signed-off-by: Ondřej Jirman <megous@megous.com>
---
 lib/fdtdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Glass Feb. 19, 2019, 3:17 p.m. | #1
Hi,

On Sat, 9 Feb 2019 at 06:44, <megous@megous.com> wrote:
>
> From: Ondrej Jirman <megous@megous.com>
>
> Length may be unitialized when fdt_getprop fails.

Not according to the docs:

 * if lenp is non-NULL, *lenp contains the length of the property
 * value (>=0)
 * NULL, on error
 * if lenp is non-NULL, *lenp contains an error code (<0):
 * -FDT_ERR_NOTFOUND, node does not have named property
 * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
 * tag
 * -FDT_ERR_BADMAGIC,
 * -FDT_ERR_BADVERSION,
 * -FDT_ERR_BADSTATE,
 * -FDT_ERR_BADSTRUCTURE,
 * -FDT_ERR_TRUNCATED, standard meanings

I suspect there might be a bug. Can you provide a few more details?

>
> Signed-off-by: Ondřej Jirman <megous@megous.com>
> ---
>  lib/fdtdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 18663ce6bd..3510de78e1 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -980,7 +980,7 @@ static int decode_timing_property(const void *blob, int node, const char *name,
>         if (!prop) {
>                 debug("%s: could not find property %s\n",
>                       fdt_get_name(blob, node, NULL), name);
> -               return length;
> +               return -ENOENT;
>         }
>
>         if (length == sizeof(u32)) {
> --
> 2.20.1
>

Regards,
Simon
Ondřej Jirman Feb. 19, 2019, 9:43 p.m. | #2
Hi,

On Tue, Feb 19, 2019 at 07:17:01AM -0800, Simon Glass wrote:
> Hi,
> 
> On Sat, 9 Feb 2019 at 06:44, <megous@megous.com> wrote:
> >
> > From: Ondrej Jirman <megous@megous.com>
> >
> > Length may be unitialized when fdt_getprop fails.
> 
> Not according to the docs:
> 
>  * if lenp is non-NULL, *lenp contains the length of the property
>  * value (>=0)
>  * NULL, on error
>  * if lenp is non-NULL, *lenp contains an error code (<0):
>  * -FDT_ERR_NOTFOUND, node does not have named property
>  * -FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE
>  * tag
>  * -FDT_ERR_BADMAGIC,
>  * -FDT_ERR_BADVERSION,
>  * -FDT_ERR_BADSTATE,
>  * -FDT_ERR_BADSTRUCTURE,
>  * -FDT_ERR_TRUNCATED, standard meanings

Ah, you're right.

> I suspect there might be a bug. Can you provide a few more details?

The return value of multiple decode_timing_property() calls is ORed together in
such a way in fdtdec_decode_display_timing() that it's pretty meaningless what
it is for each call, other than that it's < 0.

So you can ignore this patch.

regards,
  o.

> >
> > Signed-off-by: Ondřej Jirman <megous@megous.com>
> > ---
> >  lib/fdtdec.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> > index 18663ce6bd..3510de78e1 100644
> > --- a/lib/fdtdec.c
> > +++ b/lib/fdtdec.c
> > @@ -980,7 +980,7 @@ static int decode_timing_property(const void *blob, int node, const char *name,
> >         if (!prop) {
> >                 debug("%s: could not find property %s\n",
> >                       fdt_get_name(blob, node, NULL), name);
> > -               return length;
> > +               return -ENOENT;
> >         }
> >
> >         if (length == sizeof(u32)) {
> > --
> > 2.20.1
> >
> 
> Regards,
> Simon

Patch

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 18663ce6bd..3510de78e1 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -980,7 +980,7 @@  static int decode_timing_property(const void *blob, int node, const char *name,
 	if (!prop) {
 		debug("%s: could not find property %s\n",
 		      fdt_get_name(blob, node, NULL), name);
-		return length;
+		return -ENOENT;
 	}
 
 	if (length == sizeof(u32)) {