[PATCH] cpuset read past eof memory leak fix

Don't leak a page of memory if user reads a cpuset file past eof.

Signed-off-by: KUROSAWA Takahiro <kurosawa@valinux.co.jp>
Signed-off-by: Paul Jackson <pj@sgi.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Paul Jackson and committed by Linus Torvalds 5134fc15 2dd3c1df

+6 -5
+6 -5
kernel/cpuset.c
··· 969 969 ssize_t retval = 0; 970 970 char *s; 971 971 char *start; 972 - size_t n; 972 + ssize_t n; 973 973 974 974 if (!(page = (char *)__get_free_page(GFP_KERNEL))) 975 975 return -ENOMEM; ··· 999 999 *s++ = '\n'; 1000 1000 *s = '\0'; 1001 1001 1002 - /* Do nothing if *ppos is at the eof or beyond the eof. */ 1003 - if (s - page <= *ppos) 1004 - return 0; 1005 - 1006 1002 start = page + *ppos; 1007 1003 n = s - start; 1004 + 1005 + /* Do nothing if *ppos is at the eof or beyond the eof. */ 1006 + if (n <= 0) 1007 + goto out; 1008 + 1008 1009 retval = n - copy_to_user(buf, start, min(n, nbytes)); 1009 1010 *ppos += retval; 1010 1011 out: