> -----Original Message-----
> From: Stephen Hemminger [mailto:[email protected]]
> Sent: Friday, May 29, 2020 12:13 AM
> To: wangyunjian <[email protected]>
> Cc: [email protected]; [email protected]; Lilijun (Jerry)
> <[email protected]>; xudingke <[email protected]>;
> [email protected]
> Subject: Re: [dpdk-dev] [PATCH] bus/vmbus: fix wrong allocation for
> device.name
>
> On Thu, 28 May 2020 20:03:07 +0800
> wangyunjian <[email protected]> wrote:
>
> > From: Yunjian Wang <[email protected]>
> >
> > We do not need and should not allocate memory for device.name.
> > The device.name should be set point to the devargs->name.
> >
> > Fixes: 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
> > Cc: [email protected]
> >
> > Signed-off-by: Yunjian Wang <[email protected]>
> > ---
> > drivers/bus/vmbus/linux/vmbus_bus.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c
> b/drivers/bus/vmbus/linux/vmbus_bus.c
> > index 3c924ee..31d0dd3 100644
> > --- a/drivers/bus/vmbus/linux/vmbus_bus.c
> > +++ b/drivers/bus/vmbus/linux/vmbus_bus.c
> > @@ -242,9 +242,6 @@
> > return -1;
> >
> > dev->device.bus = &rte_vmbus_bus.bus;
> > - dev->device.name = strdup(name);
> > - if (!dev->device.name)
> > - goto error;
> >
> > /* sysfs base directory
> > * /sys/bus/vmbus/devices/7a08391f-f5a0-4ac0-9802-d13fd964f8df
> > @@ -296,6 +293,7 @@
> > }
> >
> > dev->device.devargs = vmbus_devargs_lookup(dev);
> > + dev->device.name = dev->device.devargs->name;
> >
> > /* device is valid, add in list (sorted) */
> > VMBUS_LOG(DEBUG, "Adding vmbus device %s", name);
>
> This doesn't seem right. devargs is not filled in unless devargs is used.
At present, the memory allocated for the device.name is not released
in the error handling code. I have not found the relevant code to release
the vmbus device, so I am not sure how to release it corrently.
Generally, the pointer of device.name should be set to another pointer.
However, it was defined as "const" pointer and could not be released directly.
Thanks,
Yunjian