Re: [PATCH v2 next-next] net: hns: enet specifies a reference to dsaf

From: Andy Shevchenko
Date: Thu Jan 14 2016 - 04:44:40 EST


On Thu, 2016-01-14 at 11:00 +0800, Yisen Zhuang wrote:
>
> å 2016/1/13 11:14, Kejian Yan åé:
> > This patch replace the assoication between dsaf and enet from
> > string
> > matching to object reference. It requires the DTS to be updated
> > within
> > BIOS. Thanks god it can be done for all released boards.
> >
>
> Hi kejian,
>
> This patch is fine to me.

There are few thing below.

>Â
> > --- a/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
> > +++ b/drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
> > @@ -847,6 +847,7 @@ static struct hnae_ae_ops hns_dsaf_ops = {
> > Âint hns_dsaf_ae_init(struct dsaf_device *dsaf_dev)
> > Â{
> > Â struct hnae_ae_dev *ae_dev = &dsaf_dev->ae_dev;
> > + static atomic_t id = ATOMIC_INIT(-1);
> > Â
> > Â switch (dsaf_dev->dsaf_ver) {
> > Â case AE_VERSION_1:
> > @@ -858,6 +859,9 @@ int hns_dsaf_ae_init(struct dsaf_device
> > *dsaf_dev)
> > Â default:
> > Â break;
> > Â }
> > +
> > + snprintf(ae_dev->name, AE_NAME_SIZE, "%s%d",
> > DSAF_DEVICE_NAME,
> > + Â(int)atomic_inc_return(&id));

If you bind/unbind device enough times you may get an overflow and end
up with name of existing device (if you have 1+ of them in the system).

To avoid such situation better to use IDA/IDR framework.

>
> > --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> > +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
> > @@ -1802,7 +1802,7 @@ static int hns_nic_try_get_ae(struct
> > net_device *ndev)
> > Â int ret;
> > Â
> > Â h = hnae_get_handle(&priv->netdev->dev,
> > - ÂÂÂÂpriv->ae_name, priv->port_id, NULL);
> > + ÂÂÂÂpriv->ae_node, priv->port_id, NULL);
> > Â if (IS_ERR_OR_NULL(h)) {
> > Â ret = PTR_ERR(h);
> > Â dev_dbg(priv->dev, "has not handle, register
> > notifier!\n");
> > @@ -1880,9 +1880,12 @@ static int hns_nic_dev_probe(struct
> > platform_device *pdev)
> > Â else
> > Â priv->enet_ver = AE_VERSION_2;
> > Â
> > - ret = of_property_read_string(node, "ae-name", &priv-
> > >ae_name);
> > - if (ret)
> > - goto out_read_string_fail;

(1)

> > + priv->ae_node = (void *)of_parse_phandle(node, "ae-
> > handle", 0);
> > + if (IS_ERR_OR_NULL(priv->ae_node)) {
> > + ret = PTR_ERR(priv->ae_node);
> > + dev_err(dev, "not find ae-handle\n");
> > + goto out_read_handle_fai;

(2)

> > + }
> > Â
> > Â ret = of_property_read_u32(node, "port-id", &priv-
> > >port_id);
> > Â if (ret)
> > @@ -1945,6 +1948,8 @@ static int hns_nic_dev_probe(struct
> > platform_device *pdev)
> > Â
> > Âout_notify_fail:
> > Â (void)cancel_work_sync(&priv->service_task);
> > +out_read_handle_fai:

> > +

Redundant line

> > Âout_read_string_fail:

Leftover? (see (1) and (2) )

--
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy