public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: "Petr Štetiar" <ynezz@true.cz>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>, Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Frank Rowand <frowand.list@gmail.com>,
	John Crispin <john@phrozen.org>, Felix Fietkau <nbd@nbd.name>
Subject: Re: [PATCH] of_net: add mtd-mac-address support to of_get_mac_address()
Date: Tue, 16 Apr 2019 17:29:16 -0700	[thread overview]
Message-ID: <d29bcf08-9299-8f2c-00bc-791b60658581@gmail.com> (raw)
In-Reply-To: <1555445100-30936-1-git-send-email-ynezz@true.cz>



On 16/04/2019 13:05, Petr Štetiar wrote:
> From: John Crispin <john@phrozen.org>
> 
> Many embedded devices have information such as MAC addresses stored
> inside MTD devices. This patch allows us to add a property inside a node
> describing a network interface. The new property points at a MTD
> partition with an offset where the MAC address can be found.
> 
> This patch has originated in OpenWrt some time ago, so in order to
> consider usefulness of this patch, here are some real-world numbers
> which hopefully speak for themselves:
> 
>   * mtd-mac-address                used 497 times in 357 device tree files
>   * mtd-mac-address-increment      used  74 times in  58 device tree files
>   * mtd-mac-address-increment-byte used   1 time  in   1 device tree file
> 
> Signed-off-by: John Crispin <john@phrozen.org>
> Signed-off-by: Felix Fietkau <nbd@nbd.name>
> [cleanup of the patch for upstream submission]
> Signed-off-by: Petr Štetiar <ynezz@true.cz>
> ---

[snip]

> +static const void *of_get_mac_address_mtd(struct device_node *np)
> +{
> +#ifdef CONFIG_MTD
> +	void *addr;
> +	size_t retlen;
> +	int size, ret;
> +	u8 mac[ETH_ALEN];
> +	phandle phandle;
> +	const char *part;
> +	const __be32 *list;
> +	struct mtd_info *mtd;
> +	struct property *prop;
> +	u32 mac_inc = 0;
> +	u32 inc_idx = ETH_ALEN-1;
> +	struct device_node *mtd_np = NULL;

Reverse christmas tree would look a bit nicer here.

> +
> +	list = of_get_property(np, "mtd-mac-address", &size);
> +	if (!list || (size != (2 * sizeof(*list))))
> +		return NULL;
> +
> +	phandle = be32_to_cpup(list++);
> +	if (phandle)
> +		mtd_np = of_find_node_by_phandle(phandle);
> +
> +	if (!mtd_np)
> +		return NULL;
> +
> +	part = of_get_property(mtd_np, "label", NULL);
> +	if (!part)
> +		part = mtd_np->name;
> +
> +	mtd = get_mtd_device_nm(part);
> +	if (IS_ERR(mtd))
> +		return NULL;
> +
> +	ret = mtd_read(mtd, be32_to_cpup(list), ETH_ALEN, &retlen, mac);
> +	put_mtd_device(mtd);
> +
> +	of_property_read_u32(np, "mtd-mac-address-increment-byte", &inc_idx);

of_property_read_u8() would probably be good here since this can't be 
bigger than 5 anyway.

> +	if (inc_idx > ETH_ALEN-1)
> +		return NULL; >
> +	if (!of_property_read_u32(np, "mtd-mac-address-increment", &mac_inc))
> +		mac[inc_idx] += mac_inc;

If I use a number greater than and included 128; this will cause a roll 
over, should this be range checked? Similarly, using 
of_property_read_u8() might be a better fit?

Other than those, LGTM
-- 
Florian

  reply	other threads:[~2019-04-17  0:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-16 20:05 [PATCH] of_net: add mtd-mac-address support to of_get_mac_address() Petr Štetiar
2019-04-17  0:29 ` Florian Fainelli [this message]
2019-04-17  3:01   ` Frank Rowand
2019-04-30  0:48     ` Rob Herring
2019-04-30  1:15       ` Frank Rowand
2019-04-17  5:00 ` Heiner Kallweit
2019-04-17  8:06 ` Maxime Ripard
2019-04-17  9:49   ` Petr Štetiar
2019-04-17 10:15     ` Maxime Ripard
2019-04-17 12:10       ` Petr Štetiar
2019-04-17 16:06   ` Petr Štetiar
2019-04-17 18:05     ` Maxime Ripard

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=d29bcf08-9299-8f2c-00bc-791b60658581@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=john@phrozen.org \
    --cc=mark.rutland@arm.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=ynezz@true.cz \
    /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