Re: [PATCH v7 1/3] vdpa: support set mac address from vdpa tool

From: Cindy Lu
Date: Mon Jul 29 2024 - 21:28:38 EST


On Tue, 30 Jul 2024 at 03:13, Andrew Lunn <andrew@xxxxxxx> wrote:
>
> > +static int vdpa_dev_net_device_attr_set(struct vdpa_device *vdev,
> > + struct genl_info *info)
> > +{
> > + struct vdpa_dev_set_config set_config = {};
> > + struct vdpa_mgmt_dev *mdev = vdev->mdev;
> > + struct nlattr **nl_attrs = info->attrs;
> > + const u8 *macaddr;
> > + int err = -EINVAL;
> > +
> > + down_write(&vdev->cf_lock);
> > + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]) {
> > + set_config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR);
> > + macaddr = nla_data(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]);
> > +
> > + if (is_valid_ether_addr(macaddr)) {
> > + ether_addr_copy(set_config.net.mac, macaddr);
> > + memcpy(set_config.net.mac, macaddr, ETH_ALEN);
>
> ether_addr_copy() and memcpy()?
>
> > + if (mdev->ops->dev_set_attr) {
> > + err = mdev->ops->dev_set_attr(mdev, vdev,
> > + &set_config);
> > + } else {
> > + NL_SET_ERR_MSG_FMT_MOD(info->extack,
> > + "device does not support changing the MAC address");
>
> You would generally return EOPNOTSUPP in this case, not EINVAL.
>
> Also, the device does not support setting attributes. Given the
> generic name, i assume you plan to set other attributes in the future,
> at which point this error message will be wrong.
>
sure, will fix this
Thanks
cindy
> Andrew
>