All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] of_net: factor out repetitive code from of_get_mac_address()
@ 2015-03-18 19:25 Sergei Shtylyov
  2015-03-18 19:29 ` David Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sergei Shtylyov @ 2015-03-18 19:25 UTC (permalink / raw)
  To: grant.likely, robh+dt, devicetree, f.fainelli, netdev

of_get_mac_address() basically does the same  thing thrice, every  time with  a
different  property  name,  so it makes sense to factor out the repetitive code
into separate function. While at it, we can start using ETH_ALEN instead of the
bare number and drop unnecessary parens around the property length check.

The resulting ARM object file is 100 bytes less in size than before the patch.

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

---
The patch is against Grant Likely's 'linux.git' repo's 'devicetree/next' branch.

 drivers/of/of_net.c |   29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

Index: linux/drivers/of/of_net.c
===================================================================
--- linux.orig/drivers/of/of_net.c
+++ linux/drivers/of/of_net.c
@@ -38,6 +38,15 @@ int of_get_phy_mode(struct device_node *
 }
 EXPORT_SYMBOL_GPL(of_get_phy_mode);
 
+static const void *of_get_mac_addr(struct device_node *np, const char *name)
+{
+	struct property *pp = of_find_property(np, name, NULL);
+
+	if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value))
+		return pp->value;
+	return NULL;
+}
+
 /**
  * Search the device tree for the best MAC address to use.  'mac-address' is
  * checked first, because that is supposed to contain to "most recent" MAC
@@ -58,20 +67,16 @@ EXPORT_SYMBOL_GPL(of_get_phy_mode);
 */
 const void *of_get_mac_address(struct device_node *np)
 {
-	struct property *pp;
+	const void *addr;
 
-	pp = of_find_property(np, "mac-address", NULL);
-	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-		return pp->value;
+	addr = of_get_mac_addr(np, "mac-address");
+	if (addr)
+		return addr;
 
-	pp = of_find_property(np, "local-mac-address", NULL);
-	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-		return pp->value;
+	addr = of_get_mac_addr(np, "local-mac-address");
+	if (addr)
+		return addr;
 
-	pp = of_find_property(np, "address", NULL);
-	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
-		return pp->value;
-
-	return NULL;
+	return of_get_mac_addr(np, "address");
 }
 EXPORT_SYMBOL(of_get_mac_address);

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

* Re: [PATCH] of_net: factor out repetitive code from of_get_mac_address()
  2015-03-18 19:25 [PATCH] of_net: factor out repetitive code from of_get_mac_address() Sergei Shtylyov
@ 2015-03-18 19:29 ` David Miller
  2015-03-28 13:27   ` Grant Likely
       [not found] ` <1776166.J84mUn2Yu8-gHKXc3Y1Z8zGSmamagVegGFoWSdPRAKMAL8bYrjMMd8@public.gmane.org>
  2015-03-28 13:34 ` Grant Likely
  2 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2015-03-18 19:29 UTC (permalink / raw)
  To: sergei.shtylyov; +Cc: grant.likely, robh+dt, devicetree, f.fainelli, netdev

From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Date: Wed, 18 Mar 2015 22:25:46 +0300

> of_get_mac_address() basically does the same  thing thrice, every  time with  a
> different  property  name,  so it makes sense to factor out the repetitive code
> into separate function. While at it, we can start using ETH_ALEN instead of the
> bare number and drop unnecessary parens around the property length check.
> 
> The resulting ARM object file is 100 bytes less in size than before the patch.
> 
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> 
> ---
> The patch is against Grant Likely's 'linux.git' repo's 'devicetree/next' branch.

Acked-by: David S. Miller <davem@davemloft.net>

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

* Re: [PATCH] of_net: factor out repetitive code from of_get_mac_address()
       [not found] ` <1776166.J84mUn2Yu8-gHKXc3Y1Z8zGSmamagVegGFoWSdPRAKMAL8bYrjMMd8@public.gmane.org>
