From: Wei Yongjun <weiyongjun1@xxxxxxxxxx> Enabling CONFIG_OF_DYNAMIC triggers the following error at device remove: OF: ERROR: memory leak, expected refcount 1 instead of 2, \ of_node_get()/of_node_put() unbalanced - destroy cset entry: \ attach overlay node /spi/led-controller@0/led of_get_next_available_child() is used to get child node with refcount incremented in spi_byte_probe(), but missing of_node_put() on it when done. This patch fix it. Signed-off-by: Wei Yongjun <weiyongjun1@xxxxxxxxxx> --- drivers/leds/leds-spi-byte.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/leds/leds-spi-byte.c b/drivers/leds/leds-spi-byte.c index 9d23dc9e7639..eaad227b4542 100644 --- a/drivers/leds/leds-spi-byte.c +++ b/drivers/leds/leds-spi-byte.c @@ -91,12 +91,12 @@ static int spi_byte_probe(struct spi_device *spi) dev_err(dev, "Device must have exactly one LED sub-node."); return -EINVAL; } - child = of_get_next_available_child(dev_of_node(dev), NULL); led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); if (!led) return -ENOMEM; + child = of_get_next_available_child(dev_of_node(dev), NULL); of_property_read_string(child, "label", &name); strlcpy(led->name, name, sizeof(led->name)); led->spi = spi; @@ -113,10 +113,12 @@ static int spi_byte_probe(struct spi_device *spi) led->ldev.brightness = led->ldev.max_brightness; } else if (strcmp(state, "off")) { /* all other cases except "off" */ + of_node_put(child); dev_err(dev, "default-state can only be 'on' or 'off'"); return -EINVAL; } } + of_node_put(child); spi_byte_brightness_set_blocking(&led->ldev, led->ldev.brightness); -- 2.34.1