Message ID | 20221122065002.2327772-1-zhangpeng362@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2035631wrr; Mon, 21 Nov 2022 22:28:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf4e+dAEXsPa+LN9/n1ZK/G99jbxdkT0ZrR6rHXUZj4tOm2n3xYnCXAaJxroN5/hvpH3KDQI X-Received: by 2002:a17:902:d4cf:b0:186:80e7:1e1 with SMTP id o15-20020a170902d4cf00b0018680e701e1mr2880193plg.135.1669098536376; Mon, 21 Nov 2022 22:28:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669098536; cv=none; d=google.com; s=arc-20160816; b=BX57lmgrH/b09dXs9dvaYvzeuWoUGh1IhzlDpDAyEoCNo2/u36+aCLf/4I518N5F8h auZKt5h1LCu1iV1YkAqiwdSfRcxNqmQ/sRkku81WxAMn5WTBaU2GC0pIEoVC8YOVKj5q G6aid/fTiw48UmPPZL36bns3acWKWCYAQlBItl2q5xOCvDl1HVed4xc58D2EN+Yor/0K hIAdKc9sPuJXomFoPAspV+BNdhogvFpzRelaqtWcvCX0BFQh5lAgZmXiFg6G++k89q/E IKqNfgV+buuIi3znaZkeTtx8J0eZBiaDbjllIGyqY29HgWieRGlNDMXi5rAG5IH0/eXp jrEQ== 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; bh=fS7urt9fLivYFxT4jupWqMWnCWEel/Jo1laJtyJh4WM=; b=ln/bNmwDjb9QkMfrHYEjGSaLU6sKjtz8zjXWUI1tRExK+YobJevW4k9fhKz0CAvQxU aBSWLj2S4rbisaiZx6EmYT3kcgmmnpRuIzBJ8wuAIVxEpow7loRaPFC1Dz2VC284rye0 EL8plXw23Jn3hCpuOOeq6U0Uk/Y6tQYmozcONcE5F7QkyyiuFLuSy0fBi1J+ybH0roq8 nXjfLhvWxEohWsdv91AjtNsJuTXsBTmzB7RZHqrsGrMBRCKzVB95ggRkC3Lg5iqjzwK3 taWhzD2tdYOp/cZBKUQlLWVRW3OJqhGu7rJsOCNJQEePtee1NbyPQY2TKQyMMstD2Vge x2Qw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id np11-20020a17090b4c4b00b001fdcb564d73si19479326pjb.79.2022.11.21.22.28.43; Mon, 21 Nov 2022 22:28:56 -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 S229553AbiKVGYy (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Tue, 22 Nov 2022 01:24:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbiKVGYx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 22 Nov 2022 01:24:53 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D08662D765; Mon, 21 Nov 2022 22:24:51 -0800 (PST) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NGZ3T5WvHzRpNR; Tue, 22 Nov 2022 14:24:21 +0800 (CST) Received: from kwepemm600020.china.huawei.com (7.193.23.147) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 14:24:50 +0800 Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 14:24:49 +0800 From: Peng Zhang <zhangpeng362@huawei.com> To: <pavel@ucw.cz>, <andersson@kernel.org>, <swboyd@chromium.org>, <quic_c_skakit@quicinc.com>, <marijn.suijten@somainline.org> CC: <linux-leds@vger.kernel.org>, <linux-kernel@vger.kernel.org>, ZhangPeng <zhangpeng362@huawei.com> Subject: [PATCH] leds: call of_node_put() when breaking out of for_each_available_child_of_node() Date: Tue, 22 Nov 2022 06:50:02 +0000 Message-ID: <20221122065002.2327772-1-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,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: <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?1750176666669089076?= X-GMAIL-MSGID: =?utf-8?q?1750176666669089076?= |
Series |
leds: call of_node_put() when breaking out of for_each_available_child_of_node()
|
|
Commit Message
zhangpeng (AS)
Nov. 22, 2022, 6:50 a.m. UTC
From: ZhangPeng <zhangpeng362@huawei.com> Since for_each_available_child_of_node() will increase the refcount of node, we need to call of_node_put() manually when breaking out of the iteration. Fixes: 24e2d05d1b68 ("leds: Add driver for Qualcomm LPG") Signed-off-by: ZhangPeng <zhangpeng362@huawei.com> --- drivers/leds/rgb/leds-qcom-lpg.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
Comments
Hi Peng, Thank you for the patch! Yet something to improve: [auto build test ERROR on linus/master] [also build test ERROR on v6.1-rc6 next-20221122] [cannot apply to pavel-leds/for-next] [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/Peng-Zhang/leds-call-of_node_put-when-breaking-out-of-for_each_available_child_of_node/20221122-142530 patch link: https://lore.kernel.org/r/20221122065002.2327772-1-zhangpeng362%40huawei.com patch subject: [PATCH] leds: call of_node_put() when breaking out of for_each_available_child_of_node() config: arc-randconfig-r013-20221121 compiler: arceb-elf-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/013aed0a135439317bd90a015567b9c955e50445 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Peng-Zhang/leds-call-of_node_put-when-breaking-out-of-for_each_available_child_of_node/20221122-142530 git checkout 013aed0a135439317bd90a015567b9c955e50445 # 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=arc SHELL=/bin/bash drivers/leds/rgb/ 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/leds/rgb/leds-qcom-lpg.c: In function 'lpg_add_led': >> drivers/leds/rgb/leds-qcom-lpg.c:1098:17: error: expected ';' before 'goto' 1098 | goto err_put_np_node; | ^~~~ drivers/leds/rgb/leds-qcom-lpg.c:1108:25: error: expected ';' before 'goto' 1108 | goto err_put_np_node; | ^~~~ vim +1098 drivers/leds/rgb/leds-qcom-lpg.c 1070 1071 static int lpg_add_led(struct lpg *lpg, struct device_node *np) 1072 { 1073 struct led_init_data init_data = {}; 1074 struct led_classdev *cdev; 1075 struct device_node *child; 1076 struct mc_subled *info; 1077 struct lpg_led *led; 1078 const char *state; 1079 int num_channels; 1080 u32 color = 0; 1081 int ret; 1082 int i; 1083 1084 ret = of_property_read_u32(np, "color", &color); 1085 if (ret < 0 && ret != -EINVAL) { 1086 dev_err(lpg->dev, "failed to parse \"color\" of %pOF\n", np); 1087 goto err_put_np_node; 1088 } 1089 1090 if (color == LED_COLOR_ID_RGB) 1091 num_channels = of_get_available_child_count(np); 1092 else 1093 num_channels = 1; 1094 1095 led = devm_kzalloc(lpg->dev, struct_size(led, channels, num_channels), GFP_KERNEL); 1096 if (!led) { 1097 ret = -ENOMEM > 1098 goto err_put_np_node; 1099 } 1100 1101 led->lpg = lpg; 1102 led->num_channels = num_channels; 1103 1104 if (color == LED_COLOR_ID_RGB) { 1105 info = devm_kcalloc(lpg->dev, num_channels, sizeof(*info), GFP_KERNEL); 1106 if (!info) { 1107 ret = -ENOMEM 1108 goto err_put_np_node; 1109 } 1110 i = 0; 1111 for_each_available_child_of_node(np, child) { 1112 ret = lpg_parse_channel(lpg, child, &led->channels[i]); 1113 if (ret < 0) 1114 goto err_put_child_node; 1115 1116 info[i].color_index = led->channels[i]->color; 1117 info[i].intensity = 0; 1118 i++; 1119 } 1120 1121 led->mcdev.subled_info = info; 1122 led->mcdev.num_colors = num_channels; 1123 1124 cdev = &led->mcdev.led_cdev; 1125 cdev->brightness_set = lpg_brightness_mc_set; 1126 cdev->blink_set = lpg_blink_mc_set; 1127 1128 /* Register pattern accessors only if we have a LUT block */ 1129 if (lpg->lut_base) { 1130 cdev->pattern_set = lpg_pattern_mc_set; 1131 cdev->pattern_clear = lpg_pattern_mc_clear; 1132 } 1133 } else { 1134 ret = lpg_parse_channel(lpg, np, &led->channels[0]); 1135 if (ret < 0) 1136 goto err_put_np_node; 1137 1138 cdev = &led->cdev; 1139 cdev->brightness_set = lpg_brightness_single_set; 1140 cdev->blink_set = lpg_blink_single_set; 1141 1142 /* Register pattern accessors only if we have a LUT block */ 1143 if (lpg->lut_base) { 1144 cdev->pattern_set = lpg_pattern_single_set; 1145 cdev->pattern_clear = lpg_pattern_single_clear; 1146 } 1147 } 1148 1149 cdev->default_trigger = of_get_property(np, "linux,default-trigger", NULL); 1150 cdev->max_brightness = LPG_RESOLUTION - 1; 1151 1152 if (!of_property_read_string(np, "default-state", &state) && 1153 !strcmp(state, "on")) 1154 cdev->brightness = cdev->max_brightness; 1155 else 1156 cdev->brightness = LED_OFF; 1157 1158 cdev->brightness_set(cdev, cdev->brightness); 1159 1160 init_data.fwnode = of_fwnode_handle(np); 1161 1162 if (color == LED_COLOR_ID_RGB) 1163 ret = devm_led_classdev_multicolor_register_ext(lpg->dev, &led->mcdev, &init_data); 1164 else 1165 ret = devm_led_classdev_register_ext(lpg->dev, &led->cdev, &init_data); 1166 if (ret) 1167 dev_err(lpg->dev, "unable to register %s\n", cdev->name); 1168 else 1169 return ret; 1170 1171 err_put_np_node: 1172 of_node_put(np); 1173 return ret; 1174 1175 err_put_child_node: 1176 of_node_put(child); 1177 return ret; 1178 } 1179
Hi Peng, Thank you for the patch! Yet something to improve: [auto build test ERROR on linus/master] [also build test ERROR on v6.1-rc6 next-20221122] [cannot apply to pavel-leds/for-next] [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/Peng-Zhang/leds-call-of_node_put-when-breaking-out-of-for_each_available_child_of_node/20221122-142530 patch link: https://lore.kernel.org/r/20221122065002.2327772-1-zhangpeng362%40huawei.com patch subject: [PATCH] leds: call of_node_put() when breaking out of for_each_available_child_of_node() config: riscv-randconfig-r014-20221120 compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project af8c49dc1ec44339d915d988ffe0f38da68ca0e7) 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 riscv cross compiling tool for clang build # apt-get install binutils-riscv64-linux-gnu # https://github.com/intel-lab-lkp/linux/commit/013aed0a135439317bd90a015567b9c955e50445 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Peng-Zhang/leds-call-of_node_put-when-breaking-out-of-for_each_available_child_of_node/20221122-142530 git checkout 013aed0a135439317bd90a015567b9c955e50445 # 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=riscv SHELL=/bin/bash drivers/leds/rgb/ 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/leds/rgb/leds-qcom-lpg.c:1097:16: error: expected ';' after expression ret = -ENOMEM ^ ; drivers/leds/rgb/leds-qcom-lpg.c:1107:17: error: expected ';' after expression ret = -ENOMEM ^ ; 2 errors generated. vim +1097 drivers/leds/rgb/leds-qcom-lpg.c 1070 1071 static int lpg_add_led(struct lpg *lpg, struct device_node *np) 1072 { 1073 struct led_init_data init_data = {}; 1074 struct led_classdev *cdev; 1075 struct device_node *child; 1076 struct mc_subled *info; 1077 struct lpg_led *led; 1078 const char *state; 1079 int num_channels; 1080 u32 color = 0; 1081 int ret; 1082 int i; 1083 1084 ret = of_property_read_u32(np, "color", &color); 1085 if (ret < 0 && ret != -EINVAL) { 1086 dev_err(lpg->dev, "failed to parse \"color\" of %pOF\n", np); 1087 goto err_put_np_node; 1088 } 1089 1090 if (color == LED_COLOR_ID_RGB) 1091 num_channels = of_get_available_child_count(np); 1092 else 1093 num_channels = 1; 1094 1095 led = devm_kzalloc(lpg->dev, struct_size(led, channels, num_channels), GFP_KERNEL); 1096 if (!led) { > 1097 ret = -ENOMEM 1098 goto err_put_np_node; 1099 } 1100 1101 led->lpg = lpg; 1102 led->num_channels = num_channels; 1103 1104 if (color == LED_COLOR_ID_RGB) { 1105 info = devm_kcalloc(lpg->dev, num_channels, sizeof(*info), GFP_KERNEL); 1106 if (!info) { 1107 ret = -ENOMEM 1108 goto err_put_np_node; 1109 } 1110 i = 0; 1111 for_each_available_child_of_node(np, child) { 1112 ret = lpg_parse_channel(lpg, child, &led->channels[i]); 1113 if (ret < 0) 1114 goto err_put_child_node; 1115 1116 info[i].color_index = led->channels[i]->color; 1117 info[i].intensity = 0; 1118 i++; 1119 } 1120 1121 led->mcdev.subled_info = info; 1122 led->mcdev.num_colors = num_channels; 1123 1124 cdev = &led->mcdev.led_cdev; 1125 cdev->brightness_set = lpg_brightness_mc_set; 1126 cdev->blink_set = lpg_blink_mc_set; 1127 1128 /* Register pattern accessors only if we have a LUT block */ 1129 if (lpg->lut_base) { 1130 cdev->pattern_set = lpg_pattern_mc_set; 1131 cdev->pattern_clear = lpg_pattern_mc_clear; 1132 } 1133 } else { 1134 ret = lpg_parse_channel(lpg, np, &led->channels[0]); 1135 if (ret < 0) 1136 goto err_put_np_node; 1137 1138 cdev = &led->cdev; 1139 cdev->brightness_set = lpg_brightness_single_set; 1140 cdev->blink_set = lpg_blink_single_set; 1141 1142 /* Register pattern accessors only if we have a LUT block */ 1143 if (lpg->lut_base) { 1144 cdev->pattern_set = lpg_pattern_single_set; 1145 cdev->pattern_clear = lpg_pattern_single_clear; 1146 } 1147 } 1148 1149 cdev->default_trigger = of_get_property(np, "linux,default-trigger", NULL); 1150 cdev->max_brightness = LPG_RESOLUTION - 1; 1151 1152 if (!of_property_read_string(np, "default-state", &state) && 1153 !strcmp(state, "on")) 1154 cdev->brightness = cdev->max_brightness; 1155 else 1156 cdev->brightness = LED_OFF; 1157 1158 cdev->brightness_set(cdev, cdev->brightness); 1159 1160 init_data.fwnode = of_fwnode_handle(np); 1161 1162 if (color == LED_COLOR_ID_RGB) 1163 ret = devm_led_classdev_multicolor_register_ext(lpg->dev, &led->mcdev, &init_data); 1164 else 1165 ret = devm_led_classdev_register_ext(lpg->dev, &led->cdev, &init_data); 1166 if (ret) 1167 dev_err(lpg->dev, "unable to register %s\n", cdev->name); 1168 else 1169 return ret; 1170 1171 err_put_np_node: 1172 of_node_put(np); 1173 return ret; 1174 1175 err_put_child_node: 1176 of_node_put(child); 1177 return ret; 1178 } 1179
diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c index 02f51cc61837..8075115cef58 100644 --- a/drivers/leds/rgb/leds-qcom-lpg.c +++ b/drivers/leds/rgb/leds-qcom-lpg.c @@ -1084,7 +1084,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np) ret = of_property_read_u32(np, "color", &color); if (ret < 0 && ret != -EINVAL) { dev_err(lpg->dev, "failed to parse \"color\" of %pOF\n", np); - return ret; + goto err_put_np_node; } if (color == LED_COLOR_ID_RGB) @@ -1093,21 +1093,25 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np) num_channels = 1; led = devm_kzalloc(lpg->dev, struct_size(led, channels, num_channels), GFP_KERNEL); - if (!led) - return -ENOMEM; + if (!led) { + ret = -ENOMEM + goto err_put_np_node; + } led->lpg = lpg; led->num_channels = num_channels; if (color == LED_COLOR_ID_RGB) { info = devm_kcalloc(lpg->dev, num_channels, sizeof(*info), GFP_KERNEL); - if (!info) - return -ENOMEM; + if (!info) { + ret = -ENOMEM + goto err_put_np_node; + } i = 0; for_each_available_child_of_node(np, child) { ret = lpg_parse_channel(lpg, child, &led->channels[i]); if (ret < 0) - return ret; + goto err_put_child_node; info[i].color_index = led->channels[i]->color; info[i].intensity = 0; @@ -1129,7 +1133,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np) } else { ret = lpg_parse_channel(lpg, np, &led->channels[0]); if (ret < 0) - return ret; + goto err_put_np_node; cdev = &led->cdev; cdev->brightness_set = lpg_brightness_single_set; @@ -1161,7 +1165,15 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np) ret = devm_led_classdev_register_ext(lpg->dev, &led->cdev, &init_data); if (ret) dev_err(lpg->dev, "unable to register %s\n", cdev->name); + else + return ret; + +err_put_np_node: + of_node_put(np); + return ret; +err_put_child_node: + of_node_put(child); return ret; }