@ 2015-03-18 19:46   ` Florian Fainelli
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Fainelli @ 2015-03-18 19:46 UTC (permalink / raw)
  To: Sergei Shtylyov, grant.likely-QSEj5FYQhm4dnm+yROfE0A,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	devicetree-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA

On 18/03/15 12:25, Sergei Shtylyov wrote:
> of_get_mac_address() basically does the same  thing thrice, every  time with  a
> different  property  name,  so it makes sense to factor out the repetitive code
> into separate function. While at it, we can start using ETH_ALEN instead of the
> bare number and drop unnecessary parens around the property length check.
> 
> The resulting ARM object file is 100 bytes less in size than before the patch.
> 
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov-M4DtvfQ/ZS1MRgGoP+s0PdBPR1lH4CV8@public.gmane.org>

Acked-by: Florian Fainelli <f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

> 
> ---
> The patch is against Grant Likely's 'linux.git' repo's 'devicetree/next' branch.
> 
>  drivers/of/of_net.c |   29 +++++++++++++++++------------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 
> Index: linux/drivers/of/of_net.c
> ===================================================================
> --- linux.orig/drivers/of/of_net.c
> +++ linux/drivers/of/of_net.c
> @@ -38,6 +38,15 @@ int of_get_phy_mode(struct device_node *
>  }
>  EXPORT_SYMBOL_GPL(of_get_phy_mode);
>  
> +static const void *of_get_mac_addr(struct device_node *np, const char *name)
> +{
> +	struct property *pp = of_find_property(np, name, NULL);
> +
> +	if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value))
> +		return pp->value;
> +	return NULL;
> +}
> +
>  /**
>   * Search the device tree for the best MAC address to use.  'mac-address' is
>   * checked first, because that is supposed to contain to "most recent" MAC
> @@ -58,20 +67,16 @@ EXPORT_SYMBOL_GPL(of_get_phy_mode);
>  */
>  const void *of_get_mac_address(struct device_node *np)
>  {
> -	struct property *pp;
> +	const void *addr;
>  
> -	pp = of_find_property(np, "mac-address", NULL);
> -	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> -		return pp->value;
> +	addr = of_get_mac_addr(np, "mac-address");
> +	if (addr)
> +		return addr;
>  
> -	pp = of_find_property(np, "local-mac-address", NULL);
> -	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> -		return pp->value;
> +	addr = of_get_mac_addr(np, "local-mac-address");
> +	if (addr)
> +		return addr;
>  
> -	pp = of_find_property(np, "address", NULL);
> -	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> -		return pp->value;
> -
> -	return NULL;
> +	return of_get_mac_addr(np, "address");
>  }
>  EXPORT_SYMBOL(of_get_mac_address);
> 


-- 
Florian
--
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] 6+ messages in thread

* Re: [PATCH] of_net: factor out repetitive code from of_get_mac_address()
  2015-03-18 19:29 ` David Miller
