Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp7054185rwb; Wed, 18 Jan 2023 12:53:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXuINJn9ozeQ66XB7Bt88FpkeP6HkLmYI7yN+jO7DosmJP4TG5X2LP2oEx3nGAQnvU6Ojyq2 X-Received: by 2002:a17:907:1c0b:b0:7c0:f213:4485 with SMTP id nc11-20020a1709071c0b00b007c0f2134485mr11178143ejc.73.1674075202120; Wed, 18 Jan 2023 12:53:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674075202; cv=none; d=google.com; s=arc-20160816; b=ANJ9c9UURUJuX9haAJQZfB9jPc8aoCbF1PwFEf8pkxfzYwrlUd4wjc/bLQnApbLw+P XVGIAl0Hgnf6KaVK5tsO7d0ZY1CJguFVhvG+8kzKna70Nd7CybOk+kHz9brbzBbUhfLB 97pvXoW7qK9c/UYs3TEestVaThJPaNQeXspLlx6lWWZX1py3mp0hoKUkcylez0+v+5cM ErnCC5SOify9Kdqnrjq/Fx8VSB3GJZd4at7Mtamnn6E65HHfvk4lMUKcEP9jRNn3daSf S+eTETJI9z5OAeqRN+2rBpgHfljbgSlqqsPWtlhCmB4/O2NOWEcbC0Z1+yTp+m3+lFpc X1DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=hA+fH1BKAR8DwjMQTDciJR2Bu4noelLBTmt8cjD5KaI=; b=UnmMkz57ERRdcAQIF/cl/xQxMzX40FodMX6BjdObsJLwoi2Ngsg/u7knCaM0TmOe+t N/6Ay8qTgcLXsMGo3+GE3Uy5jXSkTWQGysij1ptZzAYijbCprXd8708/vMwF7f6jd3tZ WDHafm3zuQ+9T+wGZGVefO9owahWbWmpJ3ed0SOBIATwZLCjCiaJeUZk15VVw+2ovde1 XY3uu8GbNc1q3XiD4KsnalRg/7JDj88mBr4EyH5ihChsU6oeE7BjC3XrKbyfNwK0qdIt WYpZqW2dj0dRkirqrAYnKGRYZOq+dccqsuLP/T8cn3G+P6uCWFnzRHQs61b8mR2CUPHf +5RA== 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q20-20020a056402519400b0049e0fd70dcesi2062496edd.293.2023.01.18.12.53.11; Wed, 18 Jan 2023 12:53:22 -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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229659AbjART6Z (ORCPT + 45 others); Wed, 18 Jan 2023 14:58:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbjART6Y (ORCPT ); Wed, 18 Jan 2023 14:58:24 -0500 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94B4E53E7B; Wed, 18 Jan 2023 11:58:23 -0800 (PST) Received: by mail-ej1-f49.google.com with SMTP id az20so52931ejc.1; Wed, 18 Jan 2023 11:58:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hA+fH1BKAR8DwjMQTDciJR2Bu4noelLBTmt8cjD5KaI=; b=xJOZOTVU8i+HWnAMzZLwxQ/REhvPSoYG2i+OlD97lmOijewiPr0eAGOvyv+dN5nh3h Hw/qL9FhkV//QdryXSpJHpiYCArMc5eMITzV/mpE+x331R4ZPLoA3u64I7M+NuEN3xG4 AQeNqFv6i/1mCplXcma/60MnfhwEMw9XnQk8GgluR+or0F50MuixeCzdu59c3sopHPB7 p5DDnzxVQrtToXaHqLGC0dNpRWAGb98oFsyG4K0WcMBDbAs78stwAtB6/QmhfxnM223S /M0hPLl7mveZPphWCh+OAb1/WORI7Ge5uWyFcEmAHeXnjjMJXNdOBw9+5Uli0Dla4gjr /tZQ== X-Gm-Message-State: AFqh2kpjmfzFwQ6BvMAMChHzGD9LLyTDbSH+S6Ktor/v/lMXO4BE002S eCkvtPHK5ZlHtuU08eYq4tUjN8yikrbxxH6EaQ8= X-Received: by 2002:a17:906:64a:b0:84d:3c6a:4c55 with SMTP id t10-20020a170906064a00b0084d3c6a4c55mr1058644ejb.509.1674071902195; Wed, 18 Jan 2023 11:58:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 18 Jan 2023 20:58:10 +0100 Message-ID: Subject: Re: [PATCH V4 1/3] thermal: core: call put_device() only after device_register() fails To: Viresh Kumar Cc: "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Yang Yingliang , linux-pm@vger.kernel.org, Vincent Guittot , Caleb Connolly , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no 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 Wed, Jan 18, 2023 at 9:38 AM 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 OK, so I think that this patch is needed for 6.2 and the other two may be queued up for later (they do depend on this one, though, of course). Is my understanding correct? > --- > 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); > -- > 2.31.1.272.g89b43f80a514 >