Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7526124rwb; Wed, 23 Nov 2022 07:34:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JBMnjp1kfys0nrz4EahLGFb7JRuKVRNenpI4tVOdQgR6W3jC2L/0xDjw2GBA3kiZXo8p/ X-Received: by 2002:a17:902:e0ca:b0:187:1a3f:d552 with SMTP id e10-20020a170902e0ca00b001871a3fd552mr11455083pla.5.1669217677328; Wed, 23 Nov 2022 07:34:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669217677; cv=none; d=google.com; s=arc-20160816; b=1GJ5FtV/FVfQcktjrZtl95iMtLYqT/yXAluYCNbs2EOxGcGLNYyykc6EzSMC3Y6qpi mZkAWPaF4lDD76SVNaiXZrWzKzbSnTsdtP+j9R8CjWpHntfAKetWU689Sov8xdI+vTbt U04OitIKOfBD8/uyfCOJMXLJ/aFodQTjz3/h3rrdIMil2NYCN5VQn/qVUzYPfXaHZzCT frb7uNwucp2HY7DwA8rg7lGNDkeazrcd4o3I4sD55Co2vJ1fcz8TDAO/Vis83GJ6Frxx CbMye4fhVvdIt9hglEdXwzAkXzCduM/dYkg/XEw8txfpi2zzKMi42ke0JAlSsWCPGpxC uv3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:references:cc:to:from :subject; bh=3r3Fey2Qzn9SFixKqRTTfOqTqrY0ALMYbDHNk4pEuGk=; b=qFEn8xiOcewlK7FtP82bdr0E1vsaqFY63k57ivBivs6tQ7+YLueck3Du4eNCP08tB9 aiwFdBOG7jRrbUZg0c/r/8p71vWBiEneF1YDMibL2EGXHDo+i67FvDvYlgfMAp0oELTs GXJaiMzhZcAfdbjSxNa69DvTxhwzs4lY2Bpa6jd+VkEuyGS6dP6dyiJjKciZSqDPiPc/ mZ7CJD7BWP1+EA0OlN/eM3uLyl3+/amNagW7yreVtv9McO8ER77iaAb/ZJVNidy5CRD8 CtFdUUAUGr5lEpWZOwTqr0Yx5zg8JCjGxZ32ZociwjBo0R5xfwtrwC+OQGTq/NhsTkyw 2X/A== 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 qe14-20020a17090b4f8e00b0020593d282desi2094233pjb.12.2022.11.23.07.34.23; Wed, 23 Nov 2022 07:34:37 -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 S237197AbiKWOsr (ORCPT + 88 others); Wed, 23 Nov 2022 09:48:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237333AbiKWOsi (ORCPT ); Wed, 23 Nov 2022 09:48:38 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6B7C6E553; Wed, 23 Nov 2022 06:48:36 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NHPB45PChzHw46; Wed, 23 Nov 2022 22:47:56 +0800 (CST) Received: from [10.67.110.112] (10.67.110.112) 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:48:33 +0800 Subject: Re: [PATCH] thermal/of: Fix memory leak in thermal_of_zone_register() From: xiujianfeng To: , , , CC: , References: <20221123143325.183870-1-xiujianfeng@huawei.com> Message-ID: <1c39e64f-6691-eb58-fcad-59f16ac2e6ec@huawei.com> Date: Wed, 23 Nov 2022 22:48:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: <20221123143325.183870-1-xiujianfeng@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.112] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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,NICE_REPLY_A, 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 sorry, it seems someone already sent fix patch, ignore this. ?? 2022/11/23 22:33, Xiu Jianfeng ะด??: > 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); > } >