On Mon, Jul 04, 2022 at 02:34:31PM +0100, Kevin Laatz wrote:
> On 04/07/2022 14:19, Bruce Richardson wrote:
> > On Sun, Jul 03, 2022 at 01:22:41PM +0100, Kevin Laatz wrote:
> > > ASAN reports a memory leak for the 'pci' pointer in the 'idxd_dmadev'
> > > struct.
> > >
> > > This is fixed by free'ing the struct when the last queue on the PCI
> > > device is being closed.
> > >
> > > Fixes: 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
> > > Cc: sta...@dpdk.org
> > > Cc: bruce.richard...@intel.com
> > >
> > > Reported-by: Xingguang He <xingguang...@intel.com>
> > > Signed-off-by: Kevin Laatz <kevin.la...@intel.com>
> > > ---
> > > drivers/dma/idxd/idxd_common.c | 2 ++
> > > drivers/dma/idxd/idxd_internal.h | 2 ++
> > > drivers/dma/idxd/idxd_pci.c | 34 +++++++++++++++++++++++++-------
> > > 3 files changed, 31 insertions(+), 7 deletions(-)
> > >
> > Some comments inline below.
> >
> > /Bruce
> >
> > > diff --git a/drivers/dma/idxd/idxd_common.c
> > > b/drivers/dma/idxd/idxd_common.c
> > > index c77200a457..d347bbed21 100644
> > > --- a/drivers/dma/idxd/idxd_common.c
> > > +++ b/drivers/dma/idxd/idxd_common.c
> > > @@ -620,6 +620,8 @@ idxd_dmadev_create(const char *name, struct
> > > rte_device *dev,
> > > dmadev->fp_obj->dev_private = idxd;
> > > idxd->dmadev->state = RTE_DMA_DEV_READY;
> > > + if (idxd->u.pci != NULL)
> > > + rte_atomic16_inc(&idxd->u.pci->ref_count);
> > > return 0;
> > I don't think this belongs in the common code. Can it be put somewhere in
> > the pci-specific driver code to avoid issues, e.g. after idxd_dmadev_create
> > returns in probe_pci() function.
>
> Sure, I'll look to move it in v3.
>
> [snip]
> > @@ -159,12 +178,13 @@ init_pci_device(struct rte_pci_device *dev, struct
> > idxd_dmadev *idxd,
> > uint8_t lg2_max_batch, lg2_max_copy_size;
> > unsigned int i, err_code;
> > - pci = malloc(sizeof(*pci));
> > + pci = rte_malloc(NULL, sizeof(*pci), 0);
> > Any particular reason for the change from regular malloc to rte_malloc?
>
> Mainly consistency, its the only place in the driver where malloc is used
> instead of rte_malloc.
>
> I have no strong preference here - I can remove the change for v3.
>
If it's inconsistent with the rest, please do keep the change in v3.