Re: [RFC PATCH net-next v4 2/3] net: stmmac: Add glue driver for Motorcomm YT6801 ethernet controller

Yao Zi
2025-12-23T17:41:55Z

On Sun, Dec 21, 2025 at 09:42:20PM +0100, Andrew Lunn wrote:
> > +static int motorcomm_efuse_read_patch(struct dwmac_motorcomm_priv *priv,
> > + u8 index,
> > + struct motorcomm_efuse_patch *patch)
> > +{
> > + u8 buf[sizeof(*patch)], offset;
> > + int i, ret;
> > +
> > + for (i = 0; i < sizeof(*patch); i++) {
> > + offset = EFUSE_PATCH_REGION_OFFSET + sizeof(*patch) * index + i;
> > +
> > + ret = motorcomm_efuse_read_byte(priv, offset, &buf[i]);
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + memcpy(patch, buf, sizeof(*patch));
>
> Why do you write it into a temporary buffer and then copy it to patch?
> Why not put it straight into patch?

Originally I wanted to avoid possible violation of pointer aliasing
rules, so write the RAW data to an extra buffer and do a memcpy() later.

But we have -fno-strict-aliasing in kernel, even without it accessing
any objects with character type should be okay. I'll remove buf and
write to patch directly in v5.

> > + ret = motorcomm_efuse_read_mac(priv, res.mac);
> > + if (ret == -ENOENT) {
> > + dev_warn(&pdev->dev, "eFuse contains no valid MAC address\n");
> > + dev_warn(&pdev->dev, "fallback to random MAC address\n");
> > +
> > + memset(res.mac, 0, sizeof(res.mac));
>
> It is not clear how setting this to zero results in a random MAC
> address. Maybe actually call eth_random_addr()?

stmmac_check_ether_addr() would generate a random MAC address through
eth_random_addr() if res.mac is all zeroes. But I agree calling
eth_random_addr() directly here would be clearer, will do it in v5.

> Andrew

Thanks for your review, happy holiday!

Regards,
Yao Zi