Commit 7fabaddd09ab32a7c0c08da80315758a2245189d
Committed by
Linus Torvalds
1 parent
fa29e97bb8
Exists in
master
and in
20 other branches
/dev/mem: make size_inside_page() logic straight
Also convert more size_inside_page() users. Signed-off-by: Wu Fengguang <fengguang.wu@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Avi Kivity <avi@qumranet.com> Cc: Greg Kroah-Hartman <gregkh@suse.de> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 12 additions and 22 deletions Side-by-side Diff
drivers/char/mem.c
... | ... | @@ -39,12 +39,9 @@ |
39 | 39 | { |
40 | 40 | unsigned long sz; |
41 | 41 | |
42 | - if (-start & (PAGE_SIZE - 1)) | |
43 | - sz = -start & (PAGE_SIZE - 1); | |
44 | - else | |
45 | - sz = PAGE_SIZE; | |
42 | + sz = PAGE_SIZE - (start & (PAGE_SIZE - 1)); | |
46 | 43 | |
47 | - return min_t(unsigned long, sz, size); | |
44 | + return min(sz, size); | |
48 | 45 | } |
49 | 46 | |
50 | 47 | /* |
... | ... | @@ -139,9 +136,7 @@ |
139 | 136 | #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED |
140 | 137 | /* we don't have page 0 mapped on sparc and m68k.. */ |
141 | 138 | if (p < PAGE_SIZE) { |
142 | - sz = PAGE_SIZE - p; | |
143 | - if (sz > count) | |
144 | - sz = count; | |
139 | + sz = size_inside_page(p, count); | |
145 | 140 | if (sz > 0) { |
146 | 141 | if (clear_user(buf, sz)) |
147 | 142 | return -EFAULT; |
... | ... | @@ -201,9 +196,7 @@ |
201 | 196 | #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED |
202 | 197 | /* we don't have page 0 mapped on sparc and m68k.. */ |
203 | 198 | if (p < PAGE_SIZE) { |
204 | - unsigned long sz = PAGE_SIZE - p; | |
205 | - if (sz > count) | |
206 | - sz = count; | |
199 | + sz = size_inside_page(p, count); | |
207 | 200 | /* Hmm. Do something? */ |
208 | 201 | buf += sz; |
209 | 202 | p += sz; |
210 | 203 | |
... | ... | @@ -412,15 +405,14 @@ |
412 | 405 | #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED |
413 | 406 | /* we don't have page 0 mapped on sparc and m68k.. */ |
414 | 407 | if (p < PAGE_SIZE && low_count > 0) { |
415 | - size_t tmp = PAGE_SIZE - p; | |
416 | - if (tmp > low_count) tmp = low_count; | |
417 | - if (clear_user(buf, tmp)) | |
408 | + sz = size_inside_page(p, low_count); | |
409 | + if (clear_user(buf, sz)) | |
418 | 410 | return -EFAULT; |
419 | - buf += tmp; | |
420 | - p += tmp; | |
421 | - read += tmp; | |
422 | - low_count -= tmp; | |
423 | - count -= tmp; | |
411 | + buf += sz; | |
412 | + p += sz; | |
413 | + read += sz; | |
414 | + low_count -= sz; | |
415 | + count -= sz; | |
424 | 416 | } |
425 | 417 | #endif |
426 | 418 | while (low_count > 0) { |
... | ... | @@ -480,9 +472,7 @@ |
480 | 472 | #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED |
481 | 473 | /* we don't have page 0 mapped on sparc and m68k.. */ |
482 | 474 | if (realp < PAGE_SIZE) { |
483 | - unsigned long sz = PAGE_SIZE - realp; | |
484 | - if (sz > count) | |
485 | - sz = count; | |
475 | + sz = size_inside_page(realp, count); | |
486 | 476 | /* Hmm. Do something? */ |
487 | 477 | buf += sz; |
488 | 478 | p += sz; |