Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7508313rwb; Wed, 23 Nov 2022 07:22:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf640Bu7pRVtelZXw6FbbMEmSrCTAnbziyhsymtwa/oanKsyqiCE8CQjQBeByqKjJXP01mi1 X-Received: by 2002:a17:906:1e4a:b0:78d:3505:6f3e with SMTP id i10-20020a1709061e4a00b0078d35056f3emr23713294ejj.611.1669216938136; Wed, 23 Nov 2022 07:22:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669216938; cv=none; d=google.com; s=arc-20160816; b=CH/PHk7AL+uvjlZr11sDRdRbZ6ks3O4HCmPrRVf/9iEn1Z1YStJ+X3o8zJhgisSSP9 fNUmbbT+cE7/poCxV1/Y+jQ/axaradysejskFKMzlyMxRO+kJTcYxFfJumNZXx6ySjwW m+Ax07NV59Z/yiTticbjK0gkCvNyP319IkUSdmXwZsVws548WFc+GU1DOFKI+BsWZhCF 2614NutXj5+usRAAa15Ls+Q76nlafa7Swz4ubprmNZGNdeIj0rewIB9y0QMNagL3Hv4u 2GxL2WOV4uZPunpQVTKakCXeBlQ4ocTpG0Tm6o7zTjWI5MAy3Ro1PqPX5K+ehNUq+kZO QDIg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he40-20020a1709073da800b007ae61d89b3esi3310906ejc.356.2022.11.23.07.21.55; Wed, 23 Nov 2022 07:22:18 -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 + 88 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 Content-Type: text/plain 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 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); } -- 2.17.1