Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp687196rwb; Thu, 19 Jan 2023 01:02:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXs2+lDqt3QBCJvdkXFfXa/lou5kj1+dLyGPytlRmsrlVrQEZ2/8GTzKIQzBPKwWt2d0eh5M X-Received: by 2002:aa7:dbc4:0:b0:47c:445b:b4f with SMTP id v4-20020aa7dbc4000000b0047c445b0b4fmr9940359edt.32.1674118965698; Thu, 19 Jan 2023 01:02:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674118965; cv=none; d=google.com; s=arc-20160816; b=CG2xaU4FiNc5x6muOWZJEwpij8jAQLqKB6FZZLthbcc9X3/OpNxrEcP1ZmZm6zMtqB Zgl+Raaw00kV1Uc5PJnnW2o8f/X80XBgNMJJeGxCFHeOu2rqHZ/Lwoa7QNyOUCaNptHa GOAeABQk+5Ib2v8hqHi6KzjvxiWabhOzCDdLLnGvJCaH2jSLo+G47MYxM5bxMc/hmaw4 KtAbwmR8xvZ7AhXD85vtu18Xcg8CsZ86GYApRxH/hUXRUVka/sUyKQ0N35YO/UKqvQRP jktbzL/sTT3N66wfHqIjEj0XA1sQsnNg3bOZxZJFrazfdwfZrIEqUTPC9fnylsLaW5f/ LWfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=PAJKyAhhMPVq6za4tzgxXPGClT4sRaI5NHGGKGO2GuE=; b=B+Vj1Ap5EQqCu4JhbEnCealEe1BtkUNzCzhP1928pPmhN18VRKm6kYVQaMUCVjkkCP jJ+A4upyCsknXhAth8ZN5oi3kUrOxdB09jdMctUE8NJhT8pupUSfFQwTlb8aTW3kb4tj PGl6e7/MKoh/g36VoQl7zauKXHa09MZGXXkseVSxTlgZ/uOptbNc3Mps1f/5KpRZHuXW 5KWDBQ+Fxo49a+LTidTWKjeH3tRmchRqIUJ3o7uneM0Dt/9yFW8AEmRI1AAyiIT15Qrh cA6xXenqcPD+o3sdvjNpDKrLTOIMbE7H3NKK6b3ar0Vfyuvh7OhGuAyCh3n+9xcyQx3w pAow== 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 sd38-20020a1709076e2600b008725a1034d3si9670811ejc.85.2023.01.19.01.02.34; Thu, 19 Jan 2023 01:02:45 -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 S229820AbjASINT (ORCPT + 44 others); Thu, 19 Jan 2023 03:13:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjASINR (ORCPT ); Thu, 19 Jan 2023 03:13:17 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B665145BDD; Thu, 19 Jan 2023 00:13:15 -0800 (PST) Received: from dggpemm100007.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NyFh74YGwzRrHR; Thu, 19 Jan 2023 16:11:19 +0800 (CST) Received: from [10.174.178.174] (10.174.178.174) by dggpemm100007.china.huawei.com (7.185.36.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Thu, 19 Jan 2023 16:13:12 +0800 Subject: Re: [PATCH V4 1/3] thermal: core: call put_device() only after device_register() fails To: Viresh Kumar , "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui CC: , Vincent Guittot , Caleb Connolly , "Rafael J. Wysocki" , References: From: Yang Yingliang Message-ID: Date: Thu, 19 Jan 2023 16:13:12 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.178.174] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100007.china.huawei.com (7.185.36.116) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.3 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 On 2023/1/18 16: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 > --- Reviewed-by: Yang Yingliang > 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);