[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <SJ0PR11MB5072362B1C8DD994CEC9F54AF1D10@SJ0PR11MB5072.namprd11.prod.outlook.com>
Date: Tue, 5 Jan 2021 04:33:05 +0000
From: "Li, Meng" <Meng.Li@...driver.com>
To: Jim Quinlan <jim2101024@...il.com>,
Jim Quinlan <james.quinlan@...adcom.com>,
open list <linux-kernel@...r.kernel.org>
CC: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"rafael@...nel.org" <rafael@...nel.org>,
"Hao, Kexin" <Kexin.Hao@...driver.com>,
Christoph Hellwig <hch@....de>
Subject: RE: [PATCH] drivers core: Free dma_range_map when driver probe failed
> -----Original Message-----
> From: Jim Quinlan <jim2101024@...il.com>
> Sent: Monday, January 4, 2021 11:56 PM
> To: Jim Quinlan <james.quinlan@...adcom.com>; Li, Meng
> <Meng.Li@...driver.com>; open list <linux-kernel@...r.kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>; rafael@...nel.org;
> Hao, Kexin <Kexin.Hao@...driver.com>; Jim Quinlan
> <jim2101024@...il.com>; Christoph Hellwig <hch@....de>
> Subject: Re: [PATCH] drivers core: Free dma_range_map when driver probe
> failed
>
> > Subject: [PATCH] drivers core: Free dma_range_map when driver probe
> > failed
> >
> > There will be memory leak if driver probe failed. Trace as below:
> > backtrace:
> > [<000000002415258f>] kmemleak_alloc+0x3c/0x50
> > [<00000000f447ebe4>] __kmalloc+0x208/0x530
> > [<0000000048bc7b3a>] of_dma_get_range+0xe4/0x1b0
> > [<0000000041e39065>] of_dma_configure_id+0x58/0x27c
> > [<000000006356866a>] platform_dma_configure+0x2c/0x40
> > ......
> > [<000000000afcf9b5>] ret_from_fork+0x10/0x3c
> >
> > This issue is introduced by commit e0d072782c73("dma-mapping:
> > introduce DMA range map, supplanting dma_pfn_offset "). It doesn't
> > free dma_range_map when driver probe failed and cause above memory
> > leak. So, add code to free it in error path.
> >
> > Fixes: e0d072782c73("dma-mapping: introduce DMA range map,
> supplanting
> > dma_pfn_offset ")
> > Cc: stable@...r.kernel.org
> > Signed-off-by: Meng Li <Meng.Li@...driver.com>
> > ---
> > drivers/base/dd.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/base/dd.c b/drivers/base/dd.c index
> > 148e81969e04..8e4871aa34bc 100644
> > --- a/drivers/base/dd.c
> > +++ b/drivers/base/dd.c
> > @@ -612,6 +612,7 @@ static int really_probe(struct device *dev, struct
> > device_driver *drv)
> > else if (drv->remove)
> > drv->remove(dev);
> > probe_failed:
> > + kfree(dev->dma_range_map);
> > if (dev->bus)
> > blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
> >
> > BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
> > --
> > 2.17.1
> >
> > --
>
> Hi Meng,
>
> Sorry for the delay -- I was on vacation. I agree with you -- thanks.
> However, note that in function device_release() in drivers/base/core.c
> there is this line:
>
> kfree(dev->dma_range_map);
>
> Won't this also be called if all of the appropriate drivers' probes fail for this
> device, effecting a double kfree? Perhaps your patch could also set "dev-
> >dma_range_map" to NULL after calling kfree()?
>
Hi Jim,
Please discard my previous reply, because I had a misunderstand about what you suggested.
I agree with you total, and I will set dma_range_map as NULL in really_probe() function when driver probe failed.
I will sent V2 patch.
Thanks,
Limeng
> Thanks much,
> Jim Quinlan
> Broadcom STB
Powered by blists - more mailing lists