public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stephen Warren <swarren@wwwdotorg.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] dm: fdtdec: Check full path for alias
Date: Thu, 14 Apr 2016 09:24:54 -0600	[thread overview]
Message-ID: <570FB646.1000408@wwwdotorg.org> (raw)
In-Reply-To: <8e099aeaccd18d6dd51fb6252a4f12031f140e89.1460638938.git.michal.simek@xilinx.com>

On 04/14/2016 07:02 AM, Michal Simek wrote:
> Fix fdtdec_get_alias_seq() which is not checking full path to certain
> node and it incorrectly provides incorrect seq number.
> Checking full path ensure that if alias is present correct seq number is
> return.
> This problem was found on ZynqMP zcu102 where are several I2C muxes
> where the first bus name is i2c at 0 and for following muxes incorrect seq
> numbers are return.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
> I am not sure if there is any macro for max alias length which I can use
> instead of new macro.

> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 70acc29c924d..79efcf0cd6b0 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -506,6 +506,8 @@ int fdtdec_add_aliases_for_id(const void *blob, const char *name,
>   	return num_found;
>   }
>
> +#define FDT_ALIAS_PATH_LEN	64
> +
>   int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
>   			 int *seqp)
>   {
> @@ -514,9 +516,13 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
>   	int find_namelen;
>   	int prop_offset;
>   	int aliases;
> +	char buf[FDT_ALIAS_PATH_LEN];
> +
> +	fdt_get_path(blob, offset, buf, sizeof(buf));

Rather the getting the path of the object, and then comparing it against 
the alias, you could check each component separately, and hence not need 
to ever generate the full concatenated path. That would be a lot slower 
though.

Another thought is a variant of fdt_get_path() which also returns the 
required length of the path, so you could do something like:

buf = malloc(DEFAULT_LEN);
ret = fdt_get_path(blob, offset, buf, DEFAULT_LEN, &required_len);
if (ret == -ENOSPC)
     buf = realloc(buf, required_len);
     ret = fdt_get_path(blob, offset, buf, required_len, &required_len);
}
if (ret)
     return ret;

> @@ -533,6 +539,13 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,

> +		/* Check full path first not to point to incorrect alias */
> +		if (strncmp(prop, buf, min(len, FDT_ALIAS_PATH_LEN)))
> +			continue;
> +
>   		slash = strrchr(prop, '/');
>   		if (strcmp(slash + 1, find_name))
>   			continue;

I would expect the existing check to completely replace the original 
one. IIUC, the comparison is required to be via the full path, and the 
existing code is simply a bug for simplicity.

  reply	other threads:[~2016-04-14 15:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-14 13:02 [U-Boot] [PATCH] dm: fdtdec: Check full path for alias Michal Simek
2016-04-14 15:24 ` Stephen Warren [this message]
2016-04-20 14:41 ` Simon Glass
2016-04-21  4:47   ` Michal Simek
2016-05-01 18:54     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=570FB646.1000408@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox