Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: various: use only available OF children

Various drivers count and iterate over OF children nodes via
of_get_child_count and for_each_child_of_node. Instead they should use
of_get_available_child_count and for_each_available_child_of_node, so
that if a given node has the `status` property set to `disabled`, the
child will be ignored.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Andrey Utkin <andrey_utkin@fastmail.com>
Cc: Baolin Wang <baolin.wang7@gmail.com>
Cc: Baolin Wang <baolin.wang@linaro.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Christian Mauderer <oss@c-mauderer.de>
Cc: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: Dan Murphy <dmurphy@ti.com>
Cc: David Rivshin <drivshin@allworx.com>
Cc: Haojian Zhuang <haojian.zhuang@marvell.com>
Cc: H. Nikolaus Schaller <hns@goldelico.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Milo Kim <milo.kim@ti.com>
Cc: NeilBrown <neilb@suse.de>
Cc: Nikita Travkin <nikitos.tr@gmail.com>
Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Philippe Retornaz <philippe.retornaz@epfl.ch>
Cc: Riku Voipio <riku.voipio@iki.fi>
Cc: Simon Guinot <sguinot@lacie.com>
Cc: Simon Shields <simon@lineageos.org>
Cc: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Cc: Xiaotong Lu <xiaotong.lu@spreadtrum.com>
Signed-off-by: Pavel Machek <pavel@ucw.cz>

authored by

Marek Behún and committed by
Pavel Machek
99a013c8 05dec742

+26 -26
+1 -1
drivers/leds/leds-88pm860x.c
··· 125 125 dev_err(&pdev->dev, "failed to find leds node\n"); 126 126 return -ENODEV; 127 127 } 128 - for_each_child_of_node(nproot, np) { 128 + for_each_available_child_of_node(nproot, np) { 129 129 if (of_node_name_eq(np, data->name)) { 130 130 of_property_read_u32(np, "marvell,88pm860x-iset", 131 131 &iset);
+1 -1
drivers/leds/leds-an30259a.c
··· 208 208 const char *str; 209 209 struct an30259a_led *led; 210 210 211 - count = of_get_child_count(np); 211 + count = of_get_available_child_count(np); 212 212 if (!count || count > AN30259A_MAX_LEDS) 213 213 return -EINVAL; 214 214
+1 -1
drivers/leds/leds-aw2013.c
··· 265 265 int count, ret = 0, i = 0; 266 266 struct aw2013_led *led; 267 267 268 - count = of_get_child_count(np); 268 + count = of_get_available_child_count(np); 269 269 if (!count || count > AW2013_MAX_LEDS) 270 270 return -EINVAL; 271 271
+2 -2
drivers/leds/leds-is31fl319x.c
··· 220 220 221 221 is31->cdef = device_get_match_data(dev); 222 222 223 - count = of_get_child_count(np); 223 + count = of_get_available_child_count(np); 224 224 225 225 dev_dbg(dev, "probing with %d leds defined in DT\n", count); 226 226 ··· 230 230 return -ENODEV; 231 231 } 232 232 233 - for_each_child_of_node(np, child) { 233 + for_each_available_child_of_node(np, child) { 234 234 struct is31fl319x_led *led; 235 235 u32 reg; 236 236
+2 -2
drivers/leds/leds-is31fl32xx.c
··· 372 372 struct device_node *child; 373 373 int ret = 0; 374 374 375 - for_each_child_of_node(dev_of_node(dev), child) { 375 + for_each_available_child_of_node(dev_of_node(dev), child) { 376 376 struct is31fl32xx_led_data *led_data = 377 377 &priv->leds[priv->num_leds]; 378 378 const struct is31fl32xx_led_data *other_led_data; ··· 435 435 436 436 cdef = device_get_match_data(dev); 437 437 438 - count = of_get_child_count(dev_of_node(dev)); 438 + count = of_get_available_child_count(dev_of_node(dev)); 439 439 if (!count) 440 440 return -EINVAL; 441 441
+3 -3
drivers/leds/leds-lp55xx-common.c
··· 611 611 struct device_node *child; 612 612 int num_colors = 0, ret; 613 613 614 - for_each_child_of_node(np, child) { 614 + for_each_available_child_of_node(np, child) { 615 615 ret = lp55xx_parse_multi_led_child(child, cfg, child_number, 616 616 num_colors); 617 617 if (ret) ··· 665 665 if (!pdata) 666 666 return ERR_PTR(-ENOMEM); 667 667 668 - num_channels = of_get_child_count(np); 668 + num_channels = of_get_available_child_count(np); 669 669 if (num_channels == 0) { 670 670 dev_err(dev, "no LED channels\n"); 671 671 return ERR_PTR(-EINVAL); ··· 679 679 pdata->num_channels = num_channels; 680 680 cfg->max_channel = chip->cfg->max_channel; 681 681 682 - for_each_child_of_node(np, child) { 682 + for_each_available_child_of_node(np, child) { 683 683 ret = lp55xx_parse_logical_led(child, cfg, i); 684 684 if (ret) 685 685 return ERR_PTR(-EINVAL);
+2 -2
drivers/leds/leds-mc13783.c
··· 131 131 if (ret) 132 132 goto out_node_put; 133 133 134 - pdata->num_leds = of_get_child_count(parent); 134 + pdata->num_leds = of_get_available_child_count(parent); 135 135 136 136 pdata->led = devm_kcalloc(dev, pdata->num_leds, sizeof(*pdata->led), 137 137 GFP_KERNEL); ··· 140 140 goto out_node_put; 141 141 } 142 142 143 - for_each_child_of_node(parent, child) { 143 + for_each_available_child_of_node(parent, child) { 144 144 const char *str; 145 145 u32 tmp; 146 146
+2 -2
drivers/leds/leds-netxbig.c
··· 485 485 } 486 486 487 487 /* LEDs */ 488 - num_leds = of_get_child_count(np); 488 + num_leds = of_get_available_child_count(np); 489 489 if (!num_leds) { 490 490 dev_err(dev, "No LED subnodes found in DT\n"); 491 491 return -ENODEV; ··· 496 496 return -ENOMEM; 497 497 498 498 led = leds; 499 - for_each_child_of_node(np, child) { 499 + for_each_available_child_of_node(np, child) { 500 500 const char *string; 501 501 int *mode_val; 502 502 int num_modes;
+2 -2
drivers/leds/leds-ns2.c
··· 251 251 struct ns2_led *led, *leds; 252 252 int ret, num_leds = 0; 253 253 254 - num_leds = of_get_child_count(np); 254 + num_leds = of_get_available_child_count(np); 255 255 if (!num_leds) 256 256 return -ENODEV; 257 257 ··· 261 261 return -ENOMEM; 262 262 263 263 led = leds; 264 - for_each_child_of_node(np, child) { 264 + for_each_available_child_of_node(np, child) { 265 265 const char *string; 266 266 int i, num_modes; 267 267 struct ns2_led_modval *modval;
+1 -1
drivers/leds/leds-pca9532.c
··· 478 478 if (!pdata) 479 479 return ERR_PTR(-ENOMEM); 480 480 481 - for_each_child_of_node(np, child) { 481 + for_each_available_child_of_node(np, child) { 482 482 if (of_property_read_string(child, "label", 483 483 &pdata->leds[i].name)) 484 484 pdata->leds[i].name = child->name;
+1 -1
drivers/leds/leds-powernv.c
··· 250 250 struct powernv_led_data *powernv_led; 251 251 struct device *dev = &pdev->dev; 252 252 253 - for_each_child_of_node(led_node, np) { 253 + for_each_available_child_of_node(led_node, np) { 254 254 p = of_find_property(np, "led-types", NULL); 255 255 256 256 while ((cur = of_prop_next_string(p, cur)) != NULL) {
+2 -2
drivers/leds/leds-sc27xx-bltc.c
··· 281 281 u32 base, count, reg; 282 282 int err; 283 283 284 - count = of_get_child_count(np); 284 + count = of_get_available_child_count(np); 285 285 if (!count || count > SC27XX_LEDS_MAX) 286 286 return -EINVAL; 287 287 ··· 305 305 return err; 306 306 } 307 307 308 - for_each_child_of_node(np, child) { 308 + for_each_available_child_of_node(np, child) { 309 309 err = of_property_read_u32(child, "reg", &reg); 310 310 if (err) { 311 311 of_node_put(child);
+2 -2
drivers/leds/leds-spi-byte.c
··· 87 87 const char *state; 88 88 int ret; 89 89 90 - if (of_get_child_count(dev_of_node(dev)) != 1) { 90 + if (of_get_available_child_count(dev_of_node(dev)) != 1) { 91 91 dev_err(dev, "Device must have exactly one LED sub-node."); 92 92 return -EINVAL; 93 93 } 94 - child = of_get_next_child(dev_of_node(dev), NULL); 94 + child = of_get_next_available_child(dev_of_node(dev), NULL); 95 95 96 96 led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); 97 97 if (!led)
+2 -2
drivers/leds/leds-tca6507.c
··· 694 694 struct led_info *tca_leds; 695 695 int count; 696 696 697 - count = of_get_child_count(np); 697 + count = of_get_available_child_count(np); 698 698 if (!count || count > NUM_LEDS) 699 699 return ERR_PTR(-ENODEV); 700 700 ··· 703 703 if (!tca_leds) 704 704 return ERR_PTR(-ENOMEM); 705 705 706 - for_each_child_of_node(np, child) { 706 + for_each_available_child_of_node(np, child) { 707 707 struct led_info led; 708 708 u32 reg; 709 709 int ret;
+2 -2
drivers/leds/leds-tlc591xx.c
··· 158 158 if (!np) 159 159 return -ENODEV; 160 160 161 - count = of_get_child_count(np); 161 + count = of_get_available_child_count(np); 162 162 if (!count || count > tlc591xx->max_leds) 163 163 return -EINVAL; 164 164 ··· 180 180 if (err < 0) 181 181 return err; 182 182 183 - for_each_child_of_node(np, child) { 183 + for_each_available_child_of_node(np, child) { 184 184 struct tlc591xx_led *led; 185 185 struct led_init_data init_data = {}; 186 186