From patchwork Fri Apr 10 08:43:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Praveen Paneri X-Patchwork-Id: 6193001 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1D3BEBF4A6 for ; Fri, 10 Apr 2015 08:39:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 58040203C4 for ; Fri, 10 Apr 2015 08:39:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 6769320351 for ; Fri, 10 Apr 2015 08:39:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E23326E8E7; Fri, 10 Apr 2015 01:39:32 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTP id 71B3E6E8E7 for ; Fri, 10 Apr 2015 01:39:30 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 10 Apr 2015 01:39:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,555,1422950400"; d="scan'208";a="706745235" Received: from intel-desktop.iind.intel.com ([10.223.82.37]) by fmsmga002.fm.intel.com with ESMTP; 10 Apr 2015 01:39:29 -0700 From: Praveen Paneri To: intel-gfx@lists.freedesktop.org Date: Fri, 10 Apr 2015 14:13:01 +0530 Message-Id: <1428655383-26087-10-git-send-email-praveen.paneri@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428655383-26087-1-git-send-email-praveen.paneri@intel.com> References: <1428655383-26087-1-git-send-email-praveen.paneri@intel.com> Cc: Praveen Paneri Subject: [Intel-gfx] [PATCH 09/11] xf86drmSL: Check memory allocation by SL_RANDOM_INIT() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the allocation fails, return -ENOMEM. Handle the return value at the caller funtion drmSLInsert() as well. v2: Rebased to the latest. Signed-off-by: Praveen Paneri --- xf86drmSL.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xf86drmSL.c b/xf86drmSL.c index 42b5bc4..3ceb087 100644 --- a/xf86drmSL.c +++ b/xf86drmSL.c @@ -40,6 +40,7 @@ #include #include +#include #include "xf86drm.h" @@ -92,6 +93,7 @@ static int SLRandomLevel(void) SL_RANDOM_DECL; SL_RANDOM_INIT(SL_RANDOM_SEED); + if (!state) return -ENOMEM; while ((SL_RANDOM & 0x01) && level < SL_MAX_LEVEL) ++level; return level; @@ -168,6 +170,9 @@ int drmSLInsert(void *l, unsigned long key, void *value) level = SLRandomLevel(); + if (level < 0) + return level; + if (level > list->level) { level = ++list->level; update[level] = list->head;