Message ID | 20221027031648.2452-1-huangqibo.tech@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp203751dyb; Wed, 26 Oct 2022 20:26:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4X5dYQpEhDW/NdVWev1S0jSRLTs4Qphwye+t2jhi490rSPv6IukhuoLaGeaIY3x3VWKSgY X-Received: by 2002:a17:902:8a97:b0:178:1939:c721 with SMTP id p23-20020a1709028a9700b001781939c721mr48236219plo.108.1666841190750; Wed, 26 Oct 2022 20:26:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666841190; cv=none; d=google.com; s=arc-20160816; b=YjVA+KdiA75JvoAwefu5k9KQUoV5clGOxwJVwPqWZjttxk6hY3w5kBeGzQt7IwWPPe 9PFXJBFjVZSH/hKkIB3+zDaHiqUoBqwySeeLYQw6RYQ2hE/cvHfOCQTpVm/7W6QopdOB OLT5+GTcIVoSpGKj5Gwr+hxueBLzF+l5ZYLT5bJXiWdmLmkNnj+FjqiUdUUDkIyP9GyL uCvqFH8A3itw6bg8ncC30r42O2MQQAVogmfhOevTBALXf7x49VIQ7MhH+2Ekd0W+wQjS WbQex+Pmc2q7jPjpMsBz20CiAu3lCq7hL0+JGZJdF+XhTzOQiVQvREe0j9y/VZUBkGgG rTJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UdfYL7Y9VZRkcaGm5JO6kmXdUQOSNAtEcm9KHbShwM0=; b=ExvxTb6OmAviGdTTzcEobtH2l7Hbfb9Rd9pkj6G2Dz8qhdSYv0vTKQEW9csaAi1No7 sCb3puLuCfpeLADVfyZ8rbHHHf887J2Rtoyhe0RsxmSDNmN9yca5Mm3obYhuW0kZZhLR 5lLt4sMXFLDDDFaTnKRhPLTD4or6cOaVSSj4h3UacweooU4m51zzhBABHnz9YCERNanR QZGp9yJ6PHF+GHx9axNP3gk3NnNR0ifQ/h8+zN/IAFn2StrXpA1KknMN6xs1qWL1QtTl T8bKuFH+hN+3/relLRyMtJhGYtu6H433Svi22Ebvh6NQHXPmjl6FR9lVokzwXnzOoE9z IRvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XIR6I96J; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w5-20020a170902e88500b001867bac69cdsi150123plg.342.2022.10.26.20.26.17; Wed, 26 Oct 2022 20:26:30 -0700 (PDT) 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=XIR6I96J; 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 S234260AbiJ0DRF (ORCPT <rfc822;hiifong.im@gmail.com> + 99 others); Wed, 26 Oct 2022 23:17:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbiJ0DQ7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 26 Oct 2022 23:16:59 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8B89DD896; Wed, 26 Oct 2022 20:16:58 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id q1so17045600pgl.11; Wed, 26 Oct 2022 20:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UdfYL7Y9VZRkcaGm5JO6kmXdUQOSNAtEcm9KHbShwM0=; b=XIR6I96JOE4YdJFAGI9vkaV9ftdFHLXvgaTfH/BrmdWg9E2lioAP3gwj4j1QwOd2kg X+kE3+dK4thHPm6gdtYky6VrtInB+1Q1jGzVBZwg+eGWIVy8edwa/o3jOjFBZZGh3+Jn avgFZEtcdOQWzfLftnRYYAcVp/s5Bxbq3Yt5xcRHl7a6pW2hZ54N3drqU/cnp3KUd2s9 waFl/lFpGUTa42N5g7fZz0MaF7hrepY/48d78ngJk4gNlWYNWURl2QoudknCUVCzYOen 48S/4/HXTh9ZzjtopQlg7loHvqdxIZxAN2OmYYfCwiucNx58+w6gXGKor9H8EGjaTk0O wQNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UdfYL7Y9VZRkcaGm5JO6kmXdUQOSNAtEcm9KHbShwM0=; b=1P2R7Zn5QVL+zeH63gLYPgcSDLL1UBQAo3Nnv02pQzk3Dr4aJk6UiF01BfEhKvHonA c4QvsLscOlbDDEYgXu3lIOHQScISbAe2u5G9XuizpG2waqUw80AcrWjjlmI6MpEymrw0 Cd3kg5egWYUj/YT/7dvikP9RB++OyEgdjT1K+yfPKaG12ucbQRc5AFmn5AZgN4BJ+2zq HcxI8yevoUPEE1K5/coM6a0w9hZL6ed06WXNzHWtu22SG7QV/pttOoQbgEe41BjULlEU PB5+aLXb/wuWuuJLF++y/7a/lZwGr1SGS/17RStUGvJYnAGsOrLKWzFZox31yauNPd4J llCw== X-Gm-Message-State: ACrzQf2qQImFKOE4tVDyHwjAKEIKmHYbx2Zm6BKsv+74EpVQZTypAkGY WY8irqnl4qyigdnCbizVjGA= X-Received: by 2002:a63:1b16:0:b0:46b:8e7:3e0a with SMTP id b22-20020a631b16000000b0046b08e73e0amr39509387pgb.86.1666840618217; Wed, 26 Oct 2022 20:16:58 -0700 (PDT) Received: from localhost.localdomain ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id d17-20020aa797b1000000b0056bb99db338sm112636pfq.175.2022.10.26.20.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 20:16:57 -0700 (PDT) From: Qibo Huang <huangqibo.tech@gmail.com> To: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Qibo Huang <huangqibo.tech@gmail.com> Subject: [PATCH] thermal/core: cooling device duplicate creation check Date: Thu, 27 Oct 2022 11:16:48 +0800 Message-Id: <20221027031648.2452-1-huangqibo.tech@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747809668547467971?= X-GMAIL-MSGID: =?utf-8?q?1747809668547467971?= |
Series |
thermal/core: cooling device duplicate creation check
|
|
Commit Message
Qibo Huang
Oct. 27, 2022, 3:16 a.m. UTC
Because creating a cooling device may have duplicate names.
When creating, first check thermal_cdev_list whether
there is a device with the same name. If it has the same name,
it returns a reference to the cooling device.
Signed-off-by: Qibo Huang <huangqibo.tech@gmail.com>
---
drivers/thermal/thermal_core.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
Comments
Hi Qibo, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on rafael-pm/thermal] [also build test WARNING on linus/master v6.1-rc2 next-20221027] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Qibo-Huang/thermal-core-cooling-device-duplicate-creation-check/20221027-111751 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal patch link: https://lore.kernel.org/r/20221027031648.2452-1-huangqibo.tech%40gmail.com patch subject: [PATCH] thermal/core: cooling device duplicate creation check config: x86_64-randconfig-a016 compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/a48c9aab70c31e06e9e02f82cb2283153012dfa0 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Qibo-Huang/thermal-core-cooling-device-duplicate-creation-check/20221027-111751 git checkout a48c9aab70c31e06e9e02f82cb2283153012dfa0 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/thermal/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): >> drivers/thermal/thermal_core.c:847:32: warning: no previous prototype for function 'thermal_cdev_get_zone_by_name' [-Wmissing-prototypes] struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) ^ drivers/thermal/thermal_core.c:847:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) ^ static 1 warning generated. vim +/thermal_cdev_get_zone_by_name +847 drivers/thermal/thermal_core.c 846 > 847 struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) 848 { 849 struct thermal_cooling_device *pos = NULL, *ref = ERR_PTR(-EINVAL); 850 unsigned int found = 0; 851 852 if (!name) 853 goto exit; 854 855 mutex_lock(&thermal_list_lock); 856 list_for_each_entry(pos, &thermal_cdev_list, node) 857 if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { 858 found++; 859 ref = pos; 860 } 861 mutex_unlock(&thermal_list_lock); 862 863 /* nothing has been found, thus an error code for it */ 864 if (found == 0) 865 ref = ERR_PTR(-ENODEV); 866 else if (found > 1) 867 /* Success only when an unique zone is found */ 868 ref = ERR_PTR(-EEXIST); 869 870 exit: 871 return ref; 872 } 873 EXPORT_SYMBOL_GPL(thermal_cdev_get_zone_by_name); 874
Hi Qibo, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on rafael-pm/thermal] [also build test WARNING on linus/master v6.1-rc2 next-20221027] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Qibo-Huang/thermal-core-cooling-device-duplicate-creation-check/20221027-111751 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal patch link: https://lore.kernel.org/r/20221027031648.2452-1-huangqibo.tech%40gmail.com patch subject: [PATCH] thermal/core: cooling device duplicate creation check config: i386-randconfig-a013 compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/intel-lab-lkp/linux/commit/a48c9aab70c31e06e9e02f82cb2283153012dfa0 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Qibo-Huang/thermal-core-cooling-device-duplicate-creation-check/20221027-111751 git checkout a48c9aab70c31e06e9e02f82cb2283153012dfa0 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/thermal/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): >> drivers/thermal/thermal_core.c:847:32: warning: no previous prototype for function 'thermal_cdev_get_zone_by_name' [-Wmissing-prototypes] struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) ^ drivers/thermal/thermal_core.c:847:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) ^ static 1 warning generated. vim +/thermal_cdev_get_zone_by_name +847 drivers/thermal/thermal_core.c 846 > 847 struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) 848 { 849 struct thermal_cooling_device *pos = NULL, *ref = ERR_PTR(-EINVAL); 850 unsigned int found = 0; 851 852 if (!name) 853 goto exit; 854 855 mutex_lock(&thermal_list_lock); 856 list_for_each_entry(pos, &thermal_cdev_list, node) 857 if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { 858 found++; 859 ref = pos; 860 } 861 mutex_unlock(&thermal_list_lock); 862 863 /* nothing has been found, thus an error code for it */ 864 if (found == 0) 865 ref = ERR_PTR(-ENODEV); 866 else if (found > 1) 867 /* Success only when an unique zone is found */ 868 ref = ERR_PTR(-EEXIST); 869 870 exit: 871 return ref; 872 } 873 EXPORT_SYMBOL_GPL(thermal_cdev_get_zone_by_name); 874
On Thu, Oct 27, 2022 at 5:17 AM Qibo Huang <huangqibo.tech@gmail.com> wrote: > > Because creating a cooling device may have duplicate names. Why is this a problem? > When creating, first check thermal_cdev_list whether > there is a device with the same name. If it has the same name, > it returns a reference to the cooling device. Why is this a correct and the best possible solution? > Signed-off-by: Qibo Huang <huangqibo.tech@gmail.com> > --- > drivers/thermal/thermal_core.c | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 7e669b60a065..f38f9464e9f4 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -844,6 +844,34 @@ static void bind_cdev(struct thermal_cooling_device *cdev) > mutex_unlock(&thermal_list_lock); > } > > +struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) > +{ > + struct thermal_cooling_device *pos = NULL, *ref = ERR_PTR(-EINVAL); > + unsigned int found = 0; > + > + if (!name) > + goto exit; > + > + mutex_lock(&thermal_list_lock); > + list_for_each_entry(pos, &thermal_cdev_list, node) > + if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { > + found++; > + ref = pos; > + } > + mutex_unlock(&thermal_list_lock); > + > + /* nothing has been found, thus an error code for it */ > + if (found == 0) > + ref = ERR_PTR(-ENODEV); > + else if (found > 1) > + /* Success only when an unique zone is found */ > + ref = ERR_PTR(-EEXIST); > + > +exit: > + return ref; > +} > +EXPORT_SYMBOL_GPL(thermal_cdev_get_zone_by_name); > + > /** > * __thermal_cooling_device_register() - register a new thermal cooling device > * @np: a pointer to a device tree node. > @@ -873,6 +901,12 @@ __thermal_cooling_device_register(struct device_node *np, > !ops->set_cur_state) > return ERR_PTR(-EINVAL); > > + if (type) { > + cdev = thermal_cdev_get_zone_by_name(type); > + if (!IS_ERR(cdev)) > + return cdev; > + } > + > cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); > if (!cdev) > return ERR_PTR(-ENOMEM); > -- > 2.37.1 >
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 7e669b60a065..f38f9464e9f4 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -844,6 +844,34 @@ static void bind_cdev(struct thermal_cooling_device *cdev) mutex_unlock(&thermal_list_lock); } +struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) +{ + struct thermal_cooling_device *pos = NULL, *ref = ERR_PTR(-EINVAL); + unsigned int found = 0; + + if (!name) + goto exit; + + mutex_lock(&thermal_list_lock); + list_for_each_entry(pos, &thermal_cdev_list, node) + if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { + found++; + ref = pos; + } + mutex_unlock(&thermal_list_lock); + + /* nothing has been found, thus an error code for it */ + if (found == 0) + ref = ERR_PTR(-ENODEV); + else if (found > 1) + /* Success only when an unique zone is found */ + ref = ERR_PTR(-EEXIST); + +exit: + return ref; +} +EXPORT_SYMBOL_GPL(thermal_cdev_get_zone_by_name); + /** * __thermal_cooling_device_register() - register a new thermal cooling device * @np: a pointer to a device tree node. @@ -873,6 +901,12 @@ __thermal_cooling_device_register(struct device_node *np, !ops->set_cur_state) return ERR_PTR(-EINVAL); + if (type) { + cdev = thermal_cdev_get_zone_by_name(type); + if (!IS_ERR(cdev)) + return cdev; + } + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); if (!cdev) return ERR_PTR(-ENOMEM);