Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5617219img; Wed, 27 Mar 2019 11:48:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLVowwXFuQ/M8D7tl1w/cIoCdl33JI9nQiNVRAsjyflyzxcTo6Depjiz28Jyd9jtKxIt8E X-Received: by 2002:a63:83:: with SMTP id 125mr36140834pga.403.1553712500797; Wed, 27 Mar 2019 11:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553712500; cv=none; d=google.com; s=arc-20160816; b=g2LiEKCbjxYOLDAEAzaYZuwSIL267jrzWxYlHX/SdwSHsIlHXLpbr/M1b0cWRNsLZU u8ASS4wYIkKncAsApxKfEvCndHS5v1QNjhPmJh0hxRnZGPPeF91rFtZg703tBKiKN+sg KfVIX/8NJ98jQ+6pMci6SRH4yAW5N9KYOHwNppytcBvqsdFJUl8fr7iDVhK4xEKWJdJ9 Bzr5FYnYUsl2bfE6amYPWOCVVk4N5EAGQ7hfK7x+bLN5muVI86rk0+Fn5LHqVFjQusJe +lMEPZHAebRSCns69/w9R9lSZKtsNNdwsepcFcB4jNhvj1HOtfqpUlz3kcZkBK//pry5 1llg== 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=0BlteLIeMJ49y1WH1smPLNi4IEzArFU7Tulm0vkDYIg=; b=DLc2DrJB+hFPaSW/cAXMO9yT1d/0ulHQ1dCJlReTfiPqwWrzvjM3RJMTwHIQFpETsU Ab865dTzZCYILuKapDcbwCQACcqnBN/fHBimrUccSP3SIcqTTWPT1q5yxwNiovDcLMHi hyPcSdIHwd44fMr0W0EXReo1zW5F0399CtNjOZjNsZfNBAKog3GThxXwULg03pSdKnQx 234exkmABMbSFxbogAxMO2eHOPksOqF6kufURUiZvUA9Tssr7ZoTtEtYmZTCiHwxgKm9 e+w/aLG+vAuV4l6nWuhyGShpkgUMMEetDW9Ln5u5XofQoSRvF4WV9BWW+chJrN83XkTP s0Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HmFP0tSU; 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 89si19562322pfs.243.2019.03.27.11.48.05; Wed, 27 Mar 2019 11:48:20 -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=HmFP0tSU; 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 S2391276AbfC0Sp0 (ORCPT + 99 others); Wed, 27 Mar 2019 14:45:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:38684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390349AbfC0SU7 (ORCPT ); Wed, 27 Mar 2019 14:20:59 -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 64CE92070B; Wed, 27 Mar 2019 18:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710858; bh=tsEwdK4bz9q3pOh9P+soQ2+50/Ss0lGmLcWF6Ak5pRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HmFP0tSU11W96Yllejv+omo0Q2DcErdfDO6XU3S0k6TlRipOTpt+OoUwbXQm9F2Yl KnrqlOqHmZFErX/sVQ7CdtzM+CT0fC5xzKkw1zSFTeog82b5kRjZmvIV38CvTCiZ5r poZBVyVuDuOSfa5RspzMu3k7S+SEXAO/oLJm6lak= 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 4.9 10/87] mm/cma.c: cma_declare_contiguous: correct err handling Date: Wed, 27 Mar 2019 14:19:23 -0400 Message-Id: <20190327182040.17444-10-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327182040.17444-1-sashal@kernel.org> References: <20190327182040.17444-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 397687fc51f9..b5d8847497a3 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -339,12 +339,14 @@ int __init cma_declare_contiguous(phys_addr_t base, ret = cma_init_reserved_mem(base, size, order_per_bit, 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