Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2823996rwe; Mon, 29 Aug 2022 00:17:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR6wxM1ed+Ga3BTF+w8snZT0j8WQnS2GVg3Ljwji+akUHd52m/5G68Vm3PECVLd3DVO+VwJt X-Received: by 2002:a17:907:1c12:b0:741:a0bc:bd2c with SMTP id nc18-20020a1709071c1200b00741a0bcbd2cmr856220ejc.241.1661757471099; Mon, 29 Aug 2022 00:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661757471; cv=none; d=google.com; s=arc-20160816; b=iFNcuMca0Fep0vGkG8nybvVl/6+x/AFNHAxloamfrMcL9uDbx44i02sqRLJW5MI58/ YteKZWAo1uv9ufMkQ/jIvpFDubayUYDO9/0IGKV2lBG11d0vJ8pzY4/XxJHFkCYnWWr3 qWgIYYL+YmKbDeeRIwEtgZcFYlN6VNhgIEw9WveiXvFMyNi2Rgt46dV+ZhhPql3E51Ws FvRMkFl7TbwifCkvG+NG5l8S0DdRFi2BWHzP2COeAY8vPPWVM3LkBs+OtjQ7kiumdQ1X 2rSc87ZJeGW5v7NKXZfZFq8xgwUucJkqBLz8cadpeyYIV/IwXV0kn9d98jQrrwyytw9o AEYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=42JL/HX+DBvKEZiPjU44VW0keiluftCBRj/jOuYSejs=; b=ELecCO75jqxYl4rjkSQbHu57jhkvD+H1eQ4mLQu3LZbhTbFcQQTenYOnSrvRrj+Ja7 km29yvsEU/+5oWFNtmYuiVqkSPKM4kKJb83D9s9NceraiBXBhuMKcJhvcnCBBzWEHOKv Wq5RuODiTi5MU+bp0MGW6mj68GQndHVBzRbxQGPdtu3gPyvZWOMHt7ynEU0s90iy/y0n I5q+mN8X39ZURC91glK68D0NS0STb0NTrJOhIYlY6PFWC0m1Inb8ldla7oNm9nqXKKSe mCm5MyJ1lVO8e7/k6MX7ToG5vPI0iET9yT1wFm5XUHAlEWeVTqaZbRdGJL7xHB8LsXsD 2wmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv16-20020a17090760d000b0072f25c0af5dsi6104751ejc.135.2022.08.29.00.17.25; Mon, 29 Aug 2022 00:17:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbiH2HNb (ORCPT + 99 others); Mon, 29 Aug 2022 03:13:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbiH2HN3 (ORCPT ); Mon, 29 Aug 2022 03:13:29 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D414D819 for ; Mon, 29 Aug 2022 00:13:28 -0700 (PDT) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MGM5S26bMzlWZh; Mon, 29 Aug 2022 15:10:04 +0800 (CST) Received: from huawei.com (10.175.112.208) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 29 Aug 2022 15:13:25 +0800 From: Yuan Can To: , , , CC: , Subject: [PATCH] iommu: fix resource leak in iommu_group_alloc Date: Mon, 29 Aug 2022 07:11:25 +0000 Message-ID: <20220829071125.104173-1-yuancan@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.208] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When it fails to create file for reserved_regions and type of an iommu_group, the iommu_group_alloc returns ERR_PTR without releasing the iommu_group. Add error handling to cleanup leaking resources. Signed-off-by: Yuan Can --- drivers/iommu/iommu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 1ca59afc8472..fff23231b5fc 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -675,15 +675,22 @@ struct iommu_group *iommu_group_alloc(void) ret = iommu_group_create_file(group, &iommu_group_attr_reserved_regions); if (ret) - return ERR_PTR(ret); + goto out_put_group; ret = iommu_group_create_file(group, &iommu_group_attr_type); if (ret) - return ERR_PTR(ret); + goto out_remove_file; pr_debug("Allocated group %d\n", group->id); return group; + +out_remove_file: + iommu_group_remove_file(group, &iommu_group_attr_reserved_regions); +out_put_group: + iommu_group_put(group); + + return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(iommu_group_alloc); -- 2.17.1