From patchwork Fri Apr 10 08:42:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Praveen Paneri X-Patchwork-Id: 6192981 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 457AD9F349 for ; Fri, 10 Apr 2015 08:39:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 157CD203DA for ; Fri, 10 Apr 2015 08:39:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2534220351 for ; Fri, 10 Apr 2015 08:39:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 921086E8E8; Fri, 10 Apr 2015 01:39:28 -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 D1F5E6E8E8 for ; Fri, 10 Apr 2015 01:39:27 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 10 Apr 2015 01:39:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,555,1422950400"; d="scan'208";a="706745210" Received: from intel-desktop.iind.intel.com ([10.223.82.37]) by fmsmga002.fm.intel.com with ESMTP; 10 Apr 2015 01:39:26 -0700 From: Praveen Paneri To: intel-gfx@lists.freedesktop.org Date: Fri, 10 Apr 2015 14:12:59 +0530 Message-Id: <1428655383-26087-8-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 07/11] intel: Validate memory allocations 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 This patch adds check for various malloc/calloc function if they were able to allocate memory as requested or not. Return appropriate error if the allocation fails. v2: Rebased to the latest. Signed-off-by: Praveen Paneri --- intel/intel_bufmgr_fake.c | 4 ++++ intel/intel_bufmgr_gem.c | 3 +++ intel/intel_decode.c | 2 ++ 3 files changed, 9 insertions(+) diff --git a/intel/intel_bufmgr_fake.c b/intel/intel_bufmgr_fake.c index 129d344..e2b25eb 100644 --- a/intel/intel_bufmgr_fake.c +++ b/intel/intel_bufmgr_fake.c @@ -1278,6 +1278,8 @@ drm_intel_fake_emit_reloc(drm_intel_bo *bo, uint32_t offset, if (bo_fake->relocs == NULL) { bo_fake->relocs = malloc(sizeof(struct fake_buffer_reloc) * MAX_RELOCS); + if (!bo_fake->relocs) + return -ENOMEM; } r = &bo_fake->relocs[bo_fake->nr_relocs++]; @@ -1597,6 +1599,8 @@ drm_intel_bufmgr_fake_init(int fd, unsigned long low_offset, drm_intel_bufmgr_fake *bufmgr_fake; bufmgr_fake = calloc(1, sizeof(*bufmgr_fake)); + if (!bufmgr_fake) + return NULL; if (pthread_mutex_init(&bufmgr_fake->lock, NULL) != 0) { free(bufmgr_fake); diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c index 91320ca..6180c6e 100644 --- a/intel/intel_bufmgr_gem.c +++ b/intel/intel_bufmgr_gem.c @@ -2081,6 +2081,9 @@ aub_write_bo_data(drm_intel_bo *bo, uint32_t offset, uint32_t size) unsigned int i; data = malloc(bo->size); + if (!data) + return; + drm_intel_bo_get_subdata(bo, offset, size, data); /* Easy mode: write out bo with no relocations */ diff --git a/intel/intel_decode.c b/intel/intel_decode.c index 5dab9ca..88267fd 100644 --- a/intel/intel_decode.c +++ b/intel/intel_decode.c @@ -3914,6 +3914,8 @@ drm_intel_decode(struct drm_intel_decode *ctx) * checking in statically sized packets. */ temp = malloc(size + 4096); + if (!temp) + return; memcpy(temp, ctx->base_data, size); memset((char *)temp + size, 0xd0, 4096); ctx->data = temp;