From patchwork Wed Nov 23 14:33:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 25022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2831256wrr; Wed, 23 Nov 2022 06:42:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf52+NZoMS5hLj+VdvAy/vFSSiVMd04N83xpXCiB4UgB4+XmwnYn9I+cPe1SWdL2FY4Cq7z5 X-Received: by 2002:a17:906:78c:b0:78d:9c18:7307 with SMTP id l12-20020a170906078c00b0078d9c187307mr25860931ejc.23.1669214559147; Wed, 23 Nov 2022 06:42:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669214559; cv=none; d=google.com; s=arc-20160816; b=Q6prLOjK+pw79zxv62XGVcXrmIXUZOjEoDeB1+FM2y8+RuivFr1exmn50Oxs/O4fzW AM7ygyo67VrT+7BOeK3aQif86H2qlmbINOOvDE1KuAGMXwCOoPTy9FKhc29BN+9SvCE3 /YxfES6tnMAfy7TB1Lb02N79Y/OPg+i9TNH0F8NCyBJen2Oy0sLGiAtvhMKwToa23tdU rykh/ND/aYH/O0DbzuLB/d5JjdO7taZZ/cklKRLkjdTTZTksVqiXdo1qYtcPmxX5gXZy 68GtoLUg5r6aJd1+0rjI/1FLU6yuHrQAzyVZH4DdYxxcF7gKKD1sS28qyBxj6XwNiEGa D7Ag== 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=K/FGYc424/j76V73OSjO/HIgLNDokL4pfp3HPDcV5uA=; b=Ny3ooJr3o8jEJ+9oiULAQ3sfdJOCs4qf5r9dDUPhY7NKkaeiHiImVkkVqjWb6O3JGc aNlSkpMtwfduZdYJh+GcHWJG5ZV1mhGI3zy+w410CA+zpCm7RJWIKnTug1l+vNptkEwy O43U0h/sITJpwUEoqzpB2bux6pkS0aiCqXCupUizKmrdxjzXghwOHbuFR3mfpSqyFQEG dxQBLDb0D37N8XeJod2QVtjlmu4HfZSdI48eUNIS4nIEHmk6KOit6GndQ1St8KClLtAm vQC9B40emo13cdhJCQxoPH/RIT0maTNoIsqs2m9qjVhg6T3zNAnG29VJk43xStYdisqX Nvmw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d14-20020a056402400e00b00461cd4b5a01si13736312eda.419.2022.11.23.06.42.10; Wed, 23 Nov 2022 06:42:39 -0800 (PST) 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 S238502AbiKWOgn (ORCPT + 99 others); Wed, 23 Nov 2022 09:36:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238477AbiKWOgk (ORCPT ); Wed, 23 Nov 2022 09:36:40 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB42F1D314; Wed, 23 Nov 2022 06:36:38 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NHNwN745nz15M0R; Wed, 23 Nov 2022 22:36:04 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 23 Nov 2022 22:36:35 +0800 From: Xiu Jianfeng To: , , , CC: , Subject: [PATCH] thermal/of: Fix memory leak in thermal_of_zone_register() Date: Wed, 23 Nov 2022 22:33:25 +0800 Message-ID: <20221123143325.183870-1-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500023.china.huawei.com (7.185.36.114) 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750298325594472128?= X-GMAIL-MSGID: =?utf-8?q?1750298325594472128?= In the entry of this function, it has allocated memory by kmemdup() and save it in @of_ops, it should be freed on the error paths, otherwise memory leak issue happens, fix it. Fixes: 3fd6d6e2b4e8 ("thermal/of: Rework the thermal device tree initialization") Signed-off-by: Xiu Jianfeng --- drivers/thermal/thermal_of.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index d4b6335ace15..95d3da9051c4 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -604,13 +604,15 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, if (IS_ERR(np)) { if (PTR_ERR(np) != -ENODEV) pr_err("Failed to find thermal zone for %pOFn id=%d\n", sensor, id); - return ERR_CAST(np); + ret = PTR_ERR(np); + goto out_kfree_ops; } trips = thermal_of_trips_init(np, &ntrips); if (IS_ERR(trips)) { pr_err("Failed to find trip points for %pOFn id=%d\n", sensor, id); - return ERR_CAST(trips); + ret = PTR_ERR(trips); + goto out_kfree_ops; } ret = thermal_of_monitor_init(np, &delay, &pdelay); @@ -659,6 +661,8 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, kfree(tzp); out_kfree_trips: kfree(trips); +out_kfree_ops: + kfree(of_ops); return ERR_PTR(ret); }