From: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
To: grant.likely@linaro.org
Cc: robh+dt@kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Subject: [PATCH] of/base: Replace alias if it already exists
Date: Sun, 1 Jun 2014 15:01:23 +0300 [thread overview]
Message-ID: <1401624083-30796-1-git-send-email-ivo.g.dimitrov.75@gmail.com> (raw)
The current code unconditionally adds aliases without check if it already
exists, so it is not possible to alter an alias, from board DT file for
example. Fix that by replacing an alias if it already exists
Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
---
drivers/of/base.c | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 03e7fc6..99215f0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2036,6 +2036,23 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np,
ap->alias, ap->stem, ap->id, of_node_full_name(np));
}
+static int of_alias_replace(struct device_node *np, int id, const char *stem,
+ int stem_len)
+{
+ struct alias_prop *ap;
+
+ list_for_each_entry(ap, &aliases_lookup, link) {
+ if (strncmp(ap->stem, stem, stem_len))
+ continue;
+
+ if (np == ap->np) {
+ ap->id = id;
+ return 0;
+ }
+ }
+
+ return -ENODEV;
+}
/**
* of_alias_scan - Scan all properties of 'aliases' node
*
@@ -2092,13 +2109,16 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align))
if (kstrtoint(end, 10, &id) < 0)
continue;
- /* Allocate an alias_prop with enough space for the stem */
- ap = dt_alloc(sizeof(*ap) + len + 1, 4);
- if (!ap)
- continue;
- memset(ap, 0, sizeof(*ap) + len + 1);
- ap->alias = start;
- of_alias_add(ap, np, id, start, len);
+ if (of_alias_replace(np, id, start, len)) {
+ /* Allocate an alias_prop with enough space for the stem
+ */
+ ap = dt_alloc(sizeof(*ap) + len + 1, 4);
+ if (!ap)
+ continue;
+ memset(ap, 0, sizeof(*ap) + len + 1);
+ ap->alias = start;
+ of_alias_add(ap, np, id, start, len);
+ }
}
}
--
1.7.9.5
next reply other threads:[~2014-06-01 12:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-01 12:01 Ivaylo Dimitrov [this message]
[not found] ` <1401624083-30796-1-git-send-email-ivo.g.dimitrov.75-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-02 14:59 ` [PATCH] of/base: Replace alias if it already exists Grant Likely
2014-06-02 16:07 ` Ivaylo Dimitrov
[not found] ` <538CA125.7090906-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-03 8:53 ` Grant Likely
[not found] ` <20140603085325.490A1C4096E-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-06-03 9:58 ` Ivaylo Dimitrov
[not found] ` <538D9C42.9040707-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-03 17:09 ` Ivaylo Dimitrov
[not found] ` <538E0144.1050700-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-06-03 22:54 ` Grant Likely
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=1401624083-30796-1-git-send-email-ivo.g.dimitrov.75@gmail.com \
--to=ivo.g.dimitrov.75@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=grant.likely@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).