Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp7003519rwb; Wed, 18 Jan 2023 12:08:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXvBtavtqouTnsuS3OEe3TSE0HhOnajkC5ohoCIDmvfFNLoLwuUKIC8KaSBKPVM3ctTP+G71 X-Received: by 2002:aa7:db97:0:b0:46c:d2a3:76b3 with SMTP id u23-20020aa7db97000000b0046cd2a376b3mr8429845edt.14.1674072495852; Wed, 18 Jan 2023 12:08:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674072495; cv=none; d=google.com; s=arc-20160816; b=xLk95aqaRtTtBI6Iji15sNw4Q/ydTLuV5G7VdGTpDNL/fGT7/ATnm0oLr1GpNcVuep OrmJsjPwJCRENBaI5Szp0Sq+BOVXswd24EwLh/uuwngSa8PH1BPsYn7b7nwRAAu/XUc3 XDH/pLBi6Tw2aTl5JpejQdJXflulcQ00Uz74yuTfAfHKfly7xQygzZsOe9s23ZuWFpTm CDj243w+EI/+sdtBi7YYtMP7fLuicO3I0ZCfac169fHexq56bO/l/8T8piYRMVMUpgiY emvZGLCx46B3cJtFcuabTi03zXjfWyLLNM5UOCuKAVrP/TnBqvyD0rt0ypXthAztnl/a asyg== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=2qWA5wiyfjH0Va+Vx5qAKgnXVeWFuFmu2RbQWpk+MCc=; b=A/rjxNkXHm9T34sBHtE7R/xnBPqnI5Ha554fH7meTSSIm5lcFc8RTTqTAM2NE1S6xV XVYd3qRn5Gb+UgS0i3uH8I3kg8xoYCGPnEeORvsZvKHNhcqMnEzAa/1j+RGpFQje2hno Ca/XD/YcmqxUy7HG+wPjojzvSuP1wGLpwPynYurZJAU6Ni1UrrBH7IAUAJLHVcrwVkYk RwXiCcKpOlKwVEDME0RmMwbiM93vI9+V+iV6px+REBkN7el3QtIqzeA85MT42LiujHAy +Cn2+N+aRHVWm4GYmeV/49vsxa4k7Y05zG9HyHj7G1h/WCThGAWy972iACduTZ7MgnEa /rfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MkYk6LD8; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q2-20020aa7d442000000b0049e02ae1365si13165328edr.117.2023.01.18.12.08.03; Wed, 18 Jan 2023 12:08:15 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=MkYk6LD8; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229669AbjART5u (ORCPT + 47 others); Wed, 18 Jan 2023 14:57:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbjART5p (ORCPT ); Wed, 18 Jan 2023 14:57:45 -0500 Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94A059541; Wed, 18 Jan 2023 11:57:42 -0800 (PST) Received: by mail-qt1-x831.google.com with SMTP id s4so1814245qtx.6; Wed, 18 Jan 2023 11:57:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2qWA5wiyfjH0Va+Vx5qAKgnXVeWFuFmu2RbQWpk+MCc=; b=MkYk6LD8I0u6FoU+zrOFzm9+HfOG9qh7vFwihyD9kbVeC2NuyQGGfGXS+0wT+o8lXg GMR4WogwcgeFmCtrqEcrZUfeA4ES6C4qt/cohsvIsMuW32D9W4awvLThONuCiqQTcKOh 0/uZy0+QB87A8dTPxHhy6dCqMYjWNHOaUMz8TXrYKdkXkZzZVxZHgjDXj06NcqnOHoAK xr7l1PvgeFB4QNiPNoX7wCOcT3Bb8SIgOUMqamQK0vxzY7YCLokgRxxNfJjTe8RNBvDT I9Wqd3V0IrEYJFRyk7Pt7tsAh3IEpQ2eJxtws0iBn6aaMzZERw/W8cKdHSDmrfaf25Li nx5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2qWA5wiyfjH0Va+Vx5qAKgnXVeWFuFmu2RbQWpk+MCc=; b=OO8/juYlnbO84m9WXGGgYSqz5CjEh4qDRsqZ8ySlqwiMEMTNe7OSXIeeZJjO5dqs7k 5/reHzdB/WgqZZKVvUYj7csAQqIj5TAhoSzh/hHFe+iz2+7DYm7q7zsmLWmIAonRoKfY MfsgCj7CQDZFk2KDUpr5XoLzZm6aqf++NtsiE8gcdx1K67gNfKiH1BWIuc148dddv0Hn WbwKPHcuspv0/+pK7xag9+0YhnDXwezhxarL5RE0oXb6GfXjnnYQkBKE5X2W5A8pgLxZ mrIMYhUg/1m0KIzhLFGuKDcvJhM7MVFPkBPN7ln1oe1k0KoITdceCuRJLrKRfLc6y21I z/Bg== X-Gm-Message-State: AFqh2kpt2tsHaWaKD58g31DSg+WBP1xo74juH8cXWW3Kz+aQrr6CYXlf aaSEkACleyvAsV0Kk2dLI05c4Vw9Eq8= X-Received: by 2002:a05:622a:1dc4:b0:3b6:3b60:e0 with SMTP id bn4-20020a05622a1dc400b003b63b6000e0mr10477164qtb.31.1674071861737; Wed, 18 Jan 2023 11:57:41 -0800 (PST) Received: from ?IPV6:2600:1700:2442:6db0:c0fe:24db:874d:3fd8? ([2600:1700:2442:6db0:c0fe:24db:874d:3fd8]) by smtp.gmail.com with ESMTPSA id b24-20020ac86798000000b0039cc944ebdasm17888911qtp.54.2023.01.18.11.57.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Jan 2023 11:57:41 -0800 (PST) Message-ID: <0c1b5696-060b-8545-994d-160217449951@gmail.com> Date: Wed, 18 Jan 2023 13:57:40 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH V4 1/3] thermal: core: call put_device() only after device_register() fails Content-Language: en-US To: Viresh Kumar , "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Yang Yingliang Cc: linux-pm@vger.kernel.org, Vincent Guittot , Caleb Connolly , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org References: From: Frank Rowand In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,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 On 1/18/23 02:38, Viresh Kumar wrote: > put_device() shouldn't be called before a prior call to > device_register(). __thermal_cooling_device_register() doesn't follow > that properly and needs fixing. Also > thermal_cooling_device_destroy_sysfs() is getting called unnecessarily > on few error paths. > > Fix all this by placing the calls at the right place. > > Based on initial work done by Caleb Connolly. > > Fixes: 4748f9687caa ("thermal: core: fix some possible name leaks in error paths") > Fixes: c408b3d1d9bb ("thermal: Validate new state in cur_state_store()") > Reported-by: Caleb Connolly > Signed-off-by: Viresh Kumar > --- > For v6.2-rc. > > V3->V4: > - The first three versions were sent by Caleb. > - The new version fixes the current bugs, without looking to optimize the > code any further, which is done separately in the next two patches. > > drivers/thermal/thermal_core.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index f17ab2316dbd..77bd47d976a2 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -909,15 +909,20 @@ __thermal_cooling_device_register(struct device_node *np, > cdev->devdata = devdata; > > ret = cdev->ops->get_max_state(cdev, &cdev->max_state); > - if (ret) > - goto out_kfree_type; > + if (ret) { > + kfree(cdev->type); > + goto out_ida_remove; > + } > > thermal_cooling_device_setup_sysfs(cdev); > + > ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id); > if (ret) { > + kfree(cdev->type); > thermal_cooling_device_destroy_sysfs(cdev); > - goto out_kfree_type; > + goto out_ida_remove; > } > + > ret = device_register(&cdev->device); > if (ret) > goto out_kfree_type; > @@ -943,6 +948,8 @@ __thermal_cooling_device_register(struct device_node *np, > thermal_cooling_device_destroy_sysfs(cdev); > kfree(cdev->type); > put_device(&cdev->device); > + > + /* thermal_release() takes care of the rest */ > cdev = NULL; > out_ida_remove: > ida_free(&thermal_cdev_ida, id); My testing: Applied on top of v6.2-rc1 The configuration is qcom_defconfig The system is a Qualcomm Dragon 8074 The two WARNING stack traces no longer occur after applying the patch. Tested-by: Frank Rowand