diff options
author | David Howells <dhowells@redhat.com> | 2009-01-08 07:04:46 -0500 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2009-01-08 07:04:46 -0500 |
commit | 0e8f989a253b1bf85ea1c8d7987d67c054f4af91 (patch) | |
tree | 0b8b2c1e5c09c5cd46851680d8de2a0ad3c0fa9b /fs/ramfs/file-nommu.c | |
parent | 9e42d0cf5020aaf217433cad1a224745241d212a (diff) |
NOMMU: Fix cleanup handling in ramfs_nommu_get_umapped_area()
Fix cleanup handling in ramfs_nommu_get_umapped_area() by only freeing the
number of pages that find_get_pages() said it had returned (nr) rather than
attempting to free the number of pages we asked for (lpages) - thus avoiding
the situation whereby put_page() may be handed NULL pointers if
find_get_pages() returned fewer pages that were requested.
Also avoid a warning about nr being uninitialised and the need for an
if-statement in the cleanup path by using appropriate gotos.
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'fs/ramfs/file-nommu.c')
-rw-r--r-- | fs/ramfs/file-nommu.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c index 76acdbc34611..b9b567a28376 100644 --- a/fs/ramfs/file-nommu.c +++ b/fs/ramfs/file-nommu.c | |||
@@ -262,11 +262,11 @@ unsigned long ramfs_nommu_get_unmapped_area(struct file *file, | |||
262 | ret = -ENOMEM; | 262 | ret = -ENOMEM; |
263 | pages = kzalloc(lpages * sizeof(struct page *), GFP_KERNEL); | 263 | pages = kzalloc(lpages * sizeof(struct page *), GFP_KERNEL); |
264 | if (!pages) | 264 | if (!pages) |
265 | goto out; | 265 | goto out_free; |
266 | 266 | ||
267 | nr = find_get_pages(inode->i_mapping, pgoff, lpages, pages); | 267 | nr = find_get_pages(inode->i_mapping, pgoff, lpages, pages); |
268 | if (nr != lpages) | 268 | if (nr != lpages) |
269 | goto out; /* leave if some pages were missing */ | 269 | goto out_free_pages; /* leave if some pages were missing */ |
270 | 270 | ||
271 | /* check the pages for physical adjacency */ | 271 | /* check the pages for physical adjacency */ |
272 | ptr = pages; | 272 | ptr = pages; |
@@ -274,19 +274,18 @@ unsigned long ramfs_nommu_get_unmapped_area(struct file *file, | |||
274 | page++; | 274 | page++; |
275 | for (loop = lpages; loop > 1; loop--) | 275 | for (loop = lpages; loop > 1; loop--) |
276 | if (*ptr++ != page++) | 276 | if (*ptr++ != page++) |
277 | goto out; | 277 | goto out_free_pages; |
278 | 278 | ||
279 | /* okay - all conditions fulfilled */ | 279 | /* okay - all conditions fulfilled */ |
280 | ret = (unsigned long) page_address(pages[0]); | 280 | ret = (unsigned long) page_address(pages[0]); |
281 | 281 | ||
282 | out: | 282 | out_free_pages: |
283 | if (pages) { | 283 | ptr = pages; |
284 | ptr = pages; | 284 | for (loop = nr; loop > 0; loop--) |
285 | for (loop = lpages; loop > 0; loop--) | 285 | put_page(*ptr++); |
286 | put_page(*ptr++); | 286 | out_free: |
287 | kfree(pages); | 287 | kfree(pages); |
288 | } | 288 | out: |
289 | |||
290 | return ret; | 289 | return ret; |
291 | } | 290 | } |
292 | 291 | ||