@ 2015-03-28 13:27   ` Grant Likely
  0 siblings, 0 replies; 6+ messages in thread
From: Grant Likely @ 2015-03-28 13:27 UTC (permalink / raw)
  To: David Miller, sergei.shtylyov; +Cc: robh+dt, devicetree, f.fainelli, netdev

On Wed, 18 Mar 2015 15:29:33 -0400 (EDT)
, David Miller <davem@davemloft.net>
 wrote:
> From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> Date: Wed, 18 Mar 2015 22:25:46 +0300
> 
> > of_get_mac_address() basically does the same  thing thrice, every  time with  a
> > different  property  name,  so it makes sense to factor out the repetitive code
> > into separate function. While at it, we can start using ETH_ALEN instead of the
> > bare number and drop unnecessary parens around the property length check.
> > 
> > The resulting ARM object file is 100 bytes less in size than before the patch.
> > 
> > Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> > 
> > ---
> > The patch is against Grant Likely's 'linux.git' repo's 'devicetree/next' branch.
> 
> Acked-by: David S. Miller <davem@davemloft.net>

Applied for v4.1, thanks.

g.

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

* Re: [PATCH] of_net: factor out repetitive code from of_get_mac_address()
  2015-03-18 19:25 [PATCH] of_net: factor out repetitive code from of_get_mac_address() Sergei Shtylyov
  2015-03-18 19:29 ` David Miller
       [not found] ` <1776166.J84mUn2Yu8-gHKXc3Y1Z8zGSmamagVegGFoWSdPRAKMAL8bYrjMMd8@public.gmane.org>
@ 2015-03-28 13:34 ` Grant Likely
  2015-03-28 17:17   ` Sergei Shtylyov
  2 siblings, 1 reply; 6+ messages in thread
From: Grant Likely @ 2015-03-28 13:34 UTC (permalink / raw)
  To: Sergei Shtylyov, robh+dt, devicetree, f.fainelli, netdev

On Wed, 18 Mar 2015 22:25:46 +0300
, Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
 wrote:
> of_get_mac_address() basically does the same  thing thrice, every  time with  a
> different  property  name,  so it makes sense to factor out the repetitive code
> into separate function. While at it, we can start using ETH_ALEN instead of the
> bare number and drop unnecessary parens around the property length check.
> 
> The resulting ARM object file is 100 bytes less in size than before the patch.
> 
> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> 
> ---
> The patch is against Grant Likely's 'linux.git' repo's 'devicetree/next' branch.

Thanks for looking at this, I've merged it.

Since you're already playing with this, could you also write a unittest
of of_get_mac_addr()? (drivers/of/unittest.c & drivers/of/unittest-data)

g.

> 
>  drivers/of/of_net.c |   29 +++++++++++++++++------------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 
> Index: linux/drivers/of/of_net.c
> ===================================================================
> --- linux.orig/drivers/of/of_net.c
> +++ linux/drivers/of/of_net.c
> @@ -38,6 +38,15 @@ int of_get_phy_mode(struct device_node *
>  }
>  EXPORT_SYMBOL_GPL(of_get_phy_mode);
>  
> +static const void *of_get_mac_addr(struct device_node *np, const char *name)
> +{
> +	struct property *pp = of_find_property(np, name, NULL);
> +
> +	if (pp && pp->length == ETH_ALEN && is_valid_ether_addr(pp->value))
> +		return pp->value;
> +	return NULL;
> +}
> +
>  /**
>   * Search the device tree for the best MAC address to use.  'mac-address' is
>   * checked first, because that is supposed to contain to "most recent" MAC
> @@ -58,20 +67,16 @@ EXPORT_SYMBOL_GPL(of_get_phy_mode);
>  */
>  const void *of_get_mac_address(struct device_node *np)
>  {
> -	struct property *pp;
> +	const void *addr;
>  
> -	pp = of_find_property(np, "mac-address", NULL);
> -	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> -		return pp->value;
> +	addr = of_get_mac_addr(np, "mac-address");
> +	if (addr)
> +		return addr;
>  
> -	pp = of_find_property(np, "local-mac-address", NULL);
> -	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> -		return pp->value;
> +	addr = of_get_mac_addr(np, "local-mac-address");
> +	if (addr)
> +		return addr;
>  
> -	pp = of_find_property(np, "address", NULL);
> -	if (pp && (pp->length == 6) && is_valid_ether_addr(pp->value))
> -		return pp->value;
> -
> -	return NULL;
> +	return of_get_mac_addr(np, "address");
>  }
>  EXPORT_SYMBOL(of_get_mac_address);
> 

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

* Re: [PATCH] of_net: factor out repetitive code from of_get_mac_address()
  2015-03-28 13:34 ` Grant Likely
@ 2015-03-28 17:17   ` Sergei Shtylyov
  0 siblings, 0 replies; 6+ messages in thread
From: Sergei Shtylyov @ 2015-03-28 17:17 UTC (permalink / raw)
  To: Grant Likely, robh+dt, devicetree, f.fainelli, netdev

Hello.

On 03/28/2015 04:34 PM, Grant Likely wrote:

>> of_get_mac_address() basically does the same  thing thrice, every  time with  a
>> different  property  name,  so it makes sense to factor out the repetitive code
>> into separate function. While at it, we can start using ETH_ALEN instead of the
>> bare number and drop unnecessary parens around the property length check.

>> The resulting ARM object file is 100 bytes less in size than before the patch.

>> Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

>> ---
>> The patch is against Grant Likely's 'linux.git' repo's 'devicetree/next' branch.

> Thanks for looking at this, I've merged it.

> Since you're already playing with this, could you also write a unittest
> of of_get_mac_addr()? (drivers/of/unittest.c & drivers/of/unittest-data)

    Unfortunately, I'm constantly low on time. Even this patch was done on 
weekend.

> g.

WBR, Sergei

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

end of thread, other threads:[~2015-03-28 17:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-18 19:25 [PATCH] of_net: factor out repetitive code from of_get_mac_address() Sergei Shtylyov
2015-03-18 19:29 ` David Miller
2015-03-28 13:27   ` Grant Likely
     [not found] ` <1776166.J84mUn2Yu8-gHKXc3Y1Z8zGSmamagVegGFoWSdPRAKMAL8bYrjMMd8@public.gmane.org>
2015-03-18 19:46   ` Florian Fainelli
2015-03-28 13:34 ` Grant Likely
2015-03-28 17:17   ` Sergei Shtylyov

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.