From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53DA2C43217 for ; Thu, 20 Oct 2022 10:45:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229838AbiJTKpx (ORCPT ); Thu, 20 Oct 2022 06:45:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229674AbiJTKpu (ORCPT ); Thu, 20 Oct 2022 06:45:50 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8484C1C2F04 for ; Thu, 20 Oct 2022 03:45:49 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id EA0675C0048; Thu, 20 Oct 2022 06:45:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 20 Oct 2022 06:45:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1666262748; x=1666349148; bh=3i9CEmk2eCVnbmZlcrVEWWg9nuuv 8GdpzkiURpH+/UA=; b=IsPLyBtZ29Ca/flqP6EMbMKne5jJsmyybxUJEMD2cssn vPp3iT7nHbzp0qFUHKDQXidFPEH0o+p9Cj4FFpL/9As9SdrseXwWiXhKMBkUPdm4 mtyMNQS82rwqbyoKaa37s3gs/j2SZKc6RJZ4pqe/Mpxdhf8OqmEAY9f2ZcHOxnFQ 4VxFoE7lJvI+vzsAWqQtstvuW2gHC6l1XPA9B5/QHWWapaNCelwWqPaB+PdMTA2+ sovsm3F5VMQJrKTE5fP7Mz1BSOLOH0DeZ4x9pPRUp9RCN2BtCYcNVKc7o71SLhy4 Ggy+Eck3t2Mzv+0KvY/Hro0CqOv176eaAr8AyJ6puw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeliedgfedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepkfguohcu ufgthhhimhhmvghluceoihguohhstghhsehiughoshgthhdrohhrgheqnecuggftrfgrth htvghrnhephefhtdejvdeiffefudduvdffgeetieeigeeugfduffdvffdtfeehieejtdfh jeeknecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehiughoshgthhesihguohhstghhrdhorhhg X-ME-Proxy: Feedback-ID: i494840e7:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 20 Oct 2022 06:45:46 -0400 (EDT) Date: Thu, 20 Oct 2022 13:45:43 +0300 From: Ido Schimmel To: Zhang Qilong Cc: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, linux-pm@vger.kernel.org Subject: Re: [PATCH] thermal/of: Fix possible memleak in thermal_of_zone_register() Message-ID: References: <20221020080048.56377-1-zhangqilong3@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221020080048.56377-1-zhangqilong3@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org On Thu, Oct 20, 2022 at 04:00:48PM +0800, Zhang Qilong wrote: > diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c > index d4b6335ace15..fc8fa27480a1 100644 > --- a/drivers/thermal/thermal_of.c > +++ b/drivers/thermal/thermal_of.c > @@ -596,10 +596,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, > int ntrips, mask; > int ret; > > - of_ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); > - if (!of_ops) > - return ERR_PTR(-ENOMEM); > - > np = of_thermal_zone_find(sensor, id); > if (IS_ERR(np)) { > if (PTR_ERR(np) != -ENODEV) > @@ -626,6 +622,12 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, > goto out_kfree_trips; > } > > + of_ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); > + if (!of_ops) { > + ret = -ENOMEM; > + goto out_kfree_tzp; > + } > + > of_ops->get_trip_type = of_ops->get_trip_type ? : of_thermal_get_trip_type; > of_ops->get_trip_temp = of_ops->get_trip_temp ? : of_thermal_get_trip_temp; > of_ops->get_trip_hyst = of_ops->get_trip_hyst ? : of_thermal_get_trip_hyst; > @@ -656,6 +658,7 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, > return tz; > > out_kfree_tzp: > + kfree(of_ops); > kfree(tzp); > out_kfree_trips: > kfree(trips); The patch looks correct, but it can be cleaner. Ideally, you would have a separate label to free 'of_ops' like we have for other variables. Also, the error path is not symmetric with thermal_of_zone_unregister() where this variable is the last to be freed, not the first. I also encountered this issue and posted a patch: https://lore.kernel.org/linux-pm/20221020103658.802457-1-idosch@nvidia.com/ Unless you see something wrong with it, can you please test and see if it fixes your issue? Thanks