From patchwork Tue Aug 13 17:16:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 11092709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C610746 for ; Tue, 13 Aug 2019 17:15:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DAC5286B9 for ; Tue, 13 Aug 2019 17:15:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F181B286DF; Tue, 13 Aug 2019 17:15:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60903286B9 for ; Tue, 13 Aug 2019 17:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726155AbfHMRPg (ORCPT ); Tue, 13 Aug 2019 13:15:36 -0400 Received: from mail.skyhub.de ([5.9.137.197]:47358 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726029AbfHMRPg (ORCPT ); Tue, 13 Aug 2019 13:15:36 -0400 Received: from zn.tnic (p200300EC2F0D2400C42B856AF2D9BBDA.dip0.t-ipconnect.de [IPv6:2003:ec:2f0d:2400:c42b:856a:f2d9:bbda]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 49F971EC0716; Tue, 13 Aug 2019 19:15:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1565716535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=MKvPtw39k4N+Zo5QrzcqmJCmYa89E6ty+9O3MiOg9Ak=; b=os+6Yx7mfVvvbD3vz96XGojt+UlOedAh80BEC277yi4t5QHIpvWaAk9RljyVjdfTMf+BaJ Tw0cUi+Qnm1PXYP5WQrewkSI+jrMejlzpZcv+K7M0+tgGV0WIDbkhmSqYVCNwJsK7ZIZMp WDokZfmoRPq5o5F41lwQj2ep0LHtz5M= Date: Tue, 13 Aug 2019 19:16:19 +0200 From: Borislav Petkov To: luanshi , "Rafael J. Wysocki" Cc: "Rafael J. Wysocki" , Len Brown , James Morse , Tony Luck , linux-acpi@vger.kernel.org Subject: [PATCH v4.1] ACPI / APEI: release resources if gen_pool_add fails Message-ID: <20190813171619.GH16770@zn.tnic> References: <1563173924-47479-1-git-send-email-zhangliguang@linux.alibaba.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1563173924-47479-1-git-send-email-zhangliguang@linux.alibaba.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, here's v4.1 with the labels properly balanced. Thx. --- From: Liguang Zhang Date: Mon, 15 Jul 2019 14:58:44 +0800 Subject: [PATCH] ACPI / APEI: Release resources if gen_pool_add() fails Destroy ghes_estatus_pool and release memory allocated via vmalloc() on errors in ghes_estatus_pool_init() in order to avoid memory leaks. [ bp: do the labels properly and with descriptive names and massage. ] Signed-off-by: Liguang Zhang Signed-off-by: Borislav Petkov Cc: "Rafael J. Wysocki" Cc: James Morse Cc: Len Brown Cc: linux-acpi@vger.kernel.org Cc: Tony Luck Link: https://lkml.kernel.org/r/1563173924-47479-1-git-send-email-zhangliguang@linux.alibaba.com --- drivers/acpi/apei/ghes.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index a66e00fe31fe..66205ec54555 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -153,6 +153,7 @@ static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx) int ghes_estatus_pool_init(int num_ghes) { unsigned long addr, len; + int rc; ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1); if (!ghes_estatus_pool) @@ -164,7 +165,7 @@ int ghes_estatus_pool_init(int num_ghes) ghes_estatus_pool_size_request = PAGE_ALIGN(len); addr = (unsigned long)vmalloc(PAGE_ALIGN(len)); if (!addr) - return -ENOMEM; + goto err_pool_alloc; /* * New allocation must be visible in all pgd before it can be found by @@ -172,7 +173,19 @@ int ghes_estatus_pool_init(int num_ghes) */ vmalloc_sync_all(); - return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1); + rc = gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1); + if (rc) + goto err_pool_add; + + return 0; + +err_pool_add: + vfree((void *)addr); + +err_pool_alloc: + gen_pool_destroy(ghes_estatus_pool); + + return -ENOMEM; } static int map_gen_v2(struct ghes *ghes)