netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] device property: Don't overwrite addr when failing in device_get_mac_address
@ 2015-09-03 22:59 Julien Grall
  2015-09-04 14:03 ` Jeremy Linton
  2015-09-08 20:40 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Julien Grall @ 2015-09-03 22:59 UTC (permalink / raw)
  To: jeremy.linton, davem
  Cc: linux-kernel, Julien Grall, Greg Kroah-Hartman, netdev

The function device_get_mac_address is trying different property names
in order to get the mac address. To check the return value, the variable
addr (which contain the buffer pass by the caller) will be re-used. This
means that if the previous property is not found, the next property will
be read using a NULL buffer.

Therefore it's only possible to retrieve the mac if node contains a
property "mac-address". Fix it by using a temporary buffer for the
return value.

This has been introduced by commit 4c96b7dc0d393f12c17e0d81db15aa4a820a6ab3
"Add a matching set of device_ functions for determining mac/phy"

Signed-off-by: Julien Grall <julien.grall@citrix.com>
Cc: Jeremy Linton <jeremy.linton@arm.com>
Cc: David S. Miller <davem@davemloft.net>

---
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: netdev@vger.kernel.org
---
 drivers/base/property.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index ff03f23..2d75366 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -611,13 +611,15 @@ static void *device_get_mac_addr(struct device *dev,
 */
 void *device_get_mac_address(struct device *dev, char *addr, int alen)
 {
-	addr = device_get_mac_addr(dev, "mac-address", addr, alen);
-	if (addr)
-		return addr;
+	char *res;
 
-	addr = device_get_mac_addr(dev, "local-mac-address", addr, alen);
-	if (addr)
-		return addr;
+	res = device_get_mac_addr(dev, "mac-address", addr, alen);
+	if (res)
+		return res;
+
+	res = device_get_mac_addr(dev, "local-mac-address", addr, alen);
+	if (res)
+		return res;
 
 	return device_get_mac_addr(dev, "address", addr, alen);
 }
-- 
2.1.4

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

* Re: [PATCH] device property: Don't overwrite addr when failing in device_get_mac_address
  2015-09-03 22:59 [PATCH] device property: Don't overwrite addr when failing in device_get_mac_address Julien Grall
@ 2015-09-04 14:03 ` Jeremy Linton
  2015-09-08 20:40 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Jeremy Linton @ 2015-09-04 14:03 UTC (permalink / raw)
  To: Julien Grall, davem; +Cc: linux-kernel, Greg Kroah-Hartman, netdev

On 09/03/2015 05:59 PM, Julien Grall wrote:
> The function device_get_mac_address is trying different property names
> in order to get the mac address. To check the return value, the variable
> addr (which contain the buffer pass by the caller) will be re-used. This
> means that if the previous property is not found, the next property will
> be read using a NULL buffer.

Thanks for catching that! I checked the OF version to see if it has the 
same problem, but of course it doesn't because I added the logic to pass 
the buffer into the routine.

Reviewed-by: Jeremy Linton <jeremy.linton@arm.com>

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

* Re: [PATCH] device property: Don't overwrite addr when failing in device_get_mac_address
  2015-09-03 22:59 [PATCH] device property: Don't overwrite addr when failing in device_get_mac_address Julien Grall
  2015-09-04 14:03 ` Jeremy Linton
@ 2015-09-08 20:40 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-09-08 20:40 UTC (permalink / raw)
  To: julien.grall; +Cc: jeremy.linton, linux-kernel, gregkh, netdev

From: Julien Grall <julien.grall@citrix.com>
Date: Thu, 3 Sep 2015 23:59:50 +0100

> The function device_get_mac_address is trying different property names
> in order to get the mac address. To check the return value, the variable
> addr (which contain the buffer pass by the caller) will be re-used. This
> means that if the previous property is not found, the next property will
> be read using a NULL buffer.
> 
> Therefore it's only possible to retrieve the mac if node contains a
> property "mac-address". Fix it by using a temporary buffer for the
> return value.
> 
> This has been introduced by commit 4c96b7dc0d393f12c17e0d81db15aa4a820a6ab3
> "Add a matching set of device_ functions for determining mac/phy"
> 
> Signed-off-by: Julien Grall <julien.grall@citrix.com>

Applied, thanks.

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

end of thread, other threads:[~2015-09-08 20:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-03 22:59 [PATCH] device property: Don't overwrite addr when failing in device_get_mac_address Julien Grall
2015-09-04 14:03 ` Jeremy Linton
2015-09-08 20:40 ` David Miller

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).