Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5579303img; Wed, 27 Mar 2019 11:04:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqySsRQh8fiqWZFFr+SR+wG/vDU4pVscilPeMTkKBobzCUIdHHP34xMM81FfirIpqp/HYMem X-Received: by 2002:a17:902:4381:: with SMTP id j1mr5498422pld.75.1553709854065; Wed, 27 Mar 2019 11:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553709854; cv=none; d=google.com; s=arc-20160816; b=VnqYZ9/ibMVRwtoeZyN3oKhg840RbQ2gwr11b4av+J5M0IVgrDzqmuqfBsoegK38VQ kZR+U4Wffe+/Woavg0ESXtCZ1sma/18vEw18RuRa6Up8mVZ2Suj0XY6fCluA0kuKIK8U UwOPIznPNCFSU1Wt3OwSfC8yH5Im6O544oBEZIoOBKD4cM+qaYUXFEnEwyIcNG88vTKi Fzp7RPeYbZDDcdw83e2IlOqLw/hB2u0MYiuW8jAIFxbFlX5aLlIbKrxdCrg3mayRqtUu xclBIYGsy5+nLIcWmELMM0ZQ+N1Vxe+vURE1Pw/yP+t63hItq3iBvLy1xw0mkNaU4jX1 G/5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oshVF3pnS80y9kU1Xv9q7KmogsfX3bUL924jNqzFaYY=; b=0AwU2pOdC1rMLE7v5AOMx9yYRvEUnDpVkj00vgPtp6vOdZH51mPKCjq4hDuD2BUsOy /hw7mBVwuuQEzIvaYt8f+M1KdY4NuWSl2LQ4GSGVJjbnh349UtjGnjBWWkhOCcWJ3OFx eYl1N7HqZYmbQshKnNZa5QUywfzAESddQ1mtSPzaFWUJrGLHxFi3zYbaiVHmmN4IyC8a J9Uf1rFr+ODNfZqcwJXMa6xzzg+tUNlZCZNsEXZxjLxz8aSjVHg1oxlfgKWq1Du7h2tc c9XJ5YT+HsHmsNnJktxosNcmSaaQBWrZX2CpjOxbG09daSYjy15AhzxXRQAaPVPbJtGt 31Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lWz3fb6R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bg1si19654466plb.118.2019.03.27.11.03.58; Wed, 27 Mar 2019 11:04:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lWz3fb6R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731675AbfC0SCz (ORCPT + 99 others); Wed, 27 Mar 2019 14:02:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:42822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731628AbfC0SCv (ORCPT ); Wed, 27 Mar 2019 14:02:51 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA0742082F; Wed, 27 Mar 2019 18:02:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709771; bh=VmNGT9gWdIwRpvfBryTTHeFlhfr4c6tuu743yAtQCJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lWz3fb6Rbv9F1qvi/uEXlWtWQpWXQnRHYTDiM8f8+S5SCs8GfDPZ6/61HXpM+GW/T IKCEiz7zl3vbSENbqPD5ijCLEE7GhXySM7eJzEM3iw6/sw4htiAadayHOfeOYM7bAm 4LWUHIkltljvSi6bt7vwr0W+oZ1O6qq9y4f+gwBY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peng Fan , Laura Abbott , Joonsoo Kim , Michal Hocko , Vlastimil Babka , Marek Szyprowski , Andrey Konovalov , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 5.0 031/262] mm/cma.c: cma_declare_contiguous: correct err handling Date: Wed, 27 Mar 2019 13:58:06 -0400 Message-Id: <20190327180158.10245-31-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peng Fan [ Upstream commit 0d3bd18a5efd66097ef58622b898d3139790aa9d ] In case cma_init_reserved_mem failed, need to free the memblock allocated by memblock_reserve or memblock_alloc_range. Quote Catalin's comments: https://lkml.org/lkml/2019/2/26/482 Kmemleak is supposed to work with the memblock_{alloc,free} pair and it ignores the memblock_reserve() as a memblock_alloc() implementation detail. It is, however, tolerant to memblock_free() being called on a sub-range or just a different range from a previous memblock_alloc(). So the original patch looks fine to me. FWIW: Link: http://lkml.kernel.org/r/20190227144631.16708-1-peng.fan@nxp.com Signed-off-by: Peng Fan Reviewed-by: Catalin Marinas Reviewed-by: Mike Rapoport Cc: Laura Abbott Cc: Joonsoo Kim Cc: Michal Hocko Cc: Vlastimil Babka Cc: Marek Szyprowski Cc: Andrey Konovalov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/cma.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/cma.c b/mm/cma.c index c7b39dd3b4f6..f4f3a8a57d86 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -353,12 +353,14 @@ int __init cma_declare_contiguous(phys_addr_t base, ret = cma_init_reserved_mem(base, size, order_per_bit, name, res_cma); if (ret) - goto err; + goto free_mem; pr_info("Reserved %ld MiB at %pa\n", (unsigned long)size / SZ_1M, &base); return 0; +free_mem: + memblock_free(base, size); err: pr_err("Failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M); return ret; -- 2.19.1