From patchwork Thu Oct 22 16:40:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Deucher X-Patchwork-Id: 7465921 Return-Path: X-Original-To: patchwork-dri-devel@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 460979F30B for ; Thu, 22 Oct 2015 16:40:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 82E3B20857 for ; Thu, 22 Oct 2015 16:40:37 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id B50C92085F for ; Thu, 22 Oct 2015 16:40:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0E8527220B; Thu, 22 Oct 2015 09:40:35 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yk0-f178.google.com (mail-yk0-f178.google.com [209.85.160.178]) by gabe.freedesktop.org (Postfix) with ESMTPS id 79E7B6E5C2 for ; Thu, 22 Oct 2015 09:40:31 -0700 (PDT) Received: by ykdr3 with SMTP id r3so88462329ykd.1 for ; Thu, 22 Oct 2015 09:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=flpfnwLz3BdN7r44aNR8/70f5ZkXzBN4aSY5YCxvqyM=; b=oRO76Ucok5eOod0dRyVb/o/QLNwSyLeH936oVx01stQ/uv+//ppHFFRgGYSgFOip4n VqNChGSfPWF2PQ56jn0Ey378SBOiMWYkkTweDOwfn6bj5ZM804ze5zhwgddulE/2AjNH OBqwnbYnPgqaqtJS5mxiXDEVGyDYvWjCjZfIRAKajOjChBTZ3j2+ikgwjSW/zr49qJd5 ri7GozFLYScdXeux1UtpF5+ZAa5Y47Eb6GjVPLrk1eiBMT2a0ztVqgGfF/nPaF4qD/cT /felXmG4zdEClSJ2TglOPTvxehIh0udEz5NUdEhNKBGh/Rj3XzCI7fAEleXfSX51Mq8d A5YA== X-Received: by 10.129.0.2 with SMTP id 2mr13248567ywa.127.1445532030785; Thu, 22 Oct 2015 09:40:30 -0700 (PDT) Received: from localhost.localdomain (static-74-96-105-49.washdc.fios.verizon.net. [74.96.105.49]) by smtp.gmail.com with ESMTPSA id q4sm10378921ywf.32.2015.10.22.09.40.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 09:40:30 -0700 (PDT) From: Alex Deucher X-Google-Original-From: Alex Deucher To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] amdgpu: Cleanly handle ENOMEM on result in amdgpu_bo_list_create() Date: Thu, 22 Oct 2015 12:40:23 -0400 Message-Id: <1445532023-16778-3-git-send-email-alexander.deucher@amd.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1445532023-16778-1-git-send-email-alexander.deucher@amd.com> References: <1445532023-16778-1-git-send-email-alexander.deucher@amd.com> Cc: Tom St Denis X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 From: Tom St Denis Move the allocation of result prior to the IOCTL so we can cleanly backtrack if the allocation fails. Signed-off-by: Tom St Denis Reviewed-by: Alex Deucher --- amdgpu/amdgpu_bo.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/amdgpu/amdgpu_bo.c b/amdgpu/amdgpu_bo.c index 348da00..1a5a401 100644 --- a/amdgpu/amdgpu_bo.c +++ b/amdgpu/amdgpu_bo.c @@ -591,6 +591,12 @@ int amdgpu_bo_list_create(amdgpu_device_handle dev, if (!list) return -ENOMEM; + *result = malloc(sizeof(struct amdgpu_bo_list)); + if (!*result) { + free(list); + return -ENOMEM; + } + memset(&args, 0, sizeof(args)); args.in.operation = AMDGPU_BO_LIST_OP_CREATE; args.in.bo_number = number_of_resources; @@ -608,10 +614,11 @@ int amdgpu_bo_list_create(amdgpu_device_handle dev, r = drmCommandWriteRead(dev->fd, DRM_AMDGPU_BO_LIST, &args, sizeof(args)); free(list); - if (r) + if (r) { + free(*result); return r; + } - *result = malloc(sizeof(struct amdgpu_bo_list)); (*result)->dev = dev; (*result)->handle = args.out.list_handle; return 0;