mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 5/5] misc: fix /dev/mem size
Date: Mon,  4 Feb 2019 15:46:41 +0100	[thread overview]
Message-ID: <20190204144641.19600-6-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20190204144641.19600-1-s.hauer@pengutronix.de>

The size of /dev/mem was limited to the lower half of the 64bit address
range. This is unfortunate since on some architectures (MIPS64, namely)
the upper half contains meaningful addresses. We can't just set /dev/mem
to its real size since that's bigger than the maximum loff_t. Set the
DEVFS_IS_CHARACTER_DEV flag instead for /dev/mem which will cause the
size checks in lseek and friends to be bypassed.
Also fix the size the memory device is registered with. We used to set
the size to ~0, but the real size is one higher. To do this explicitly
register the device with specifying the end address rather than the
size. This will make /dev/mem appear with filesize 0, but so does
/dev/zero already.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/misc/mem.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/mem.c b/drivers/misc/mem.c
index 60981a3e98..6dd7f687c9 100644
--- a/drivers/misc/mem.c
+++ b/drivers/misc/mem.c
@@ -21,8 +21,18 @@ static int mem_probe(struct device_d *dev)
 	dev->priv = cdev;
 
 	cdev->name = (char*)dev->resource[0].name;
-	cdev->size = min_t(unsigned long long, resource_size(&dev->resource[0]),
-			   S64_MAX);
+	if (dev->resource[0].start == 0 && dev->resource[0].end == ~0) {
+		/*
+		 * Special case for /dev/mem. We can't express it's size as it's
+		 * outside of our address range. Set DEVFS_IS_CHARACTER_DEV to
+		 * bypass size checks.
+		 */
+		cdev->size = 0;
+		cdev->flags = DEVFS_IS_CHARACTER_DEV;
+	} else {
+		cdev->size = resource_size(&dev->resource[0]);
+	}
+
 	cdev->ops = &memops;
 	cdev->dev = dev;
 
@@ -38,7 +48,26 @@ static struct driver_d mem_drv = {
 
 static int mem_init(void)
 {
-	add_mem_device("mem", 0, ~0, IORESOURCE_MEM_WRITEABLE);
+	struct device_d *dev;
+	struct resource res = {
+		.start = 0,
+		.end = ~0,
+		.flags = IORESOURCE_MEM,
+		.name = "mem",
+	};
+	int ret;
+
+	dev = device_alloc("mem", DEVICE_ID_DYNAMIC);
+	if (!dev)
+		return -ENOMEM;
+
+	dev->resource = xmemdup(&res, sizeof(res));
+	dev->num_resources = 1;
+
+	ret = platform_device_register(dev);
+	if (ret)
+		return ret;
+
 	return platform_driver_register(&mem_drv);
 }
 device_initcall(mem_init);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-02-04 14:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 14:46 [PATCH 0/5] 32-bit lseek and /dev/mem fixes/improvements Sascha Hauer
2019-02-04 14:46 ` [PATCH 1/5] fs: let truncate take a loff_t argument Sascha Hauer
2019-02-04 14:46 ` [PATCH 2/5] fs: set errno in ftruncate() Sascha Hauer
2019-02-04 14:46 ` [PATCH 3/5] fs: do not call truncate for FILE_SIZE_STREAM sized files Sascha Hauer
2019-02-04 14:46 ` [PATCH 4/5] fs: devfs: forbid truncation when cdev has no truncate operation Sascha Hauer
2019-02-04 14:46 ` Sascha Hauer [this message]
2019-02-05 21:44 ` [PATCH 0/5] 32-bit lseek and /dev/mem fixes/improvements Andrey Smirnov
2019-02-06  7:33   ` Sascha Hauer
2019-02-06  7:37     ` Andrey Smirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190204144641.19600-6-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox