All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andres Salomon <dilinger@queued.net>
To: Andres Salomon <dilinger@queued.net>
Cc: Daniel Drake <dsd@laptop.org>,
	David Woodhouse <dwmw2@infradead.org>,
	cbou@mail.ru, linux-kernel@vger.kernel.org, x86@kernel.org,
	tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	dmitry.torokhov@gmail.com,
	Grant Likely <grant.likely@secretlab.ca>,
	devicetree-discuss@lists.ozlabs.org,
	Mitch Bradley <wmb@laptop.org>,
	"David S. Miller" <davem@davemloft.net>,
	sparclinux@vger.kernel.org
Subject: [PATCH] of/pdt: don't bother parsing pkg2path results, return as-is
Date: Sat, 19 Feb 2011 03:12:25 +0000	[thread overview]
Message-ID: <20110218191225.5e38b8bc@queued.net> (raw)
In-Reply-To: <20110218190659.7f955e4c@queued.net>

On Fri, 18 Feb 2011 19:06:59 -0800
Andres Salomon <dilinger@queued.net> wrote:

> On Fri, 18 Feb 2011 23:42:57 +0000
> Daniel Drake <dsd@laptop.org> wrote:
> 
> > On 16 February 2011 22:44, David Woodhouse <dwmw2@infradead.org>
> > wrote:
> > > On Wed, 2011-02-16 at 22:28 +0000, Daniel Drake wrote:
> > >>
> > >> +static int __init add_common_platform_devices(void)
> > >> +{
> > >> +       struct platform_device *pdev;
> > >> +
> > >> +       pdev = platform_device_register_simple("olpc-battery",
> > >> -1, NULL, 0);
> > >> +       if (IS_ERR(pdev))
> > >> +               return PTR_ERR(pdev);
> > >> +
> > >> +       return 0;
> > >> +}
> > >> +
> > >
> > > Still kind of sucks that you have to do this, and can't bind to
> > > something in the device-tree.
> > 
> > OK, feel free to put this patch on hold for now. I started looking
> > at the device tree approach today. It looks doable but first we
> > have to fix a DT bug/inconsistency that is preventing us from
> > correctly binding to the tree's devices.
> > 
> > Daniel
> 
> 
> Mea culpa.  The patch below fixes a bug I introduced earlier.
> Cc'ing the sparc folks, as this probably affects them
> (although I would think that it fixes broken behavior for them..?)
> 
> 
> 

And this is a followup to the prior patch; an optimization based
upon what we're doing with pkg2path stuff.

The sparc folks don't use pkg2path, so this shouldn't affect them at
all.

Cc'ing Mitch as well, in case there's some reason why I should be
wary of doing this.  :)




From: Andres Salomon <dilinger@queued.net>

The of_pdt_try_pkg2path() function currently allocates memory for
and fetches the full path name from OFW (of the form '/foo/bar/baz@0').
It then returns only the name ('baz@0)', and the caller re-constructs
the full name (for dp->full_name) based upon dp->parent->full_name and
what was returned by of_pdt_try_pkg2path().  Oh, and it allocates more
memory for it.

OLPC is the only architecture which fills in the pkg2path hook, so
this shouldn't affect any other users (ie, sparc).  Since in practice
(dp->parent->full_name + '/' + strrchr(pkg2path, '/')) and the result
from pkg2path end up being exactly the same, just short circuit the rest
of the of_pdt_build_full_name logic and set dp->full_name to the result
of pkg2path.  This means we don't have to parse it nor allocate more
memory for it.

This saves time, code, and memory.

Signed-off-by: Andres Salomon <dilinger@queued.net>
---
 drivers/of/pdt.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index b39d584..605834b 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -134,7 +134,7 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,13 +147,7 @@ static char * __init of_pdt_try_pkg2path(phandle node)
 		pr_err("%s: package-to-path failed\n", __func__);
 		return NULL;
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__, buf);
-		return NULL;
-	}
-	return res+1;
+	return buf;
 }
 
 static struct device_node * __init of_pdt_create_node(phandle node,
@@ -193,10 +187,13 @@ static char * __init of_pdt_build_full_name(struct device_node *dp,
 	 * name property (ie, 'battery'), we want the name we see with
 	 * package-to-path (ie, 'battery@0').
 	 */
+	n = of_pdt_try_pkg2path(node);
+	if (n)
+		return n;
+
+	/* Older methods for determining full name */
 	name = of_pdt_node_name(dp);
 	if (!name)
-		name = of_pdt_try_pkg2path(node);
-	if (!name)
 		name = dp->name;
 
 	plen = strlen(dp->parent->full_name);
-- 
1.7.2.3


WARNING: multiple messages have this Message-ID (diff)
From: Andres Salomon <dilinger@queued.net>
To: Andres Salomon <dilinger@queued.net>
Cc: Daniel Drake <dsd@laptop.org>,
	David Woodhouse <dwmw2@infradead.org>,
	cbou@mail.ru, linux-kernel@vger.kernel.org, x86@kernel.org,
	tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	dmitry.torokhov@gmail.com,
	Grant Likely <grant.likely@secretlab.ca>,
	devicetree-discuss@lists.ozlabs.org,
	Mitch Bradley <wmb@laptop.org>,
	"David S. Miller" <davem@davemloft.net>,
	sparclinux@vger.kernel.org
Subject: [PATCH] of/pdt: don't bother parsing pkg2path results, return as-is
Date: Fri, 18 Feb 2011 19:12:25 -0800	[thread overview]
Message-ID: <20110218191225.5e38b8bc@queued.net> (raw)
In-Reply-To: <20110218190659.7f955e4c@queued.net>

On Fri, 18 Feb 2011 19:06:59 -0800
Andres Salomon <dilinger@queued.net> wrote:

> On Fri, 18 Feb 2011 23:42:57 +0000
> Daniel Drake <dsd@laptop.org> wrote:
> 
> > On 16 February 2011 22:44, David Woodhouse <dwmw2@infradead.org>
> > wrote:
> > > On Wed, 2011-02-16 at 22:28 +0000, Daniel Drake wrote:
> > >>
> > >> +static int __init add_common_platform_devices(void)
> > >> +{
> > >> +       struct platform_device *pdev;
> > >> +
> > >> +       pdev = platform_device_register_simple("olpc-battery",
> > >> -1, NULL, 0);
> > >> +       if (IS_ERR(pdev))
> > >> +               return PTR_ERR(pdev);
> > >> +
> > >> +       return 0;
> > >> +}
> > >> +
> > >
> > > Still kind of sucks that you have to do this, and can't bind to
> > > something in the device-tree.
> > 
> > OK, feel free to put this patch on hold for now. I started looking
> > at the device tree approach today. It looks doable but first we
> > have to fix a DT bug/inconsistency that is preventing us from
> > correctly binding to the tree's devices.
> > 
> > Daniel
> 
> 
> Mea culpa.  The patch below fixes a bug I introduced earlier.
> Cc'ing the sparc folks, as this probably affects them
> (although I would think that it fixes broken behavior for them..?)
> 
> 
> 

And this is a followup to the prior patch; an optimization based
upon what we're doing with pkg2path stuff.

The sparc folks don't use pkg2path, so this shouldn't affect them at
all.

Cc'ing Mitch as well, in case there's some reason why I should be
wary of doing this.  :)




From: Andres Salomon <dilinger@queued.net>

The of_pdt_try_pkg2path() function currently allocates memory for
and fetches the full path name from OFW (of the form '/foo/bar/baz@0').
It then returns only the name ('baz@0)', and the caller re-constructs
the full name (for dp->full_name) based upon dp->parent->full_name and
what was returned by of_pdt_try_pkg2path().  Oh, and it allocates more
memory for it.

OLPC is the only architecture which fills in the pkg2path hook, so
this shouldn't affect any other users (ie, sparc).  Since in practice
(dp->parent->full_name + '/' + strrchr(pkg2path, '/')) and the result
from pkg2path end up being exactly the same, just short circuit the rest
of the of_pdt_build_full_name logic and set dp->full_name to the result
of pkg2path.  This means we don't have to parse it nor allocate more
memory for it.

This saves time, code, and memory.

Signed-off-by: Andres Salomon <dilinger@queued.net>
---
 drivers/of/pdt.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index b39d584..605834b 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -134,7 +134,7 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,13 +147,7 @@ static char * __init of_pdt_try_pkg2path(phandle node)
 		pr_err("%s: package-to-path failed\n", __func__);
 		return NULL;
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__, buf);
-		return NULL;
-	}
-	return res+1;
+	return buf;
 }
 
 static struct device_node * __init of_pdt_create_node(phandle node,
@@ -193,10 +187,13 @@ static char * __init of_pdt_build_full_name(struct device_node *dp,
 	 * name property (ie, 'battery'), we want the name we see with
 	 * package-to-path (ie, 'battery@0').
 	 */
+	n = of_pdt_try_pkg2path(node);
+	if (n)
+		return n;
+
+	/* Older methods for determining full name */
 	name = of_pdt_node_name(dp);
 	if (!name)
-		name = of_pdt_try_pkg2path(node);
-	if (!name)
 		name = dp->name;
 
 	plen = strlen(dp->parent->full_name);
-- 
1.7.2.3


WARNING: multiple messages have this Message-ID (diff)
From: Andres Salomon <dilinger@queued.net>
To: Andres Salomon <dilinger@queued.net>
Cc: Daniel Drake <dsd@laptop.org>,
	David Woodhouse <dwmw2@infradead.org>,
	cbou@mail.ru, linux-kernel@vger.kernel.org, x86@kernel.org,
	tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	dmitry.torokhov@gmail.com,
	Grant Likely <grant.likely@secretlab.ca>,
	devicetree-discuss@lists.ozlabs.org,
	Mitch Bradley <wmb@laptop.org>,
	"David S. Miller" <davem@davemloft.net>,
	sparclinux@vger.kernel.org
Subject: [PATCH] of/pdt: don't bother parsing pkg2path results, return as-is
Date: Fri, 18 Feb 2011 19:12:25 -0800	[thread overview]
Message-ID: <20110218191225.5e38b8bc@queued.net> (raw)
In-Reply-To: <20110218190659.7f955e4c@queued.net>

On Fri, 18 Feb 2011 19:06:59 -0800
Andres Salomon <dilinger@queued.net> wrote:

> On Fri, 18 Feb 2011 23:42:57 +0000
> Daniel Drake <dsd@laptop.org> wrote:
> 
> > On 16 February 2011 22:44, David Woodhouse <dwmw2@infradead.org>
> > wrote:
> > > On Wed, 2011-02-16 at 22:28 +0000, Daniel Drake wrote:
> > >>
> > >> +static int __init add_common_platform_devices(void)
> > >> +{
> > >> +       struct platform_device *pdev;
> > >> +
> > >> +       pdev = platform_device_register_simple("olpc-battery",
> > >> -1, NULL, 0);
> > >> +       if (IS_ERR(pdev))
> > >> +               return PTR_ERR(pdev);
> > >> +
> > >> +       return 0;
> > >> +}
> > >> +
> > >
> > > Still kind of sucks that you have to do this, and can't bind to
> > > something in the device-tree.
> > 
> > OK, feel free to put this patch on hold for now. I started looking
> > at the device tree approach today. It looks doable but first we
> > have to fix a DT bug/inconsistency that is preventing us from
> > correctly binding to the tree's devices.
> > 
> > Daniel
> 
> 
> Mea culpa.  The patch below fixes a bug I introduced earlier.
> Cc'ing the sparc folks, as this probably affects them
> (although I would think that it fixes broken behavior for them..?)
> 
> 
> 

And this is a followup to the prior patch; an optimization based
upon what we're doing with pkg2path stuff.

The sparc folks don't use pkg2path, so this shouldn't affect them at
all.

Cc'ing Mitch as well, in case there's some reason why I should be
wary of doing this.  :)




From: Andres Salomon <dilinger@queued.net>

The of_pdt_try_pkg2path() function currently allocates memory for
and fetches the full path name from OFW (of the form '/foo/bar/baz@0').
It then returns only the name ('baz@0)', and the caller re-constructs
the full name (for dp->full_name) based upon dp->parent->full_name and
what was returned by of_pdt_try_pkg2path().  Oh, and it allocates more
memory for it.

OLPC is the only architecture which fills in the pkg2path hook, so
this shouldn't affect any other users (ie, sparc).  Since in practice
(dp->parent->full_name + '/' + strrchr(pkg2path, '/')) and the result
from pkg2path end up being exactly the same, just short circuit the rest
of the of_pdt_build_full_name logic and set dp->full_name to the result
of pkg2path.  This means we don't have to parse it nor allocate more
memory for it.

This saves time, code, and memory.

Signed-off-by: Andres Salomon <dilinger@queued.net>
---
 drivers/of/pdt.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index b39d584..605834b 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -134,7 +134,7 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
 
 static char * __init of_pdt_try_pkg2path(phandle node)
 {
-	char *res, *buf = NULL;
+	char *buf = NULL;
 	int len;
 
 	if (!of_pdt_prom_ops->pkg2path)
@@ -147,13 +147,7 @@ static char * __init of_pdt_try_pkg2path(phandle node)
 		pr_err("%s: package-to-path failed\n", __func__);
 		return NULL;
 	}
-
-	res = strrchr(buf, '/');
-	if (!res) {
-		pr_err("%s: couldn't find / in %s\n", __func__, buf);
-		return NULL;
-	}
-	return res+1;
+	return buf;
 }
 
 static struct device_node * __init of_pdt_create_node(phandle node,
@@ -193,10 +187,13 @@ static char * __init of_pdt_build_full_name(struct device_node *dp,
 	 * name property (ie, 'battery'), we want the name we see with
 	 * package-to-path (ie, 'battery@0').
 	 */
+	n = of_pdt_try_pkg2path(node);
+	if (n)
+		return n;
+
+	/* Older methods for determining full name */
 	name = of_pdt_node_name(dp);
 	if (!name)
-		name = of_pdt_try_pkg2path(node);
-	if (!name)
 		name = dp->name;
 
 	plen = strlen(dp->parent->full_name);
-- 
1.7.2.3

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

  reply	other threads:[~2011-02-19  3:12 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16 22:28 [PATCH v3] olpc_battery: convert to platform device Daniel Drake
2011-02-16 22:34 ` Dmitry Torokhov
2011-02-16 22:44 ` David Woodhouse
2011-02-16 23:39   ` H. Peter Anvin
2011-02-18 23:42   ` Daniel Drake
2011-02-19  3:06     ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-19  3:06       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Andres Salomon
2011-02-19  3:06       ` Andres Salomon
2011-02-19  3:12       ` Andres Salomon [this message]
2011-02-19  3:12         ` [PATCH] of/pdt: don't bother parsing pkg2path results, return as-is Andres Salomon
2011-02-19  3:12         ` Andres Salomon
2011-02-23 19:45         ` [PATCH] of/pdt: don't bother parsing pkg2path results, return Grant Likely
2011-02-23 19:45           ` [PATCH] of/pdt: don't bother parsing pkg2path results, return as-is Grant Likely
2011-02-23 19:45           ` Grant Likely
2011-02-23 19:43       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-23 19:43         ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Grant Likely
2011-02-23 19:43         ` Grant Likely
2011-02-23 19:54         ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-23 19:54           ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Andres Salomon
2011-02-23 19:54           ` Andres Salomon
2011-02-23 20:06           ` Daniel Drake
2011-02-23 20:06             ` Daniel Drake
     [not found]             ` <AANLkTi=D1eWGsN4JVWEGeHp3AXfpbOOKr9Fq7juGAXtT-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-02-23 20:37               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-23 20:37                 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Grant Likely
2011-02-23 20:37                 ` Grant Likely
2011-02-23 20:35           ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-23 20:35             ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness Grant Likely
2011-02-23 23:03       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-23 23:03         ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Andres Salomon
     [not found]         ` <20110223150357.5a40793d-pFFUokh25LWsTnJN9+BGXg@public.gmane.org>
2011-02-23 23:28           ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-23 23:28             ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Grant Likely
2011-02-23 23:28             ` Grant Likely
2011-02-24  0:16             ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  0:16               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Andres Salomon
2011-02-24  4:06               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-24  4:06                 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Grant Likely
     [not found]                 ` <20110224040638.GB22111-MrY2KI0G/OVr83L8+7iqerDks+cytr/Z@public.gmane.org>
2011-02-24  4:36                   ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  4:36                     ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Andres Salomon
2011-02-24  4:36                     ` Andres Salomon
2011-02-24  5:38                     ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-24  5:38                       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v2) Grant Likely
2011-02-24  6:38                       ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  6:38                         ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v4) Andres Salomon
2011-02-24  0:34             ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  0:34               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) Andres Salomon
2011-02-24  2:47               ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-24  2:47                 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) Grant Likely
2011-02-24  2:51                 ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Andres Salomon
2011-02-24  2:51                   ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) Andres Salomon
2011-02-24  3:25                   ` [PATCH] of/pdt: allow DT device matching by fixing 'name' Grant Likely
2011-02-24  3:25                     ` [PATCH] of/pdt: allow DT device matching by fixing 'name' brokenness (v3) 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=20110218191225.5e38b8bc@queued.net \
    --to=dilinger@queued.net \
    --cc=cbou@mail.ru \
    --cc=davem@davemloft.net \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dsd@laptop.org \
    --cc=dwmw2@infradead.org \
    --cc=grant.likely@secretlab.ca \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=sparclinux@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wmb@laptop.org \
    --cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.