Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755132Ab0BSRBV (ORCPT ); Fri, 19 Feb 2010 12:01:21 -0500 Received: from kroah.org ([198.145.64.141]:57681 "EHLO coco.kroah.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754892Ab0BSRAw (ORCPT ); Fri, 19 Feb 2010 12:00:52 -0500 X-Mailbox-Line: From gregkh@kvm.kroah.org Fri Feb 19 08:32:46 2010 Message-Id: <20100219163246.841129359@kvm.kroah.org> User-Agent: quilt/0.48-4.4 Date: Fri, 19 Feb 2010 08:29:51 -0800 From: Greg KH To: linux-kernel@vger.kernel.org, stable@kernel.org Cc: stable-review@kernel.org, torvalds@linux-foundation.org, akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk, Wu Fengguang , Andi Kleen , Marcelo Tosatti , Mark Brown , Johannes Berg , Avi Kivity , Chuck Ebbert Subject: [58/93] /dev/mem: introduce size_inside_page() In-Reply-To: <20100219165717.GA15002@kroah.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3256 Lines: 121 2.6.32-stable review patch. If anyone has any objections, please let us know. ------------------ From: Wu Fengguang commit f222318e9c3a315723e3524fb9d6566b2430db44 upstream /dev/mem: introduce size_inside_page() [ cebbert@redhat.com : backport to 2.6.32 ] [ subset of original patch, for just /dev/kmem ] Introduce size_inside_page() to replace duplicate /dev/mem code. Also apply it to /dev/kmem, whose alignment logic was buggy. Signed-off-by: Wu Fengguang Acked-by: Andi Kleen Cc: Marcelo Tosatti Cc: Greg Kroah-Hartman Cc: Mark Brown Cc: Johannes Berg Cc: Avi Kivity Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Cc: Chuck Ebbert Signed-off-by: Greg Kroah-Hartman --- drivers/char/mem.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -35,6 +35,19 @@ # include #endif +static inline unsigned long size_inside_page(unsigned long start, + unsigned long size) +{ + unsigned long sz; + + if (-start & (PAGE_SIZE - 1)) + sz = -start & (PAGE_SIZE - 1); + else + sz = PAGE_SIZE; + + return min_t(unsigned long, sz, size); +} + /* * Architectures vary in how they handle caching for addresses * outside of main memory. @@ -430,15 +443,7 @@ static ssize_t read_kmem(struct file *fi } #endif while (low_count > 0) { - /* - * Handle first page in case it's not aligned - */ - if (-p & (PAGE_SIZE - 1)) - sz = -p & (PAGE_SIZE - 1); - else - sz = PAGE_SIZE; - - sz = min_t(unsigned long, sz, low_count); + sz = size_inside_page(p, low_count); /* * On ia64 if a page has been mapped somewhere as @@ -462,10 +467,8 @@ static ssize_t read_kmem(struct file *fi if (!kbuf) return -ENOMEM; while (count > 0) { - int len = count; + int len = size_inside_page(p, count); - if (len > PAGE_SIZE) - len = PAGE_SIZE; len = vread(kbuf, (char *)p, len); if (!len) break; @@ -510,15 +513,8 @@ do_write_kmem(void *p, unsigned long rea while (count > 0) { char *ptr; - /* - * Handle first page in case it's not aligned - */ - if (-realp & (PAGE_SIZE - 1)) - sz = -realp & (PAGE_SIZE - 1); - else - sz = PAGE_SIZE; - sz = min_t(unsigned long, sz, count); + sz = size_inside_page(realp, count); /* * On ia64 if a page has been mapped somewhere as @@ -578,10 +574,8 @@ static ssize_t write_kmem(struct file * if (!kbuf) return wrote ? wrote : -ENOMEM; while (count > 0) { - int len = count; + int len = size_inside_page(p, count); - if (len > PAGE_SIZE) - len = PAGE_SIZE; if (len) { written = copy_from_user(kbuf, buf, len); if (written) { -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/