From patchwork Tue Apr 19 14:55:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 66100 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1897664qge; Tue, 19 Apr 2016 07:55:43 -0700 (PDT) X-Received: by 10.66.100.197 with SMTP id fa5mr648008pab.25.1461077743710; Tue, 19 Apr 2016 07:55:43 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id xl10si10523964pac.14.2016.04.19.07.55.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Apr 2016 07:55:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 157B81A21FD; Tue, 19 Apr 2016 07:55:43 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x236.google.com (mail-wm0-x236.google.com [IPv6:2a00:1450:400c:c09::236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 877BB1A21AE for ; Tue, 19 Apr 2016 07:55:41 -0700 (PDT) Received: by mail-wm0-x236.google.com with SMTP id e201so17114380wme.0 for ; Tue, 19 Apr 2016 07:55:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=S9NlUm7vsSED143K1OA5cY7eAfqDMVs3K9kXPJQtCEc=; b=SZxUo37GKKArGTdJ2zKV+bcRmlRmyV2UNuKLIvzKBHo/AqlZOQjflFT4+U0wL3ix4N bO16PF6wt5kI0xdQVjRc3GD4ifanTBvcfBpjp+iV55IEsG5k86nWE+EeaPQqhwdgsBaE DD4QtVyLKSCbXX3UHQQbGII/2nnSs26NIrWRc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=S9NlUm7vsSED143K1OA5cY7eAfqDMVs3K9kXPJQtCEc=; b=YJ3QkgOkOmJ39GBSvvuFOQpsYrg/qHSYIz7BHI60pMO5scBhi2tVRNinojIh6gVVQ7 AbU5oBUK+UaPNCquC5+kNr1UC8NUpTwqu/dozGSWQMeREMtydkflKqWoU+8QzUQa2izK obRPII60jcHiR9j41eeAlfQUpExvry9hmTRvgBTMFoxrIsjoc61Va31UU1vlAkflftR7 W268HCKv9x480gHcns1odueiQcNwRp/yYJOw4j52BA/7NljTf/kd8cTqQAp9hBsTJhMH 4inH1YJ9PuaM7lOWl3Hy95xbS/o+IoJXPx0gb66NrWajHN/PsPndajrSDI+gHT5f6N3D n9Zw== X-Gm-Message-State: AOPr4FXTvWyAyGSx6t978lwvD6+zlgprRMrvVdyYzcRqoIkOwOLmhnyf+0/AKDhs++oseVTJ X-Received: by 10.28.68.70 with SMTP id r67mr4234104wma.80.1461077739775; Tue, 19 Apr 2016 07:55:39 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id i5sm684778wjx.15.2016.04.19.07.55.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 07:55:39 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, ryan.harkin@linaro.org Date: Tue, 19 Apr 2016 16:55:30 +0200 Message-Id: <1461077734-4327-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 Subject: [edk2] [PATCH 1/5] ArmPkg/ArmDmaLib: deal with NULL return value of UncachedAllocatePages () X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: heyi.guo@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The allocation function UncachedAllocatePages () may return NULL, in which case our implementation of DmaAllocateBuffer () should return EFI_OUT_OF_RESOURCES rather than silently ignoring the NULL value and returning EFI_SUCCESS. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) -- 2.5.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c index 54a49a18d302..1e6b288b10b9 100644 --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c @@ -216,6 +216,8 @@ DmaAllocateBuffer ( OUT VOID **HostAddress ) { + VOID *Allocation; + if (HostAddress == NULL) { return EFI_INVALID_PARAMETER; } @@ -226,13 +228,19 @@ DmaAllocateBuffer ( // We used uncached memory to keep coherency // if (MemoryType == EfiBootServicesData) { - *HostAddress = UncachedAllocatePages (Pages); + Allocation = UncachedAllocatePages (Pages); } else if (MemoryType == EfiRuntimeServicesData) { - *HostAddress = UncachedAllocateRuntimePages (Pages); + Allocation = UncachedAllocateRuntimePages (Pages); } else { return EFI_INVALID_PARAMETER; } + if (Allocation == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + *HostAddress = Allocation; + return EFI_SUCCESS; }