Re: [PATCH] of: of_net: add support to parse ASCII encoded mac-addresses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 07, 2023 at 07:07:43PM +0200, Marco Felsch wrote:
> Some vendors like Polyhex store the MAC address ASCII encoded instead of
> using the plain 6-byte MAC address. This commit adds the support to
> decode the 12-byte ASCII encoded MAC addresses.

The upstream i.MX8MP dtsi files have "mac-address" nvmem cells described
in the device trees, but they point to a 6-byte long cell in ocotp.
These cells are not overwritten in the Polyhex dts files. How can there
be a 12-byte ASCII stored?

> 
> Signed-off-by: Marco Felsch <m.felsch@xxxxxxxxxxxxxx>
> ---
>  drivers/of/of_net.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
> index 75a24073da51..4e74986cdda8 100644
> --- a/drivers/of/of_net.c
> +++ b/drivers/of/of_net.c
> @@ -79,6 +79,8 @@ static int of_get_mac_addr(struct device_node *np, const char *name, u8 *addr)
>  	return -ENODEV;
>  }
>  
> +#define ETH_ALEN_ASCII	12
> +
>  int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
>  {
>  	struct nvmem_cell *cell;
> @@ -98,6 +100,23 @@ int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
>  	if (IS_ERR(mac))
>  		return PTR_ERR(mac);
>  
> +	if (len == ETH_ALEN_ASCII) {

I don't like this heuristic very much. If I understand the nvmem stuff
correctly then parsing of properties in non standard formats should be
fixed in a struct nvmem_cell_info::read_post_process hook.

> +		u8 *mac_new;
> +		int ret;
> +
> +		mac_new = kzalloc(sizeof("xx:xx:xx:xx:xx:xx"), GFP_KERNEL);

If anything, then sizeof("xxxxxxxxxxxx"), but what you want here is
ETH_ALEN.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux