Commit 99a013c8 authored by Marek Behún's avatar Marek Behún Committed by Pavel Machek

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: default avatarMarek 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: default avatarPavel Machek <pavel@ucw.cz>
parent 05dec742
...@@ -125,7 +125,7 @@ static int pm860x_led_dt_init(struct platform_device *pdev, ...@@ -125,7 +125,7 @@ static int pm860x_led_dt_init(struct platform_device *pdev,
dev_err(&pdev->dev, "failed to find leds node\n"); dev_err(&pdev->dev, "failed to find leds node\n");
return -ENODEV; return -ENODEV;
} }
for_each_child_of_node(nproot, np) { for_each_available_child_of_node(nproot, np) {
if (of_node_name_eq(np, data->name)) { if (of_node_name_eq(np, data->name)) {
of_property_read_u32(np, "marvell,88pm860x-iset", of_property_read_u32(np, "marvell,88pm860x-iset",
&iset); &iset);
......
...@@ -208,7 +208,7 @@ static int an30259a_dt_init(struct i2c_client *client, ...@@ -208,7 +208,7 @@ static int an30259a_dt_init(struct i2c_client *client,
const char *str; const char *str;
struct an30259a_led *led; struct an30259a_led *led;
count = of_get_child_count(np); count = of_get_available_child_count(np);
if (!count || count > AN30259A_MAX_LEDS) if (!count || count > AN30259A_MAX_LEDS)
return -EINVAL; return -EINVAL;
......
...@@ -265,7 +265,7 @@ static int aw2013_probe_dt(struct aw2013 *chip) ...@@ -265,7 +265,7 @@ static int aw2013_probe_dt(struct aw2013 *chip)
int count, ret = 0, i = 0; int count, ret = 0, i = 0;
struct aw2013_led *led; struct aw2013_led *led;
count = of_get_child_count(np); count = of_get_available_child_count(np);
if (!count || count > AW2013_MAX_LEDS) if (!count || count > AW2013_MAX_LEDS)
return -EINVAL; return -EINVAL;
......
...@@ -220,7 +220,7 @@ static int is31fl319x_parse_dt(struct device *dev, ...@@ -220,7 +220,7 @@ static int is31fl319x_parse_dt(struct device *dev,
is31->cdef = device_get_match_data(dev); is31->cdef = device_get_match_data(dev);
count = of_get_child_count(np); count = of_get_available_child_count(np);
dev_dbg(dev, "probing with %d leds defined in DT\n", count); dev_dbg(dev, "probing with %d leds defined in DT\n", count);
...@@ -230,7 +230,7 @@ static int is31fl319x_parse_dt(struct device *dev, ...@@ -230,7 +230,7 @@ static int is31fl319x_parse_dt(struct device *dev,
return -ENODEV; return -ENODEV;
} }
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
struct is31fl319x_led *led; struct is31fl319x_led *led;
u32 reg; u32 reg;
......
...@@ -372,7 +372,7 @@ static int is31fl32xx_parse_dt(struct device *dev, ...@@ -372,7 +372,7 @@ static int is31fl32xx_parse_dt(struct device *dev,
struct device_node *child; struct device_node *child;
int ret = 0; int ret = 0;
for_each_child_of_node(dev_of_node(dev), child) { for_each_available_child_of_node(dev_of_node(dev), child) {
struct is31fl32xx_led_data *led_data = struct is31fl32xx_led_data *led_data =
&priv->leds[priv->num_leds]; &priv->leds[priv->num_leds];
const struct is31fl32xx_led_data *other_led_data; const struct is31fl32xx_led_data *other_led_data;
...@@ -435,7 +435,7 @@ static int is31fl32xx_probe(struct i2c_client *client, ...@@ -435,7 +435,7 @@ static int is31fl32xx_probe(struct i2c_client *client,
cdef = device_get_match_data(dev); cdef = device_get_match_data(dev);
count = of_get_child_count(dev_of_node(dev)); count = of_get_available_child_count(dev_of_node(dev));
if (!count) if (!count)
return -EINVAL; return -EINVAL;
......
...@@ -611,7 +611,7 @@ static int lp55xx_parse_multi_led(struct device_node *np, ...@@ -611,7 +611,7 @@ static int lp55xx_parse_multi_led(struct device_node *np,
struct device_node *child; struct device_node *child;
int num_colors = 0, ret; int num_colors = 0, ret;
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
ret = lp55xx_parse_multi_led_child(child, cfg, child_number, ret = lp55xx_parse_multi_led_child(child, cfg, child_number,
num_colors); num_colors);
if (ret) if (ret)
...@@ -665,7 +665,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, ...@@ -665,7 +665,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
if (!pdata) if (!pdata)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
num_channels = of_get_child_count(np); num_channels = of_get_available_child_count(np);
if (num_channels == 0) { if (num_channels == 0) {
dev_err(dev, "no LED channels\n"); dev_err(dev, "no LED channels\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -679,7 +679,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev, ...@@ -679,7 +679,7 @@ struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
pdata->num_channels = num_channels; pdata->num_channels = num_channels;
cfg->max_channel = chip->cfg->max_channel; cfg->max_channel = chip->cfg->max_channel;
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
ret = lp55xx_parse_logical_led(child, cfg, i); ret = lp55xx_parse_logical_led(child, cfg, i);
if (ret) if (ret)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
......
...@@ -131,7 +131,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( ...@@ -131,7 +131,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
if (ret) if (ret)
goto out_node_put; goto out_node_put;
pdata->num_leds = of_get_child_count(parent); pdata->num_leds = of_get_available_child_count(parent);
pdata->led = devm_kcalloc(dev, pdata->num_leds, sizeof(*pdata->led), pdata->led = devm_kcalloc(dev, pdata->num_leds, sizeof(*pdata->led),
GFP_KERNEL); GFP_KERNEL);
...@@ -140,7 +140,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt( ...@@ -140,7 +140,7 @@ static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
goto out_node_put; goto out_node_put;
} }
for_each_child_of_node(parent, child) { for_each_available_child_of_node(parent, child) {
const char *str; const char *str;
u32 tmp; u32 tmp;
......
...@@ -485,7 +485,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev, ...@@ -485,7 +485,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
} }
/* LEDs */ /* LEDs */
num_leds = of_get_child_count(np); num_leds = of_get_available_child_count(np);
if (!num_leds) { if (!num_leds) {
dev_err(dev, "No LED subnodes found in DT\n"); dev_err(dev, "No LED subnodes found in DT\n");
return -ENODEV; return -ENODEV;
...@@ -496,7 +496,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev, ...@@ -496,7 +496,7 @@ static int netxbig_leds_get_of_pdata(struct device *dev,
return -ENOMEM; return -ENOMEM;
led = leds; led = leds;
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
const char *string; const char *string;
int *mode_val; int *mode_val;
int num_modes; int num_modes;
......
...@@ -251,7 +251,7 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata) ...@@ -251,7 +251,7 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
struct ns2_led *led, *leds; struct ns2_led *led, *leds;
int ret, num_leds = 0; int ret, num_leds = 0;
num_leds = of_get_child_count(np); num_leds = of_get_available_child_count(np);
if (!num_leds) if (!num_leds)
return -ENODEV; return -ENODEV;
...@@ -261,7 +261,7 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata) ...@@ -261,7 +261,7 @@ ns2_leds_get_of_pdata(struct device *dev, struct ns2_led_platform_data *pdata)
return -ENOMEM; return -ENOMEM;
led = leds; led = leds;
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
const char *string; const char *string;
int i, num_modes; int i, num_modes;
struct ns2_led_modval *modval; struct ns2_led_modval *modval;
......
...@@ -478,7 +478,7 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np) ...@@ -478,7 +478,7 @@ pca9532_of_populate_pdata(struct device *dev, struct device_node *np)
if (!pdata) if (!pdata)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
if (of_property_read_string(child, "label", if (of_property_read_string(child, "label",
&pdata->leds[i].name)) &pdata->leds[i].name))
pdata->leds[i].name = child->name; pdata->leds[i].name = child->name;
......
...@@ -250,7 +250,7 @@ static int powernv_led_classdev(struct platform_device *pdev, ...@@ -250,7 +250,7 @@ static int powernv_led_classdev(struct platform_device *pdev,
struct powernv_led_data *powernv_led; struct powernv_led_data *powernv_led;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
for_each_child_of_node(led_node, np) { for_each_available_child_of_node(led_node, np) {
p = of_find_property(np, "led-types", NULL); p = of_find_property(np, "led-types", NULL);
while ((cur = of_prop_next_string(p, cur)) != NULL) { while ((cur = of_prop_next_string(p, cur)) != NULL) {
......
...@@ -281,7 +281,7 @@ static int sc27xx_led_probe(struct platform_device *pdev) ...@@ -281,7 +281,7 @@ static int sc27xx_led_probe(struct platform_device *pdev)
u32 base, count, reg; u32 base, count, reg;
int err; int err;
count = of_get_child_count(np); count = of_get_available_child_count(np);
if (!count || count > SC27XX_LEDS_MAX) if (!count || count > SC27XX_LEDS_MAX)
return -EINVAL; return -EINVAL;
...@@ -305,7 +305,7 @@ static int sc27xx_led_probe(struct platform_device *pdev) ...@@ -305,7 +305,7 @@ static int sc27xx_led_probe(struct platform_device *pdev)
return err; return err;
} }
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
err = of_property_read_u32(child, "reg", &reg); err = of_property_read_u32(child, "reg", &reg);
if (err) { if (err) {
of_node_put(child); of_node_put(child);
......
...@@ -87,11 +87,11 @@ static int spi_byte_probe(struct spi_device *spi) ...@@ -87,11 +87,11 @@ static int spi_byte_probe(struct spi_device *spi)
const char *state; const char *state;
int ret; int ret;
if (of_get_child_count(dev_of_node(dev)) != 1) { if (of_get_available_child_count(dev_of_node(dev)) != 1) {
dev_err(dev, "Device must have exactly one LED sub-node."); dev_err(dev, "Device must have exactly one LED sub-node.");
return -EINVAL; return -EINVAL;
} }
child = of_get_next_child(dev_of_node(dev), NULL); child = of_get_next_available_child(dev_of_node(dev), NULL);
led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
if (!led) if (!led)
......
...@@ -694,7 +694,7 @@ tca6507_led_dt_init(struct i2c_client *client) ...@@ -694,7 +694,7 @@ tca6507_led_dt_init(struct i2c_client *client)
struct led_info *tca_leds; struct led_info *tca_leds;
int count; int count;
count = of_get_child_count(np); count = of_get_available_child_count(np);
if (!count || count > NUM_LEDS) if (!count || count > NUM_LEDS)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
...@@ -703,7 +703,7 @@ tca6507_led_dt_init(struct i2c_client *client) ...@@ -703,7 +703,7 @@ tca6507_led_dt_init(struct i2c_client *client)
if (!tca_leds) if (!tca_leds)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
struct led_info led; struct led_info led;
u32 reg; u32 reg;
int ret; int ret;
......
...@@ -158,7 +158,7 @@ tlc591xx_probe(struct i2c_client *client, ...@@ -158,7 +158,7 @@ tlc591xx_probe(struct i2c_client *client,
if (!np) if (!np)
return -ENODEV; return -ENODEV;
count = of_get_child_count(np); count = of_get_available_child_count(np);
if (!count || count > tlc591xx->max_leds) if (!count || count > tlc591xx->max_leds)
return -EINVAL; return -EINVAL;
...@@ -180,7 +180,7 @@ tlc591xx_probe(struct i2c_client *client, ...@@ -180,7 +180,7 @@ tlc591xx_probe(struct i2c_client *client,
if (err < 0) if (err < 0)
return err; return err;
for_each_child_of_node(np, child) { for_each_available_child_of_node(np, child) {
struct tlc591xx_led *led; struct tlc591xx_led *led;
struct led_init_data init_data = {}; struct led_init_data init_data = {};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment