Re: [PATCH 4/5] sh: split arch/sh/mm/consistent.c

From: Geert Uytterhoeven
Date: Mon Jul 23 2018 - 04:49:59 EST


Hi Jacopo,

On Mon, Jul 23, 2018 at 10:42 AM jacopo mondi <jacopo@xxxxxxxxxx> wrote:
> I have a single comment on something I noticed which might be an
> implementation bug. On the overall patch architecture, it's very hard
> for me to provide a valuable opinion as it's all relatively new for me
> here :)
>
> On Thu, Jul 19, 2018 at 06:05:15AM -0700, Christoph Hellwig wrote:
> > Half of the file just contains platform device memory setup code which
> > is required for all builds, and half contains helpers for dma coherent
> > allocation, which is only needed if CONFIG_DMA_NONCOHERENT is enabled.
> >
> > Signed-off-by: Christoph Hellwig <hch@xxxxxx>

> > --- /dev/null
> > +++ b/arch/sh/kernel/dma-coherent.c
> > @@ -0,0 +1,85 @@
> > +/*
> > + * Copyright (C) 2004 - 2007 Paul Mundt
> > + *
> > + * This file is subject to the terms and conditions of the GNU General Public
> > + * License. See the file "COPYING" in the main directory of this archive
> > + * for more details.
> > + */
> > +#include <linux/mm.h>
> > +#include <linux/init.h>
> > +#include <linux/dma-mapping.h>
> > +#include <linux/module.h>
> > +#include <asm/cacheflush.h>
> > +#include <asm/addrspace.h>
> > +
> > +void *dma_generic_alloc_coherent(struct device *dev, size_t size,
> > + dma_addr_t *dma_handle, gfp_t gfp,
> > + unsigned long attrs)
> > +{
> > + void *ret, *ret_nocache;
> > + int order = get_order(size);
> > +
> > + gfp |= __GFP_ZERO;
> > +
> > + ret = (void *)__get_free_pages(gfp, order);
> > + if (!ret)
> > + return NULL;
> > +
> > + /*
> > + * Pages from the page allocator may have data present in
> > + * cache. So flush the cache before using uncached memory.
> > + */
> > + sh_sync_dma_for_device(ret, size, DMA_BIDIRECTIONAL);
> > +
> > + ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret), size);
> > + if (!ret_nocache) {
> > + free_pages((unsigned long)ret, order);
> > + return NULL;
> > + }
> > +
> > + split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order);
> > +
> > + *dma_handle = virt_to_phys(ret);
> > + if (!WARN_ON(!dev))
> > + *dma_handle - PFN_PHYS(dev->dma_pfn_offset);
>
> I guess this comes from below...

> > - *dma_handle = virt_to_phys(ret);
> > - if (!WARN_ON(!dev))
> > - *dma_handle -= PFN_PHYS(dev->dma_pfn_offset);
>
> ... here
>
> Is the s/-=/- intended?
>
> Snippets copied here below:
>
> > + *dma_handle = virt_to_phys(ret);
> > + if (!WARN_ON(!dev))
> > + *dma_handle - PFN_PHYS(dev->dma_pfn_offset);
> vs
> > - *dma_handle = virt_to_phys(ret);
> > - if (!WARN_ON(!dev))
> > - *dma_handle -= PFN_PHYS(dev->dma_pfn_offset);

Doesn't look right to me, neither.

No complaints for 0day? My gcc says:

error: statement with no effect [-Werror=unused-value]

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

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