From patchwork Wed Nov 6 00:54:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olav Haugan X-Patchwork-Id: 3144501 Return-Path: X-Original-To: patchwork-linux-arm-msm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2611DBEEB2 for ; Wed, 6 Nov 2013 00:54:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D7A72058E for ; Wed, 6 Nov 2013 00:54:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5DBDC205AC for ; Wed, 6 Nov 2013 00:54:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932072Ab3KFAyi (ORCPT ); Tue, 5 Nov 2013 19:54:38 -0500 Received: from smtp.codeaurora.org ([198.145.11.231]:57358 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932065Ab3KFAyi (ORCPT ); Tue, 5 Nov 2013 19:54:38 -0500 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id CC4D113EFB1; Wed, 6 Nov 2013 00:54:37 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id BEF0C13F286; Wed, 6 Nov 2013 00:54:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from ohaugan-linux.qualcomm.com (i-global252.qualcomm.com [199.106.103.252]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: ohaugan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 491FA13EFB1; Wed, 6 Nov 2013 00:54:37 +0000 (UTC) From: Olav Haugan To: gregkh@linuxfoundation.org Cc: ngupta@vflare.org, sjenning@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, minchan@kernel.org, linux-arm-msm@vger.kernel.org, Olav Haugan Subject: [PATCH] staging: zsmalloc: Ensure handle is never 0 on success Date: Tue, 5 Nov 2013 16:54:12 -0800 Message-Id: <1383699252-8898-1-git-send-email-ohaugan@codeaurora.org> X-Mailer: git-send-email 1.8.2.3 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP zsmalloc encodes a handle using the page pfn and an object index. On some hardware platforms the pfn could be 0 and this causes the encoded handle to be 0 which is interpreted as an allocation failure. To prevent this false error we ensure that the encoded handle will not be 0 when allocation succeeds. Change-Id: Ifff930dcf254915b497aec5cb36f152a5e5365d6 Signed-off-by: Olav Haugan --- drivers/staging/zsmalloc/zsmalloc-main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c index 523b937..0e32c0f 100644 --- a/drivers/staging/zsmalloc/zsmalloc-main.c +++ b/drivers/staging/zsmalloc/zsmalloc-main.c @@ -441,7 +441,7 @@ 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; } @@ -451,7 +451,7 @@ 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,