# Re: \[RFC PATCH net-next 4/7\] net: ethtool: add a netlink command to list PHYs

- From: Maxime Chevallier \<maxime.chevallier@bootlin.com\>
- Date: 2023-09-07 15:31:44 
- List: netdev
- Page: https://ratatoskr.run/netdev/2023/09/2326096
- Thread: https://ratatoskr.run/netdev/2023/09/2326448/t.md

```text
Hello Russell,

On Thu, 7 Sep 2023 11:00:24 +0100
"Russell King (Oracle)" [ref] wrote:

> On Thu, Sep 07, 2023 at 11:24:02AM +0200, Maxime Chevallier wrote:
> > +#define PHY_MAX_ENTRIES	16
> > +
> > +struct phy_list_reply_data {
> > +	struct ethnl_reply_data		base;
> > +	u8 n_phys;
> > +	u32 phy_indices[PHY_MAX_ENTRIES];  
> 
> Please could you detail the decision making behind 16 entries - is this
> arbitary or based on something?
> 
> Also, please consider what we should do if we happen to have more than
> 16 entries.

Ah indeed it was totally arbitrary, the idea was to have a fixed-size
reply struct, so that we can populate the
ethnl_request_ops.reply_data_size field and not do any manual memory
management. But I can store a pointer to the array of phy devices,
dynamically allocated and we won't have to deal with this fixed,
arbitrary-sized array anymore.

Sorry for not documenting this.

> Finally, using u8 before an array of u32 can leave 3 bytes of padding.
> It would be better to use u32 for n_phys to avoid that padding.

Sure thing, I'll change this

> > +	mutex_lock(&phy_ns->ns_lock);
> > +	list_for_each_entry(phydev, &phy_ns->phys, node)
> > +		data->phy_indices[data->n_phys++] = phydev->phyindex;  
> 
> I think this loop should limit its iterations to ensure that the
> array can't overflow.

Thanks,

Maxime


```
