summaryrefslogtreecommitdiffstats
path: root/commands/mem.c
diff options
context:
space:
mode:
authorLucas Stach <l.stach@pengutronix.de>2018-11-06 17:14:07 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-11-07 08:46:55 +0100
commit20c12d090a1de80a3c58a232b4074067dcbb61a4 (patch)
treef8c65a379c628bf1b4738fd2d7f86cd9a3b11434 /commands/mem.c
parentb8cfa99541e218bdf76a63872eb252e0ef94078d (diff)
downloadbarebox-20c12d090a1de80a3c58a232b4074067dcbb61a4.tar.gz
barebox-20c12d090a1de80a3c58a232b4074067dcbb61a4.tar.xz
commands: mem: truncate mem device size to fit the loff_t file size
On 64bit arches the file covering the whole address space is larger than what can be represented in the loff_t type (s64) used for the file size. Thus the size of this device is interpreted as negative in a lot of places. Fix this by truncating the size to fit the file size type. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/mem.c')
-rw-r--r--commands/mem.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/commands/mem.c b/commands/mem.c
index eb91ade05a..cdd7a492d0 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -96,7 +96,8 @@ static int mem_probe(struct device_d *dev)
dev->priv = cdev;
cdev->name = (char*)dev->resource[0].name;
- cdev->size = (unsigned long)resource_size(&dev->resource[0]);
+ cdev->size = min(resource_size(&dev->resource[0]),
+ (unsigned long long)S64_MAX);
cdev->ops = &memops;
cdev->dev = dev;