Hi Niklas,
On Fri, Aug 31, 2018 at 9:57 AM Niklas Söderlund
<[email protected]> wrote:
> On 2018-08-31 00:10:28 +0200, Geert Uytterhoeven wrote:
> > On Thu, Aug 30, 2018 at 11:39 PM Niklas Söderlund
> > <[email protected]> wrote:
> > > Fix warning when running with CONFIG_DMA_API_DEBUG_SG=y by allocating a
> > > device_dma_parameters structure and filling in the max segment size. The
> > > size used is the result of a discussion with Renesas hardware engineers
> > > and unfortunately not found in the datasheet.
> > >
> > > renesas_sdhi_internal_dmac ee140000.sd: DMA-API: mapping sg segment
> > > longer than device claims to support [len=126976] [max=65536A]
> > > --- a/drivers/mmc/host/renesas_sdhi_internal_dmac.c
> > > +++ b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
> > > @@ -308,12 +308,23 @@ static const struct soc_device_attribute
> > > gen3_soc_whitelist[] = {
> > > static int renesas_sdhi_internal_dmac_probe(struct platform_device *pdev)
> > > {
> > > const struct soc_device_attribute *soc =
> > > soc_device_match(gen3_soc_whitelist);
> > > + struct device *dev = &pdev->dev;
> > >
> > > if (!soc)
> > > return -ENODEV;
> > >
> > > global_flags |= (unsigned long)soc->data;
> > >
> > > + if (!dev->dma_parms) {
> >
> > I guess dev->dma_parms is retained on unbind/rebind?
> >
> > > + dev->dma_parms = devm_kzalloc(dev,
> > > sizeof(*dev->dma_parms),
> > > + GFP_KERNEL);
> >
> > But by using devm_kzalloc(), the memory will be freed, and lead to reuse
> > after
> > free?
>
> I don't know how the unbind/rebind behaves in this regard. In v1 of this
I expect the struct device to be retained. You can check with sysfs unbind/bind,
and CONFIG_DEBUG_SLAB=y to enable poisoning on free (or just print
the value found for less spectacular behavior ;-)
> patch I used kzalloc() and a remove function to free the memory and
> reset the dev->dma_parms pointe to NULL. Do you think that is the
> correct approach here?
As a comment in the other thread said you should not set it multiple times,
probably the best solution is to:
(a) check if dev->dma_parms is already set, and if not:
(b) allocate using plain kzalloc() (with a comment why!),
(c) not free the memory nor reset dev->dma_parms (with a comment why!).
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds