diff mbox

[3/3,media] tw68: don't assume that pagesize is always 4096

Message ID 5bbc05f52d23b17cc0faa81a2e5d4f2a344aaaa9.1409841955.git.m.chehab@samsung.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mauro Carvalho Chehab Sept. 4, 2014, 2:46 p.m. UTC
This code implicitly assumes that pagesize is 4096, but this is
not true on all archs, as the PAGE_SHIFT can be different than
12 on all those architectures: alpha, arc, arm64, cris, frv,
hexagon,ia64, m68k, metag, microblaze, mips, openrisc, parisc,
powerpc, sh, sparc and tile.

The real constrant here seems to be to limit the buffer size to
4MB.

So, fix the code to reflect that, in a way that it will keep
working with differnt values for PAGE_SIZE.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>

Comments

Hans Verkuil (hansverk) Sept. 4, 2014, 2:53 p.m. UTC | #1
I need to review this more closely tomorrow.

	Hans

On 09/04/14 16:46, Mauro Carvalho Chehab wrote:
> This code implicitly assumes that pagesize is 4096, but this is
> not true on all archs, as the PAGE_SHIFT can be different than
> 12 on all those architectures: alpha, arc, arm64, cris, frv,
> hexagon,ia64, m68k, metag, microblaze, mips, openrisc, parisc,
> powerpc, sh, sparc and tile.
> 
> The real constrant here seems to be to limit the buffer size to
> 4MB.
> 
> So, fix the code to reflect that, in a way that it will keep
> working with differnt values for PAGE_SIZE.
> 
> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> 
> diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c
> index 4dd38578cf1b..66658accdca9 100644
> --- a/drivers/media/pci/tw68/tw68-video.c
> +++ b/drivers/media/pci/tw68/tw68-video.c
> @@ -366,7 +366,7 @@ static int tw68_buffer_pages(int size)
>  {
>  	size  = PAGE_ALIGN(size);
>  	size += PAGE_SIZE; /* for non-page-aligned buffers */
> -	size /= 4096;
> +	size /= PAGE_SIZE;
>  	return size;
>  }
>  
> @@ -376,7 +376,7 @@ static int tw68_buffer_count(unsigned int size, unsigned int count)
>  {
>  	unsigned int maxcount;
>  
> -	maxcount = 1024 / tw68_buffer_pages(size);
> +	maxcount = (4096 * 1024 / PAGE_SIZE) / tw68_buffer_pages(size);
>  	if (count > maxcount)
>  		count = maxcount;
>  	return count;
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hans Verkuil Sept. 4, 2014, 4:21 p.m. UTC | #2
On 09/04/2014 04:46 PM, Mauro Carvalho Chehab wrote:
> This code implicitly assumes that pagesize is 4096, but this is
> not true on all archs, as the PAGE_SHIFT can be different than
> 12 on all those architectures: alpha, arc, arm64, cris, frv,
> hexagon,ia64, m68k, metag, microblaze, mips, openrisc, parisc,
> powerpc, sh, sparc and tile.
> 
> The real constrant here seems to be to limit the buffer size to
> 4MB.
> 
> So, fix the code to reflect that, in a way that it will keep
> working with differnt values for PAGE_SIZE.

While your fix is OK, I have a better patch that makes the code a lot more
readable. I'll post that soon.

Regards,

	Hans

> 
> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
> 
> diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c
> index 4dd38578cf1b..66658accdca9 100644
> --- a/drivers/media/pci/tw68/tw68-video.c
> +++ b/drivers/media/pci/tw68/tw68-video.c
> @@ -366,7 +366,7 @@ static int tw68_buffer_pages(int size)
>  {
>  	size  = PAGE_ALIGN(size);
>  	size += PAGE_SIZE; /* for non-page-aligned buffers */
> -	size /= 4096;
> +	size /= PAGE_SIZE;
>  	return size;
>  }
>  
> @@ -376,7 +376,7 @@ static int tw68_buffer_count(unsigned int size, unsigned int count)
>  {
>  	unsigned int maxcount;
>  
> -	maxcount = 1024 / tw68_buffer_pages(size);
> +	maxcount = (4096 * 1024 / PAGE_SIZE) / tw68_buffer_pages(size);
>  	if (count > maxcount)
>  		count = maxcount;
>  	return count;
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c
index 4dd38578cf1b..66658accdca9 100644
--- a/drivers/media/pci/tw68/tw68-video.c
+++ b/drivers/media/pci/tw68/tw68-video.c
@@ -366,7 +366,7 @@  static int tw68_buffer_pages(int size)
 {
 	size  = PAGE_ALIGN(size);
 	size += PAGE_SIZE; /* for non-page-aligned buffers */
-	size /= 4096;
+	size /= PAGE_SIZE;
 	return size;
 }
 
@@ -376,7 +376,7 @@  static int tw68_buffer_count(unsigned int size, unsigned int count)
 {
 	unsigned int maxcount;
 
-	maxcount = 1024 / tw68_buffer_pages(size);
+	maxcount = (4096 * 1024 / PAGE_SIZE) / tw68_buffer_pages(size);
 	if (count > maxcount)
 		count = maxcount;
 	return count;