aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorOlav Haugan <ohaugan@codeaurora.org>2013-11-22 12:30:41 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-25 15:52:45 -0500
commit67296874eb1cc80317bf2a8fba22b494e21eb29b (patch)
treebed05c365a16261e247c387dfa26a1e47bf6bfed /drivers/staging
parentb39f15c972c462903208531b82f9b34ba8ef3ec0 (diff)
staging: zsmalloc: Ensure handle is never 0 on success
zsmalloc encodes a handle using the pfn and an object index. On hardware platforms with physical memory starting at 0x0 the pfn can be 0. This causes the encoded handle to be 0 and is incorrectly interpreted as an allocation failure. This issue affects all current and future SoCs with physical memory starting at 0x0. All MSM8974 SoCs which includes Google Nexus 5 devices are affected. To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds. Signed-off-by: Olav Haugan <ohaugan@codeaurora.org> Cc: stable <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/zsmalloc/zsmalloc-main.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c
index 1a67537dbc56..3b950e5a918f 100644
--- a/drivers/staging/zsmalloc/zsmalloc-main.c
+++ b/drivers/staging/zsmalloc/zsmalloc-main.c
@@ -430,7 +430,12 @@ static struct page *get_next_page(struct page *page)
430 return next; 430 return next;
431} 431}
432 432
433/* Encode <page, obj_idx> as a single handle value */ 433/*
434 * Encode <page, obj_idx> as a single handle value.
435 * On hardware platforms with physical memory starting at 0x0 the pfn
436 * could be 0 so we ensure that the handle will never be 0 by adjusting the
437 * encoded obj_idx value before encoding.
438 */
434static void *obj_location_to_handle(struct page *page, unsigned long obj_idx) 439static void *obj_location_to_handle(struct page *page, unsigned long obj_idx)
435{ 440{
436 unsigned long handle; 441 unsigned long handle;
@@ -441,17 +446,21 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx)
441 } 446 }
442 447
443 handle = page_to_pfn(page) << OBJ_INDEX_BITS; 448 handle = page_to_pfn(page) << OBJ_INDEX_BITS;
444 handle |= (obj_idx & OBJ_INDEX_MASK); 449 handle |= ((obj_idx + 1) & OBJ_INDEX_MASK);
445 450
446 return (void *)handle; 451 return (void *)handle;
447} 452}
448 453
449/* Decode <page, obj_idx> pair from the given object handle */ 454/*
455 * Decode <page, obj_idx> pair from the given object handle. We adjust the
456 * decoded obj_idx back to its original value since it was adjusted in
457 * obj_location_to_handle().
458 */
450static void obj_handle_to_location(unsigned long handle, struct page **page, 459static void obj_handle_to_location(unsigned long handle, struct page **page,
451 unsigned long *obj_idx) 460 unsigned long *obj_idx)
452{ 461{
453 *page = pfn_to_page(handle >> OBJ_INDEX_BITS); 462 *page = pfn_to_page(handle >> OBJ_INDEX_BITS);
454 *obj_idx = handle & OBJ_INDEX_MASK; 463 *obj_idx = (handle & OBJ_INDEX_MASK) - 1;
455} 464}
456 465
457static unsigned long obj_idx_to_offset(struct page *page, 466static unsigned long obj_idx_to_offset(struct page *page,