Re: [PATCH] UIO: Implement a UIO interface for the SMX Cryptengine

Paul Mundt
2008-03-12T10:08:54Z

On Tue, Mar 11, 2008 at 03:57:10PM +1100, Ben Nizette wrote:
> + regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
> + if (!regs)
> + goto out_free;
> +
> + info->mem[0].addr = regs->start;
> + if (!info->mem[0].addr)
> + goto out_free;
> + info->mem[0].internal_addr = ioremap(regs->start, regs->end -
> regs->start);
> + if (!info->mem[0].internal_addr)
> + goto out_free;
> +
> + info->mem[0].size = regs->end - regs->start;
> + info->mem[0].memtype = UIO_MEM_PHYS;
> +
You have an off-by-1 in the resource size. ioremap and struct resource
are not equal in their expectations. You probably want to do something
like:

info->mem[0].size = regs->end - regs->start + 1;
info->mem[0].internal_addr = ioremap(regs->start, info->mem[0].size);
...

and make sure that your resource end doesn't overlap with a start address
of an unrelated resource in your definition. /proc/iomem tends to be
useful for this.