[PATCH] [UIO] Add alignment warnings for uio-mem

From: Wolfram Sang
Date: Thu Sep 18 2008 - 10:46:42 EST



mmap works page aligned. If uio-mem areas were set up unaligned, mmap
would silently align it and the corresponding attributes in sysfs would
not reflect it. This patch fixes such values during init to what the
kernel will do anyway and adds a warning.

Signed-off-by: Wolfram Sang <w.sang@xxxxxxxxxxxxxx>
---
drivers/uio/uio.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

Index: drivers/uio/uio.c
===================================================================
--- drivers/uio/uio.c.orig
+++ drivers/uio/uio.c
@@ -656,6 +656,8 @@
struct uio_info *info)
{
struct uio_device *idev;
+ struct uio_mem *mem;
+ unsigned int offset;
int ret = 0;

if (!parent || !info || !info->name || !info->version)
@@ -691,6 +693,16 @@
goto err_device_create;
}

+ for (mem = info->mem; mem->size; mem++) {
+ offset = mem->addr & ~PAGE_MASK;
+ if (offset) {
+ mem->addr -= offset;
+ mem->size += offset;
+ dev_warn(idev->dev, "mem[%d] not page aligned!"
+ "Fixing values.\n", mem - info->mem);
+ }
+ }
+
ret = uio_dev_add_attributes(idev);
if (ret)
goto err_uio_dev_add_attributes;
--
Dipl.-Ing. Wolfram Sang | http://www.pengutronix.de
Pengutronix - Linux Solutions for Science and Industry

Attachment: signature.asc
Description: Digital signature