public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [UIO] Add alignment warnings for uio-mem
@ 2008-09-18 14:46 Wolfram Sang
  2008-09-18 15:03 ` Andreas Schwab
  2008-09-18 21:53 ` Hans J. Koch
  0 siblings, 2 replies; 4+ messages in thread
From: Wolfram Sang @ 2008-09-18 14:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: hjk, gregkh

[-- Attachment #1: Type: text/plain, Size: 1276 bytes --]


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@pengutronix.de>
---
 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 #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-09-19  8:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-18 14:46 [PATCH] [UIO] Add alignment warnings for uio-mem Wolfram Sang
2008-09-18 15:03 ` Andreas Schwab
2008-09-18 21:53 ` Hans J. Koch
2008-09-19  8:49   ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox