Re: [patch] ioremap sanity check to catch mapping requests exceedingthe BAR sizes

From: Jeremy Fitzhardinge
Date: Sat Sep 27 2008 - 03:16:57 EST


Suresh Siddha wrote:
> +int iomem_map_sanity_check(resource_size_t addr, unsigned long size)
> +{
> + struct resource *p = &iomem_resource;
> + int err = 0;
> + loff_t l;
> +
> + read_lock(&resource_lock);
> + for (p = p->child; p ; p = r_next(NULL, p, &l)) {
> + /*
> + * We can probably skip the resources with out
> + * IORESOURCE_IO attribute?
>

Any attempt to use ioremap on memory is a bug, so you should warn about
that too.

> + */
> + if (p->start >= addr + size)
> + continue;
> + if (p->end < addr)
> + continue;
> + if (p->start <= addr && (p->end >= addr + size - 1))
> + continue;
> + printk(KERN_WARNING "resource map sanity check conflict "
> + " 0x%llx 0x%llx 0x%llx 0x%llx %s\n",
> + addr, addr + size - 1, p->start, p->end, p->name);
> + err = -1;
> + break;
> + }
> + read_unlock(&resource_lock);
> +
> + return err;

J
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/