Commit ea0a337f authored by Vijay Kumar's avatar Vijay Kumar Committed by Greg Kroah-Hartman

Staging: poch: Correct pages from bytes.

Accurately calculate the no. of pages from the bytes.
Signed-off-by: default avatarVijay Kumar <vijaykumar@bravegnu.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ee49abcf
...@@ -299,6 +299,14 @@ static ssize_t show_direction(struct device *dev, ...@@ -299,6 +299,14 @@ static ssize_t show_direction(struct device *dev,
} }
static DEVICE_ATTR(dir, S_IRUSR|S_IRGRP, show_direction, NULL); static DEVICE_ATTR(dir, S_IRUSR|S_IRGRP, show_direction, NULL);
static unsigned long npages(unsigned long bytes)
{
if (bytes % PAGE_SIZE == 0)
return bytes / PAGE_SIZE;
else
return (bytes / PAGE_SIZE) + 1;
}
static ssize_t show_mmap_size(struct device *dev, static ssize_t show_mmap_size(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
...@@ -309,10 +317,8 @@ static ssize_t show_mmap_size(struct device *dev, ...@@ -309,10 +317,8 @@ static ssize_t show_mmap_size(struct device *dev,
unsigned long header_pages; unsigned long header_pages;
unsigned long total_group_pages; unsigned long total_group_pages;
/* FIXME: We do not have to add 1, if group_size a multiple of group_pages = npages(channel->group_size);
PAGE_SIZE. */ header_pages = npages(channel->header_size);
group_pages = (channel->group_size / PAGE_SIZE) + 1;
header_pages = (channel->header_size / PAGE_SIZE) + 1;
total_group_pages = group_pages * channel->group_count; total_group_pages = group_pages * channel->group_count;
mmap_size = (header_pages + total_group_pages) * PAGE_SIZE; mmap_size = (header_pages + total_group_pages) * PAGE_SIZE;
...@@ -350,8 +356,8 @@ static int poch_channel_alloc_groups(struct channel_info *channel) ...@@ -350,8 +356,8 @@ static int poch_channel_alloc_groups(struct channel_info *channel)
unsigned long group_pages; unsigned long group_pages;
unsigned long header_pages; unsigned long header_pages;
group_pages = (channel->group_size / PAGE_SIZE) + 1; group_pages = npages(channel->group_size);
header_pages = (channel->header_size / PAGE_SIZE) + 1; header_pages = npages(channel->header_size);
for (i = 0; i < channel->group_count; i++) { for (i = 0; i < channel->group_count; i++) {
struct poch_group_info *group; struct poch_group_info *group;
...@@ -850,8 +856,8 @@ static int poch_mmap(struct file *filp, struct vm_area_struct *vma) ...@@ -850,8 +856,8 @@ static int poch_mmap(struct file *filp, struct vm_area_struct *vma)
return -EINVAL; return -EINVAL;
} }
group_pages = (channel->group_size / PAGE_SIZE) + 1; group_pages = npages(channel->group_size);
header_pages = (channel->header_size / PAGE_SIZE) + 1; header_pages = npages(channel->header_size);
total_group_pages = group_pages * channel->group_count; total_group_pages = group_pages * channel->group_count;
size = vma->vm_end - vma->vm_start; size = vma->vm_end - vma->vm_start;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment