Message ID | 20221026120321.735-1-huangqibo.tech@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp225899wru; Wed, 26 Oct 2022 05:08:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7tyKQKtaHZJqJ5kNQtJTqqLYwCOin+JD7+TqSn2oAoiwXZWT62oe6UxKyCRyBn/U0c2slo X-Received: by 2002:a17:907:7290:b0:78d:ec20:fe4d with SMTP id dt16-20020a170907729000b0078dec20fe4dmr37733719ejc.528.1666786112694; Wed, 26 Oct 2022 05:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666786112; cv=none; d=google.com; s=arc-20160816; b=VFHPg12HvgXktSwpmKtpI+8MqgSyWIYViCftg3g5MFLp2EAVwZKSoz/ldNke4F9j+J TG6N8PCYd11sOOCN8JNsd99UngTYEXAjyZvevUrvAFtSvoa2rrpL0eyEZwiBj3xhqWnE XaybF4M6p9Vf7I317oicUWn7DbAk5K9lp0ulWWHCOYF1ah8XzVMJsPTUCw+x958zKr7Z ujoDtNTakzDNCs5PRHv8532tu0m1+mBwZpZM8jj4w3e1/gMaZcG4SoEn1XsyzBE157F6 A9VmwK9o1yWM1VpKBURALtaR+egQldssAzpeQc/9e685Ge/KyOn8FWHiLZY4fW3c4o4P lrWw== 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=eeyWPYOfNLO5HnpCrV5iKgVUweZC5smkX35UuDur0+M=; b=E0GxbNTiQxpTLiKm/oMkAbQASAF2OF43/dy2kf9uTPnlCwuz46qABwtUG09/3ZQgoR AaNcprA6bZ0JSDY583rULuAAjs7d/Oq4q7HOJZVm6LvnBh2X5Eyzjyv3jvtTlYPKgMsB c+ELPfeKbYnfvEimRGy2WQ4sqHb8Bg3FR+fG32LJ+I8nhFZDV0OK/zRoaozc1bQ7jRYf UdlSN6mrjprBPMZNpEsIUSJBJXvNncWiJ7PsSUJnJg7wb994WQKh88Y1XsURlTCj1StG qmXr7uvoKaYJ+YgtBVq+4IAjyO6W8ClTWtEY0sZmlsoBTA47lPdHpak4cswJJJiNtuF4 IZkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=M3jMZCz2; 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 sd31-20020a1709076e1f00b0078e0e850902si5968149ejc.868.2022.10.26.05.08.04; Wed, 26 Oct 2022 05:08:32 -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=M3jMZCz2; 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 S233619AbiJZMDi (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Wed, 26 Oct 2022 08:03:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233485AbiJZMDg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 26 Oct 2022 08:03:36 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6FB14B4BC; Wed, 26 Oct 2022 05:03:34 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id p3so12878277pld.10; Wed, 26 Oct 2022 05:03:34 -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=eeyWPYOfNLO5HnpCrV5iKgVUweZC5smkX35UuDur0+M=; b=M3jMZCz2f9I//6dZFQixFueDv6DvYYSZAPHVtKl+MyKAgJt6T38Gb6GzCvJeBqFFWe 0IPEe0eefPjToxWp/R7HaW03L9zOfBHUukgzhX6wH2VLoqOP1LiSPhUW8qdlzKVa1fyn ynUjy1O7nL0X2uG4J6xqfMZCAWMRa/K8N2Ttl14QZGYaym4CzdqkSkNDznT6XxNUhg1A DGnknrKGEEZOpISRKsAuZ9K3FbMmReDddGUuhOTenZ7QTT1bXck7JGO0cAeMWvlZO7SK peq006gMhlFVtmMBqC0WmcoxoqEhL/vgut4uQHRWurhrmUrceuEwqtg6fro2VEvfGI8h c81Q== 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=eeyWPYOfNLO5HnpCrV5iKgVUweZC5smkX35UuDur0+M=; b=JZY6CnB6aNqfH6j9QSrDkbMmHYnWx7kWhRGfC0x8hNEacGQWmLQsIVeQNxQ7XLY3NZ sWXg013DPPIa2QrFQhmu36sptr6g3B1Sawzp1B/b4ih0GqCf3eob37s1xaREco+LnC43 6dQE509Anqu3w1gFFw5ycA0vQ5Vqp7QyX63H5QzCX9QFh2qEjS3dZfbNmsmzVaaEkwWF lcTlSJSXhjdUPkz/nk81oB22O19eKz2JQhfsK2soQrhXF/A4rRmEPErHfJRNEkjhfaYf yEA3ADFV9QRcNAgRt5m1GOPEbGW0YDHs19dP0qNeeAdIpo1x9tA0/3YJPZB2PUXoAE38 zjoA== X-Gm-Message-State: ACrzQf1K+QKNAN6JOPHQVovOSHa+Ye3snKZ3XiscatQpwwVW5DVTHc3X MqVyuaf3vv8Rk/CfrpySFRj/Z/QqeGk= X-Received: by 2002:a17:902:ed82:b0:178:5653:ecfb with SMTP id e2-20020a170902ed8200b001785653ecfbmr43634366plj.58.1666785814222; Wed, 26 Oct 2022 05:03:34 -0700 (PDT) Received: from localhost.localdomain ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id f27-20020aa7969b000000b0053e4296e1d3sm2863289pfk.198.2022.10.26.05.03.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 05:03:33 -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, huangqibo <huangqibo@xiaomi.com> Subject: [PATCH] thermal/core: cooling device duplicate creation check Date: Wed, 26 Oct 2022 20:03:21 +0800 Message-Id: <20221026120321.735-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?1747751915216330636?= X-GMAIL-MSGID: =?utf-8?q?1747751915216330636?= |
Series |
thermal/core: cooling device duplicate creation check
|
|
Commit Message
Qibo Huang
Oct. 26, 2022, 12:03 p.m. UTC
From: huangqibo <huangqibo@xiaomi.com> 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: huangqibo <huangqibo@xiaomi.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-20221026] [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/20221026-200457 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal patch link: https://lore.kernel.org/r/20221026120321.735-1-huangqibo.tech%40gmail.com patch subject: [PATCH] thermal/core: cooling device duplicate creation check config: m68k-allyesconfig compiler: m68k-linux-gcc (GCC) 12.1.0 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/b9ffa61b51bd8fb000c57f602e94908c46345283 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/20221026-200457 git checkout b9ffa61b51bd8fb000c57f602e94908c46345283 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/ 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: In function '__thermal_cooling_device_register': drivers/thermal/thermal_core.c:877:24: error: implicit declaration of function 'thermal_cdev_get_zone_by_name'; did you mean 'thermal_zone_get_zone_by_name'? [-Werror=implicit-function-declaration] 877 | cdev = thermal_cdev_get_zone_by_name(type); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | thermal_zone_get_zone_by_name >> drivers/thermal/thermal_core.c:877:22: warning: assignment to 'struct thermal_cooling_device *' from 'int' makes pointer from integer without a cast [-Wint-conversion] 877 | cdev = thermal_cdev_get_zone_by_name(type); | ^ drivers/thermal/thermal_core.c: At top level: >> drivers/thermal/thermal_core.c:1444:32: warning: no previous prototype for 'thermal_cdev_get_zone_by_name' [-Wmissing-prototypes] 1444 | struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/thermal/thermal_core.c:1444:32: error: conflicting types for 'thermal_cdev_get_zone_by_name'; have 'struct thermal_cooling_device *(const char *)' drivers/thermal/thermal_core.c:877:24: note: previous implicit declaration of 'thermal_cdev_get_zone_by_name' with type 'int()' 877 | cdev = thermal_cdev_get_zone_by_name(type); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors vim +877 drivers/thermal/thermal_core.c 846 847 /** 848 * __thermal_cooling_device_register() - register a new thermal cooling device 849 * @np: a pointer to a device tree node. 850 * @type: the thermal cooling device type. 851 * @devdata: device private data. 852 * @ops: standard thermal cooling devices callbacks. 853 * 854 * This interface function adds a new thermal cooling device (fan/processor/...) 855 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself 856 * to all the thermal zone devices registered at the same time. 857 * It also gives the opportunity to link the cooling device to a device tree 858 * node, so that it can be bound to a thermal zone created out of device tree. 859 * 860 * Return: a pointer to the created struct thermal_cooling_device or an 861 * ERR_PTR. Caller must check return value with IS_ERR*() helpers. 862 */ 863 static struct thermal_cooling_device * 864 __thermal_cooling_device_register(struct device_node *np, 865 const char *type, void *devdata, 866 const struct thermal_cooling_device_ops *ops) 867 { 868 struct thermal_cooling_device *cdev; 869 struct thermal_zone_device *pos = NULL; 870 int id, ret; 871 872 if (!ops || !ops->get_max_state || !ops->get_cur_state || 873 !ops->set_cur_state) 874 return ERR_PTR(-EINVAL); 875 876 if (type) > 877 cdev = thermal_cdev_get_zone_by_name(type); 878 879 if (!IS_ERR_OR_NULL(cdev)) 880 return cdev; 881 882 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); 883 if (!cdev) 884 return ERR_PTR(-ENOMEM); 885 886 ret = ida_alloc(&thermal_cdev_ida, GFP_KERNEL); 887 if (ret < 0) 888 goto out_kfree_cdev; 889 cdev->id = ret; 890 id = ret; 891 892 ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id); 893 if (ret) 894 goto out_ida_remove; 895 896 cdev->type = kstrdup(type ? type : "", GFP_KERNEL); 897 if (!cdev->type) { 898 ret = -ENOMEM; 899 goto out_ida_remove; 900 } 901 902 mutex_init(&cdev->lock); 903 INIT_LIST_HEAD(&cdev->thermal_instances); 904 cdev->np = np; 905 cdev->ops = ops; 906 cdev->updated = false; 907 cdev->device.class = &thermal_class; 908 cdev->devdata = devdata; 909 thermal_cooling_device_setup_sysfs(cdev); 910 ret = device_register(&cdev->device); 911 if (ret) 912 goto out_kfree_type; 913 914 /* Add 'this' new cdev to the global cdev list */ 915 mutex_lock(&thermal_list_lock); 916 list_add(&cdev->node, &thermal_cdev_list); 917 mutex_unlock(&thermal_list_lock); 918 919 /* Update binding information for 'this' new cdev */ 920 bind_cdev(cdev); 921 922 mutex_lock(&thermal_list_lock); 923 list_for_each_entry(pos, &thermal_tz_list, node) 924 if (atomic_cmpxchg(&pos->need_update, 1, 0)) 925 thermal_zone_device_update(pos, 926 THERMAL_EVENT_UNSPECIFIED); 927 mutex_unlock(&thermal_list_lock); 928 929 return cdev; 930 931 out_kfree_type: 932 thermal_cooling_device_destroy_sysfs(cdev); 933 kfree(cdev->type); 934 put_device(&cdev->device); 935 cdev = NULL; 936 out_ida_remove: 937 ida_free(&thermal_cdev_ida, id); 938 out_kfree_cdev: 939 kfree(cdev); 940 return ERR_PTR(ret); 941 } 942
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-20221026] [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/20221026-200457 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal patch link: https://lore.kernel.org/r/20221026120321.735-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/b9ffa61b51bd8fb000c57f602e94908c46345283 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/20221026-200457 git checkout b9ffa61b51bd8fb000c57f602e94908c46345283 # 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:877:10: error: implicit declaration of function 'thermal_cdev_get_zone_by_name' is invalid in C99 [-Werror,-Wimplicit-function-declaration] cdev = thermal_cdev_get_zone_by_name(type); ^ drivers/thermal/thermal_core.c:877:10: note: did you mean 'thermal_zone_get_zone_by_name'? include/linux/thermal.h:368:29: note: 'thermal_zone_get_zone_by_name' declared here struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); ^ >> drivers/thermal/thermal_core.c:877:8: warning: incompatible integer to pointer conversion assigning to 'struct thermal_cooling_device *' from 'int' [-Wint-conversion] cdev = thermal_cdev_get_zone_by_name(type); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/thermal/thermal_core.c:1444:32: error: conflicting types for 'thermal_cdev_get_zone_by_name' struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) ^ drivers/thermal/thermal_core.c:877:10: note: previous implicit declaration is here cdev = thermal_cdev_get_zone_by_name(type); ^ 1 warning and 2 errors generated. vim +877 drivers/thermal/thermal_core.c 846 847 /** 848 * __thermal_cooling_device_register() - register a new thermal cooling device 849 * @np: a pointer to a device tree node. 850 * @type: the thermal cooling device type. 851 * @devdata: device private data. 852 * @ops: standard thermal cooling devices callbacks. 853 * 854 * This interface function adds a new thermal cooling device (fan/processor/...) 855 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself 856 * to all the thermal zone devices registered at the same time. 857 * It also gives the opportunity to link the cooling device to a device tree 858 * node, so that it can be bound to a thermal zone created out of device tree. 859 * 860 * Return: a pointer to the created struct thermal_cooling_device or an 861 * ERR_PTR. Caller must check return value with IS_ERR*() helpers. 862 */ 863 static struct thermal_cooling_device * 864 __thermal_cooling_device_register(struct device_node *np, 865 const char *type, void *devdata, 866 const struct thermal_cooling_device_ops *ops) 867 { 868 struct thermal_cooling_device *cdev; 869 struct thermal_zone_device *pos = NULL; 870 int id, ret; 871 872 if (!ops || !ops->get_max_state || !ops->get_cur_state || 873 !ops->set_cur_state) 874 return ERR_PTR(-EINVAL); 875 876 if (type) > 877 cdev = thermal_cdev_get_zone_by_name(type); 878 879 if (!IS_ERR_OR_NULL(cdev)) 880 return cdev; 881 882 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); 883 if (!cdev) 884 return ERR_PTR(-ENOMEM); 885 886 ret = ida_alloc(&thermal_cdev_ida, GFP_KERNEL); 887 if (ret < 0) 888 goto out_kfree_cdev; 889 cdev->id = ret; 890 id = ret; 891 892 ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id); 893 if (ret) 894 goto out_ida_remove; 895 896 cdev->type = kstrdup(type ? type : "", GFP_KERNEL); 897 if (!cdev->type) { 898 ret = -ENOMEM; 899 goto out_ida_remove; 900 } 901 902 mutex_init(&cdev->lock); 903 INIT_LIST_HEAD(&cdev->thermal_instances); 904 cdev->np = np; 905 cdev->ops = ops; 906 cdev->updated = false; 907 cdev->device.class = &thermal_class; 908 cdev->devdata = devdata; 909 thermal_cooling_device_setup_sysfs(cdev); 910 ret = device_register(&cdev->device); 911 if (ret) 912 goto out_kfree_type; 913 914 /* Add 'this' new cdev to the global cdev list */ 915 mutex_lock(&thermal_list_lock); 916 list_add(&cdev->node, &thermal_cdev_list); 917 mutex_unlock(&thermal_list_lock); 918 919 /* Update binding information for 'this' new cdev */ 920 bind_cdev(cdev); 921 922 mutex_lock(&thermal_list_lock); 923 list_for_each_entry(pos, &thermal_tz_list, node) 924 if (atomic_cmpxchg(&pos->need_update, 1, 0)) 925 thermal_zone_device_update(pos, 926 THERMAL_EVENT_UNSPECIFIED); 927 mutex_unlock(&thermal_list_lock); 928 929 return cdev; 930 931 out_kfree_type: 932 thermal_cooling_device_destroy_sysfs(cdev); 933 kfree(cdev->type); 934 put_device(&cdev->device); 935 cdev = NULL; 936 out_ida_remove: 937 ida_free(&thermal_cdev_ida, id); 938 out_kfree_cdev: 939 kfree(cdev); 940 return ERR_PTR(ret); 941 } 942
Hi Qibo, Thank you for the patch! Yet something to improve: [auto build test ERROR on rafael-pm/thermal] [also build test ERROR on linus/master v6.1-rc2 next-20221026] [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/20221026-200457 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal patch link: https://lore.kernel.org/r/20221026120321.735-1-huangqibo.tech%40gmail.com patch subject: [PATCH] thermal/core: cooling device duplicate creation check config: mips-randconfig-r021-20221026 compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 791a7ae1ba3efd6bca96338e10ffde557ba83920) 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 # install mips cross compiling tool for clang build # apt-get install binutils-mips64el-linux-gnuabi64 # https://github.com/intel-lab-lkp/linux/commit/b9ffa61b51bd8fb000c57f602e94908c46345283 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/20221026-200457 git checkout b9ffa61b51bd8fb000c57f602e94908c46345283 # 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=mips SHELL=/bin/bash drivers/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): >> drivers/thermal/thermal_core.c:877:10: error: call to undeclared function 'thermal_cdev_get_zone_by_name'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] cdev = thermal_cdev_get_zone_by_name(type); ^ drivers/thermal/thermal_core.c:877:10: note: did you mean 'thermal_zone_get_zone_by_name'? include/linux/thermal.h:368:29: note: 'thermal_zone_get_zone_by_name' declared here struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); ^ >> drivers/thermal/thermal_core.c:877:8: error: incompatible integer to pointer conversion assigning to 'struct thermal_cooling_device *' from 'int' [-Wint-conversion] cdev = thermal_cdev_get_zone_by_name(type); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/thermal/thermal_core.c:1444:32: error: conflicting types for 'thermal_cdev_get_zone_by_name' struct thermal_cooling_device *thermal_cdev_get_zone_by_name(const char *name) ^ drivers/thermal/thermal_core.c:877:10: note: previous implicit declaration is here cdev = thermal_cdev_get_zone_by_name(type); ^ 3 errors generated. vim +/thermal_cdev_get_zone_by_name +877 drivers/thermal/thermal_core.c 846 847 /** 848 * __thermal_cooling_device_register() - register a new thermal cooling device 849 * @np: a pointer to a device tree node. 850 * @type: the thermal cooling device type. 851 * @devdata: device private data. 852 * @ops: standard thermal cooling devices callbacks. 853 * 854 * This interface function adds a new thermal cooling device (fan/processor/...) 855 * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself 856 * to all the thermal zone devices registered at the same time. 857 * It also gives the opportunity to link the cooling device to a device tree 858 * node, so that it can be bound to a thermal zone created out of device tree. 859 * 860 * Return: a pointer to the created struct thermal_cooling_device or an 861 * ERR_PTR. Caller must check return value with IS_ERR*() helpers. 862 */ 863 static struct thermal_cooling_device * 864 __thermal_cooling_device_register(struct device_node *np, 865 const char *type, void *devdata, 866 const struct thermal_cooling_device_ops *ops) 867 { 868 struct thermal_cooling_device *cdev; 869 struct thermal_zone_device *pos = NULL; 870 int id, ret; 871 872 if (!ops || !ops->get_max_state || !ops->get_cur_state || 873 !ops->set_cur_state) 874 return ERR_PTR(-EINVAL); 875 876 if (type) > 877 cdev = thermal_cdev_get_zone_by_name(type); 878 879 if (!IS_ERR_OR_NULL(cdev)) 880 return cdev; 881 882 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); 883 if (!cdev) 884 return ERR_PTR(-ENOMEM); 885 886 ret = ida_alloc(&thermal_cdev_ida, GFP_KERNEL); 887 if (ret < 0) 888 goto out_kfree_cdev; 889 cdev->id = ret; 890 id = ret; 891 892 ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id); 893 if (ret) 894 goto out_ida_remove; 895 896 cdev->type = kstrdup(type ? type : "", GFP_KERNEL); 897 if (!cdev->type) { 898 ret = -ENOMEM; 899 goto out_ida_remove; 900 } 901 902 mutex_init(&cdev->lock); 903 INIT_LIST_HEAD(&cdev->thermal_instances); 904 cdev->np = np; 905 cdev->ops = ops; 906 cdev->updated = false; 907 cdev->device.class = &thermal_class; 908 cdev->devdata = devdata; 909 thermal_cooling_device_setup_sysfs(cdev); 910 ret = device_register(&cdev->device); 911 if (ret) 912 goto out_kfree_type; 913 914 /* Add 'this' new cdev to the global cdev list */ 915 mutex_lock(&thermal_list_lock); 916 list_add(&cdev->node, &thermal_cdev_list); 917 mutex_unlock(&thermal_list_lock); 918 919 /* Update binding information for 'this' new cdev */ 920 bind_cdev(cdev); 921 922 mutex_lock(&thermal_list_lock); 923 list_for_each_entry(pos, &thermal_tz_list, node) 924 if (atomic_cmpxchg(&pos->need_update, 1, 0)) 925 thermal_zone_device_update(pos, 926 THERMAL_EVENT_UNSPECIFIED); 927 mutex_unlock(&thermal_list_lock); 928 929 return cdev; 930 931 out_kfree_type: 932 thermal_cooling_device_destroy_sysfs(cdev); 933 kfree(cdev->type); 934 put_device(&cdev->device); 935 cdev = NULL; 936 out_ida_remove: 937 ida_free(&thermal_cdev_ida, id); 938 out_kfree_cdev: 939 kfree(cdev); 940 return ERR_PTR(ret); 941 } 942
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 117eeaf7dd24..092c7732a294 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -873,6 +873,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_OR_NULL(cdev)) + return cdev; + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); if (!cdev) return ERR_PTR(-ENOMEM); @@ -1435,6 +1441,34 @@ struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name) } EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name); +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); + static int thermal_pm_notify(struct notifier_block *nb, unsigned long mode, void *_unused) {