aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorOlav Haugan <ohaugan@codeaurora.org>2013-11-04 15:51:51 -0800
committerSimon Shields <keepcalm444@gmail.com>2016-06-12 21:19:49 +1000
commit2ee074b5fc854501be8d25fe4cae23402e5d1812 (patch)
tree5495efd8f3886350a9dd56e76c5ae1c5c6f81f03 /drivers/staging
parent195db76c72c596469fc6a194f968ccec33f1de09 (diff)
downloadkernel_samsung_smdk4412-2ee074b5fc854501be8d25fe4cae23402e5d1812.tar.gz
kernel_samsung_smdk4412-2ee074b5fc854501be8d25fe4cae23402e5d1812.tar.bz2
kernel_samsung_smdk4412-2ee074b5fc854501be8d25fe4cae23402e5d1812.zip
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. Change-Id: I5ad31712be4dd5105ebee81fa95927039c0f6935 Signed-off-by: Olav Haugan <ohaugan@codeaurora.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 523b9372156..41a68032ca8 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)
return next;
}
-/* Encode <page, obj_idx> as a single handle value */
+/*
+ * Encode <page, obj_idx> as a single handle value.
+ * On hardware platforms with physical memory starting at 0x0 the pfn
+ * could be 0 so we ensure that the handle will never be 0 by adjusting the
+ * encoded obj_idx value before encoding.
+ */
static void *obj_location_to_handle(struct page *page, unsigned long obj_idx)
{
unsigned long handle;
@@ -441,17 +446,21 @@ static void *obj_location_to_handle(struct page *page, unsigned long obj_idx)
}
handle = page_to_pfn(page) << OBJ_INDEX_BITS;
- handle |= (obj_idx & OBJ_INDEX_MASK);
+ handle |= ((obj_idx + 1) & OBJ_INDEX_MASK);
return (void *)handle;
}
-/* Decode <page, obj_idx> pair from the given object handle */
+/*
+ * Decode <page, obj_idx> pair from the given object handle. We adjust the
+ * decoded obj_idx back to its original value since it was adjusted in
+ * obj_location_to_handle().
+ */
static void obj_handle_to_location(unsigned long handle, struct page **page,
unsigned long *obj_idx)
{
*page = pfn_to_page(handle >> OBJ_INDEX_BITS);
- *obj_idx = handle & OBJ_INDEX_MASK;
+ *obj_idx = (handle & OBJ_INDEX_MASK) - 1;
}
static unsigned long obj_idx_to_offset(struct page *page,